From 596da353c225ed0200599c9de637f29a967afb0e Mon Sep 17 00:00:00 2001 From: Jonny Eom Date: Thu, 16 Jan 2025 11:05:42 -0500 Subject: [PATCH 1/2] UPGRADE: Document QueryBuilder::setParameters() Type enforcement --- UPGRADE.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/UPGRADE.md b/UPGRADE.md index 817d1f0e004..73ae9d9a3cd 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -124,6 +124,36 @@ WARNING: This was relaxed in ORM 3.2 when partial was re-allowed for array-hydra `Doctrine\ORM\Query::HINT_FORCE_PARTIAL_LOAD` are removed. - `Doctrine\ORM\EntityManager*::getPartialReference()` is removed. +## BC BREAK: Enforce ArrayCollection Type on `\Doctrine\ORM\QueryBuilder::setParameters(ArrayCollection $parameters)` + +The argument $parameters can no longer be a key=>value array. Only ArrayCollection types are allowed. + +### Before + +```php +$qb = $em->createQueryBuilder() + ->select('u') + ->from('User', 'u') + ->where('u.id = :user_id1 OR u.id = :user_id2') + ->setParameter(array( + 'user_id1' => 1, + 'user_id2' => 2 + )); +``` + +### After + +```php +$qb = $em->createQueryBuilder() + ->select('u') + ->from('User', 'u') + ->where('u.id = :user_id1 OR u.id = :user_id2') + ->setParameter(new ArrayCollection(array( + new Parameter('user_id1', 1), + new Parameter('user_id2', 2) + ))); +``` + ## BC BREAK: `Doctrine\ORM\Persister\Entity\EntityPersister::executeInserts()` return type changed to `void` Implementors should adapt to the new signature, and should call From 27b47841be9995d122a34c70db8f1d6d55e0c4e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sat, 25 Jan 2025 10:44:53 +0100 Subject: [PATCH 2/2] Display Doctrine deprecations when running PHPUnit This will give a signal that there is work to be done without blocking other contributions by failing the build. --- phpunit.xml.dist | 8 ++++++++ tests/Tests/ORM/Functional/PaginationTest.php | 3 ++- .../ORM/Functional/ParserResultSerializationTest.php | 2 ++ tests/Tests/ORM/Mapping/ClassMetadataTest.php | 3 +++ tests/Tests/ORM/Mapping/TableMappingTest.php | 3 +++ 5 files changed, 18 insertions(+), 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 48d4a0f116f..5e26bd5898a 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -14,6 +14,7 @@ --> + + + + + src + + diff --git a/tests/Tests/ORM/Functional/PaginationTest.php b/tests/Tests/ORM/Functional/PaginationTest.php index af7b83394ce..b8ea24e7fef 100644 --- a/tests/Tests/ORM/Functional/PaginationTest.php +++ b/tests/Tests/ORM/Functional/PaginationTest.php @@ -12,6 +12,7 @@ use Doctrine\ORM\Query\AST\PathExpression; use Doctrine\ORM\Query\AST\SelectStatement; use Doctrine\ORM\Query\AST\WhereClause; +use Doctrine\ORM\Query\SqlOutputWalker; use Doctrine\ORM\Query\SqlWalker; use Doctrine\ORM\Query\TreeWalkerAdapter; use Doctrine\ORM\Tools\Pagination\Paginator; @@ -643,7 +644,7 @@ public function testCountQueryStripsParametersInSelect(): void self::assertCount(2, $getCountQuery->invoke($paginator)->getParameters()); self::assertCount(9, $paginator); - $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, SqlWalker::class); + $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, SqlOutputWalker::class); $paginator = new Paginator($query); diff --git a/tests/Tests/ORM/Functional/ParserResultSerializationTest.php b/tests/Tests/ORM/Functional/ParserResultSerializationTest.php index 6918bd8e50b..af247a35b87 100644 --- a/tests/Tests/ORM/Functional/ParserResultSerializationTest.php +++ b/tests/Tests/ORM/Functional/ParserResultSerializationTest.php @@ -14,6 +14,7 @@ use Doctrine\Tests\OrmFunctionalTestCase; use Generator; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\WithoutErrorHandler; use ReflectionMethod; use Symfony\Component\VarExporter\Instantiator; use Symfony\Component\VarExporter\VarExporter; @@ -34,6 +35,7 @@ protected function setUp(): void /** @param Closure(ParserResult): ParserResult $toSerializedAndBack */ #[DataProvider('provideToSerializedAndBack')] + #[WithoutErrorHandler] public function testSerializeParserResultForQueryWithSqlWalker(Closure $toSerializedAndBack): void { $query = $this->_em diff --git a/tests/Tests/ORM/Mapping/ClassMetadataTest.php b/tests/Tests/ORM/Mapping/ClassMetadataTest.php index 296c655d743..52e5853c8a1 100644 --- a/tests/Tests/ORM/Mapping/ClassMetadataTest.php +++ b/tests/Tests/ORM/Mapping/ClassMetadataTest.php @@ -52,6 +52,7 @@ use DoctrineGlobalArticle; use LogicException; use PHPUnit\Framework\Attributes\Group as TestGroup; +use PHPUnit\Framework\Attributes\WithoutErrorHandler; use ReflectionClass; use stdClass; @@ -1074,6 +1075,7 @@ public function testItAddingLifecycleCallbackOnEmbeddedClassIsIllegal(): void $metadata->addLifecycleCallback('foo', 'bar'); } + #[WithoutErrorHandler] public function testGettingAnFQCNForNullIsDeprecated(): void { $metadata = new ClassMetadata(self::class); @@ -1112,6 +1114,7 @@ public function testClassNameMappingDiscriminatorValue(): void ); } + #[WithoutErrorHandler] public function testDiscriminatorMapWithSameClassMultipleTimesDeprecated(): void { $this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/issues/3519'); diff --git a/tests/Tests/ORM/Mapping/TableMappingTest.php b/tests/Tests/ORM/Mapping/TableMappingTest.php index 24031eafa41..50ceaa5fce5 100644 --- a/tests/Tests/ORM/Mapping/TableMappingTest.php +++ b/tests/Tests/ORM/Mapping/TableMappingTest.php @@ -6,12 +6,14 @@ use Doctrine\Deprecations\PHPUnit\VerifyDeprecations; use Doctrine\ORM\Mapping\Table; +use PHPUnit\Framework\Attributes\WithoutErrorHandler; use PHPUnit\Framework\TestCase; final class TableMappingTest extends TestCase { use VerifyDeprecations; + #[WithoutErrorHandler] public function testDeprecationOnIndexesPropertyIsTriggered(): void { $this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/11357'); @@ -19,6 +21,7 @@ public function testDeprecationOnIndexesPropertyIsTriggered(): void new Table(indexes: []); } + #[WithoutErrorHandler] public function testDeprecationOnUniqueConstraintsPropertyIsTriggered(): void { $this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/11357');