Skip to content

Commit

Permalink
Merge branch '2.14.x' into 3.0.x
Browse files Browse the repository at this point in the history
* 2.14.x:
  Allow doctrine/event-manager 2 (doctrine#10123)
  Psalm 4.29 (doctrine#10128)
  Address deprecation of Table::changeColumn() (doctrine#10121)
  Make code blocks consistent (doctrine#10103)
  Fix change set computation with enums (doctrine#10074)
  PHPStan 1.8.8, Psalm 4.28.0 (doctrine#10115)
  fix deprecated trigger help comment
  • Loading branch information
derrabus committed Oct 13, 2022
2 parents 5367ce8 + 90f8220 commit 99e07eb
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 20 deletions.
6 changes: 3 additions & 3 deletions composer.json
Expand Up @@ -27,7 +27,7 @@
"doctrine/common": "^3.3",
"doctrine/dbal": "^3.4",
"doctrine/deprecations": "^0.5.3 || ^1",
"doctrine/event-manager": "^1.1",
"doctrine/event-manager": "^1.2 || ^2",
"doctrine/inflector": "^1.4 || ^2.0",
"doctrine/instantiator": "^1.3",
"doctrine/lexer": "^1.2.3",
Expand All @@ -39,12 +39,12 @@
"doctrine/annotations": "^1.13",
"doctrine/coding-standard": "^10.0",
"phpbench/phpbench": "^1.0",
"phpstan/phpstan": "1.8.5",
"phpstan/phpstan": "1.8.8",
"phpunit/phpunit": "^9.5",
"psr/log": "^1 || ^2 || ^3",
"squizlabs/php_codesniffer": "3.7.1",
"symfony/cache": "^4.4 || ^5.4 || ^6.0",
"vimeo/psalm": "4.27.0"
"vimeo/psalm": "4.29.0"
},
"conflict": {
"doctrine/annotations": "<1.13 || >= 2.0"
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Event/LifecycleEventArgs.php
Expand Up @@ -44,7 +44,7 @@ public function getEntity()
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issues/9875',
'Method %s() is deprecated and will be removed in Doctrine ORM 3.0. Use getObjectManager() instead.',
'Method %s() is deprecated and will be removed in Doctrine ORM 3.0. Use getObject() instead.',
__METHOD__,
);

Expand Down
3 changes: 2 additions & 1 deletion lib/Doctrine/ORM/Tools/SchemaTool.php
Expand Up @@ -500,8 +500,9 @@ private function gatherColumn(
}

if ($table->hasColumn($columnName)) {
$method = method_exists($table, 'modifyColumn') ? 'modifyColumn' : 'changeColumn';
// required in some inheritance scenarios
$table->changeColumn($columnName, $options);
$table->$method($columnName, $options);
} else {
$table->addColumn($columnName, $columnType, $options);
}
Expand Down
5 changes: 5 additions & 0 deletions lib/Doctrine/ORM/UnitOfWork.php
Expand Up @@ -4,6 +4,7 @@

namespace Doctrine\ORM;

use BackedEnum;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
Expand Down Expand Up @@ -644,6 +645,10 @@ public function computeChangeSet(ClassMetadata $class, object $entity): void

$orgValue = $originalData[$propName];

if ($orgValue instanceof BackedEnum) {
$orgValue = $orgValue->value;
}

// skip if value haven't changed
if ($orgValue === $actualValue) {
continue;
Expand Down
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Expand Up @@ -130,6 +130,11 @@ parameters:
count: 2
path: lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php

-
message: "#^Method Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo\\:\\:fullyQualifiedClassName\\(\\) should return class\\-string\\|null but returns string\\|null\\.$#"
count: 1
path: lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php

-
message: "#^Negated boolean expression is always false\\.$#"
count: 1
Expand Down
17 changes: 3 additions & 14 deletions psalm-baseline.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.27.0@faf106e717c37b8c81721845dba9de3d8deed8ff">
<files psalm-version="4.29.0@7ec5ffbd5f68ae03782d7fd33fff0c45a69f95b3">
<file src="lib/Doctrine/ORM/AbstractQuery.php">
<FalsableReturnStatement occurrences="1">
<code>! $filteredParameters-&gt;isEmpty() ? $filteredParameters-&gt;first() : null</code>
Expand Down Expand Up @@ -408,10 +408,9 @@
<ParamNameMismatch occurrences="1">
<code>$entity</code>
</ParamNameMismatch>
<PossiblyNullArgument occurrences="7">
<PossiblyNullArgument occurrences="6">
<code>$class</code>
<code>$className</code>
<code>$entityResult['entityClass']</code>
<code>$mapping['targetEntity']</code>
<code>$mapping['targetEntity']</code>
<code>$parentReflFields[$embeddedClass['declaredField']]</code>
Expand Down Expand Up @@ -559,8 +558,7 @@
<code>$this-&gt;tables[$tableName]</code>
<code>$this-&gt;tables[$tableName]</code>
</PossiblyNullArrayAccess>
<PossiblyNullReference occurrences="4">
<code>getColumns</code>
<PossiblyNullReference occurrences="3">
<code>getColumns</code>
<code>getColumns</code>
<code>getIndexes</code>
Expand Down Expand Up @@ -632,12 +630,6 @@
<code>isset($xmlRoot-&gt;{'unique-constraints'})</code>
</RedundantCondition>
</file>
<file src="lib/Doctrine/ORM/Mapping/FieldResult.php">
<MissingConstructor occurrences="2">
<code>$column</code>
<code>$name</code>
</MissingConstructor>
</file>
<file src="lib/Doctrine/ORM/Mapping/InverseJoinColumn.php">
<MissingParamType occurrences="1">
<code>$onDelete</code>
Expand Down Expand Up @@ -1837,9 +1829,6 @@
<PossiblyNullArgument occurrences="1">
<code>$referencedFieldName</code>
</PossiblyNullArgument>
<PossiblyNullReference occurrences="1">
<code>getColumns</code>
</PossiblyNullReference>
<PossiblyUndefinedArrayOffset occurrences="7">
<code>$assoc['joinColumns']</code>
<code>$class-&gt;getAssociationMapping($fieldName)['joinColumns']</code>
Expand Down
40 changes: 40 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/EnumTest.php
Expand Up @@ -258,6 +258,46 @@ public function testEnumArrayInDtoHydration(): void
self::assertEqualsCanonicalizing([Unit::Gram, Unit::Meter], $result[0]->supportedUnits);
}

public function testEnumChangeSetsSimpleObjectHydrator(): void
{
$this->setUpEntitySchema([Card::class]);

$card = new Card();
$card->suit = Suit::Clubs;

$this->_em->persist($card);
$this->_em->flush();
$this->_em->clear();

$result = $this->_em->find(Card::class, $card->id);

$this->_em->getUnitOfWork()->computeChangeSets();

self::assertFalse($this->_em->getUnitOfWork()->isScheduledForUpdate($result));
}

public function testEnumChangeSetsObjectHydrator(): void
{
$this->setUpEntitySchema([Card::class]);

$card = new Card();
$card->suit = Suit::Clubs;

$this->_em->persist($card);
$this->_em->flush();
$this->_em->clear();

$result = $this->_em->createQueryBuilder()
->from(Card::class, 'c')
->select('c')
->getQuery()
->getResult();

$this->_em->getUnitOfWork()->computeChangeSets();

self::assertFalse($this->_em->getUnitOfWork()->isScheduledForUpdate($result[0]));
}

public function testFindByEnum(): void
{
$this->setUpEntitySchema([Card::class]);
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/OrmFunctionalTestCase.php
Expand Up @@ -945,7 +945,7 @@ protected function getEntityManager(

// get rid of more global state
$evm = $conn->getEventManager();
foreach ($evm->getListeners() as $event => $listeners) {
foreach ($evm->getAllListeners() as $event => $listeners) {
foreach ($listeners as $listener) {
$evm->removeEventListener([$event], $listener);
}
Expand Down

0 comments on commit 99e07eb

Please sign in to comment.