From 73e30df52bae96f54e583b72074e67094197f5af Mon Sep 17 00:00:00 2001 From: MatteoFeltrin Date: Tue, 14 May 2024 15:06:47 +0200 Subject: [PATCH 1/6] allow classname in 'value' attribute of xml discriminator-mapping field --- doctrine-mapping.xsd | 2 +- tests/Tests/Models/Customer/CustomerType.php | 16 ++++++++++++++++ tests/Tests/Models/Customer/ExternalCustomer.php | 13 +++++++++++++ tests/Tests/Models/Customer/InternalCustomer.php | 13 +++++++++++++ tests/Tests/ORM/Mapping/ClassMetadataTest.php | 16 ++++++++++++++++ ...ne.Tests.Models.Customer.CustomerType.dcm.xml | 14 ++++++++++++++ 6 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 tests/Tests/Models/Customer/CustomerType.php create mode 100644 tests/Tests/Models/Customer/ExternalCustomer.php create mode 100644 tests/Tests/Models/Customer/InternalCustomer.php create mode 100644 tests/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Customer.CustomerType.dcm.xml diff --git a/doctrine-mapping.xsd b/doctrine-mapping.xsd index a058787746c..651c9d29c09 100644 --- a/doctrine-mapping.xsd +++ b/doctrine-mapping.xsd @@ -375,7 +375,7 @@ - + diff --git a/tests/Tests/Models/Customer/CustomerType.php b/tests/Tests/Models/Customer/CustomerType.php new file mode 100644 index 00000000000..bd68c07ecf2 --- /dev/null +++ b/tests/Tests/Models/Customer/CustomerType.php @@ -0,0 +1,16 @@ +name = $name; + } +} diff --git a/tests/Tests/Models/Customer/ExternalCustomer.php b/tests/Tests/Models/Customer/ExternalCustomer.php new file mode 100644 index 00000000000..cf50d3e85e0 --- /dev/null +++ b/tests/Tests/Models/Customer/ExternalCustomer.php @@ -0,0 +1,13 @@ +getAssociationMappedByTargetField('foo'); } + + public function testClassNameMappingDiscriminatorValue(): void + { + $driver = new XmlDriver( + __DIR__ . '/xml', + XmlDriver::DEFAULT_FILE_EXTENSION, + true + ); + $xmlElement = $driver->getElement(CustomerType::class); + self::assertEquals( + 'Doctrine\Tests\Models\Customer\InternalCustomer', + $xmlElement->children()->{'discriminator-map'}->{'discriminator-mapping'}[0]->attributes()['value'] + ); + } } /** @MappedSuperclass */ diff --git a/tests/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Customer.CustomerType.dcm.xml b/tests/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Customer.CustomerType.dcm.xml new file mode 100644 index 00000000000..8767e3220a8 --- /dev/null +++ b/tests/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Customer.CustomerType.dcm.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + From 2ec2030ab2b5eb14157ec8307286a352c898dc97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sat, 12 Oct 2024 15:40:48 +0200 Subject: [PATCH 2/6] Experiment with literalinclude I think it would be great to use literalinclude for big code snippets, because our IDEs could warn us about issues, and it would be easily to showcase our coding standard. Before we do that though, let us validate that it renders as expected. I have picked a complex example where we have a configuration block. --- .../working-with-indexed-associations.rst | 167 +----------------- .../Market-annotations.php | 74 ++++++++ .../Market.php | 68 +++++++ .../market.xml | 16 ++ .../market.yaml | 15 ++ 5 files changed, 181 insertions(+), 159 deletions(-) create mode 100644 docs/en/tutorials/working-with-indexed-associations/Market-annotations.php create mode 100644 docs/en/tutorials/working-with-indexed-associations/Market.php create mode 100644 docs/en/tutorials/working-with-indexed-associations/market.xml create mode 100644 docs/en/tutorials/working-with-indexed-associations/market.yaml diff --git a/docs/en/tutorials/working-with-indexed-associations.rst b/docs/en/tutorials/working-with-indexed-associations.rst index c4099eb5589..81032ee8e4a 100644 --- a/docs/en/tutorials/working-with-indexed-associations.rst +++ b/docs/en/tutorials/working-with-indexed-associations.rst @@ -31,169 +31,18 @@ You can map indexed associations by adding: The code and mappings for the Market entity looks like this: .. configuration-block:: - .. code-block:: attribute - - */ - #[OneToMany(targetEntity: Stock::class, mappedBy: 'market', indexBy: 'symbol')] - private Collection $stocks; - - public function __construct(string $name) - { - $this->name = $name; - $this->stocks = new ArrayCollection(); - } - - public function getId(): int|null - { - return $this->id; - } - - public function getName(): string - { - return $this->name; - } - - public function addStock(Stock $stock): void - { - $this->stocks[$stock->getSymbol()] = $stock; - } + .. literalinclude:: working-with-indexed-associations/Market.php + :language: attribute - public function getStock(string $symbol): Stock - { - if (!isset($this->stocks[$symbol])) { - throw new \InvalidArgumentException("Symbol is not traded on this market."); - } - - return $this->stocks[$symbol]; - } - - /** @return array */ - public function getStocks(): array - { - return $this->stocks->toArray(); - } - } - - .. code-block:: annotation - - - */ - private Collection $stocks; - - public function __construct($name) - { - $this->name = $name; - $this->stocks = new ArrayCollection(); - } - - public function getId(): int|null - { - return $this->id; - } - - public function getName(): string - { - return $this->name; - } - - public function addStock(Stock $stock): void - { - $this->stocks[$stock->getSymbol()] = $stock; - } - - public function getStock($symbol): Stock - { - if (!isset($this->stocks[$symbol])) { - throw new \InvalidArgumentException("Symbol is not traded on this market."); - } - - return $this->stocks[$symbol]; - } - - /** @return array */ - public function getStocks(): array - { - return $this->stocks->toArray(); - } - } - - .. code-block:: xml - - - - - - - - - - - - - - - - .. code-block:: yaml - - Doctrine\Tests\Models\StockExchange\Market: - type: entity - id: - id: - type: integer - generator: - strategy: AUTO - fields: - name: - type:string - oneToMany: - stocks: - targetEntity: Stock - mappedBy: market - indexBy: symbol Inside the ``addStock()`` method you can see how we directly set the key of the association to the symbol, so that we can work with the indexed association directly after invoking ``addStock()``. Inside ``getStock($symbol)`` diff --git a/docs/en/tutorials/working-with-indexed-associations/Market-annotations.php b/docs/en/tutorials/working-with-indexed-associations/Market-annotations.php new file mode 100644 index 00000000000..798b49d1d02 --- /dev/null +++ b/docs/en/tutorials/working-with-indexed-associations/Market-annotations.php @@ -0,0 +1,74 @@ + + */ + private Collection $stocks; + + public function __construct($name) + { + $this->name = $name; + $this->stocks = new ArrayCollection(); + } + + public function getId(): int|null + { + return $this->id; + } + + public function getName(): string + { + return $this->name; + } + + public function addStock(Stock $stock): void + { + $this->stocks[$stock->getSymbol()] = $stock; + } + + public function getStock($symbol): Stock + { + if (!isset($this->stocks[$symbol])) { + throw new InvalidArgumentException("Symbol is not traded on this market."); + } + + return $this->stocks[$symbol]; + } + + /** @return array */ + public function getStocks(): array + { + return $this->stocks->toArray(); + } +} diff --git a/docs/en/tutorials/working-with-indexed-associations/Market.php b/docs/en/tutorials/working-with-indexed-associations/Market.php new file mode 100644 index 00000000000..bb16d3902b3 --- /dev/null +++ b/docs/en/tutorials/working-with-indexed-associations/Market.php @@ -0,0 +1,68 @@ + */ + #[OneToMany(targetEntity: Stock::class, mappedBy: 'market', indexBy: 'symbol')] + private Collection $stocks; + + public function __construct(string $name) + { + $this->name = $name; + $this->stocks = new ArrayCollection(); + } + + public function getId(): int|null + { + return $this->id; + } + + public function getName(): string + { + return $this->name; + } + + public function addStock(Stock $stock): void + { + $this->stocks[$stock->getSymbol()] = $stock; + } + + public function getStock(string $symbol): Stock + { + if (! isset($this->stocks[$symbol])) { + throw new InvalidArgumentException('Symbol is not traded on this market.'); + } + + return $this->stocks[$symbol]; + } + + /** @return array */ + public function getStocks(): array + { + return $this->stocks->toArray(); + } +} diff --git a/docs/en/tutorials/working-with-indexed-associations/market.xml b/docs/en/tutorials/working-with-indexed-associations/market.xml new file mode 100644 index 00000000000..3fc9fa2a857 --- /dev/null +++ b/docs/en/tutorials/working-with-indexed-associations/market.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + diff --git a/docs/en/tutorials/working-with-indexed-associations/market.yaml b/docs/en/tutorials/working-with-indexed-associations/market.yaml new file mode 100644 index 00000000000..b7c8132e090 --- /dev/null +++ b/docs/en/tutorials/working-with-indexed-associations/market.yaml @@ -0,0 +1,15 @@ +Doctrine\Tests\Models\StockExchange\Market: + type: entity + id: + id: + type: integer + generator: + strategy: AUTO + fields: + name: + type:string + oneToMany: + stocks: + targetEntity: Stock + mappedBy: market + indexBy: symbol From 32682aa14d14bf2ddded8719ec825bb82e4768f0 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sun, 13 Oct 2024 21:17:33 +0200 Subject: [PATCH 3/6] Fix PHPUnit deprecations --- .../ORM/Cache/DefaultCacheFactoryTest.php | 12 ++++----- ...ReadWriteCachedCollectionPersisterTest.php | 4 +-- ...rictReadWriteCachedEntityPersisterTest.php | 2 +- .../ReadWriteCachedEntityPersisterTest.php | 18 ++++++------- .../ORM/Functional/PostLoadEventTest.php | 27 +++++++------------ tests/Tests/ORM/Functional/SQLFilterTest.php | 18 ++++++------- .../ORM/Functional/Ticket/DDC2359Test.php | 10 +++---- .../ORM/Hydration/ObjectHydratorTest.php | 4 +-- .../Internal/HydrationCompleteHandlerTest.php | 8 +++--- .../Tests/ORM/LazyCriteriaCollectionTest.php | 14 +++++----- .../ORM/Mapping/ClassMetadataFactoryTest.php | 2 +- .../ReflectionPropertiesGetterTest.php | 4 +-- tests/Tests/ORM/Proxy/ProxyFactoryTest.php | 8 +++--- .../ORM/Query/SqlExpressionVisitorTest.php | 2 +- .../DefaultRepositoryFactoryTest.php | 12 ++++----- 15 files changed, 68 insertions(+), 77 deletions(-) diff --git a/tests/Tests/ORM/Cache/DefaultCacheFactoryTest.php b/tests/Tests/ORM/Cache/DefaultCacheFactoryTest.php index d8427a7f966..0a3680d7140 100644 --- a/tests/Tests/ORM/Cache/DefaultCacheFactoryTest.php +++ b/tests/Tests/ORM/Cache/DefaultCacheFactoryTest.php @@ -77,7 +77,7 @@ public function testBuildCachedEntityPersisterReadOnly(): void $this->factory->expects(self::once()) ->method('getRegion') ->with(self::equalTo($metadata->cache)) - ->will(self::returnValue($region)); + ->willReturn($region); $cachedPersister = $this->factory->buildCachedEntityPersister($em, $persister, $metadata); @@ -97,7 +97,7 @@ public function testBuildCachedEntityPersisterReadWrite(): void $this->factory->expects(self::once()) ->method('getRegion') ->with(self::equalTo($metadata->cache)) - ->will(self::returnValue($region)); + ->willReturn($region); $cachedPersister = $this->factory->buildCachedEntityPersister($em, $persister, $metadata); @@ -117,7 +117,7 @@ public function testBuildCachedEntityPersisterNonStrictReadWrite(): void $this->factory->expects(self::once()) ->method('getRegion') ->with(self::equalTo($metadata->cache)) - ->will(self::returnValue($region)); + ->willReturn($region); $cachedPersister = $this->factory->buildCachedEntityPersister($em, $persister, $metadata); @@ -138,7 +138,7 @@ public function testBuildCachedCollectionPersisterReadOnly(): void $this->factory->expects(self::once()) ->method('getRegion') ->with(self::equalTo($mapping['cache'])) - ->will(self::returnValue($region)); + ->willReturn($region); $cachedPersister = $this->factory->buildCachedCollectionPersister($em, $persister, $mapping); @@ -159,7 +159,7 @@ public function testBuildCachedCollectionPersisterReadWrite(): void $this->factory->expects(self::once()) ->method('getRegion') ->with(self::equalTo($mapping['cache'])) - ->will(self::returnValue($region)); + ->willReturn($region); $cachedPersister = $this->factory->buildCachedCollectionPersister($em, $persister, $mapping); @@ -180,7 +180,7 @@ public function testBuildCachedCollectionPersisterNonStrictReadWrite(): void $this->factory->expects(self::once()) ->method('getRegion') ->with(self::equalTo($mapping['cache'])) - ->will(self::returnValue($region)); + ->willReturn($region); $cachedPersister = $this->factory->buildCachedCollectionPersister($em, $persister, $mapping); diff --git a/tests/Tests/ORM/Cache/Persister/Collection/ReadWriteCachedCollectionPersisterTest.php b/tests/Tests/ORM/Cache/Persister/Collection/ReadWriteCachedCollectionPersisterTest.php index 66c51df0a0f..f06845db9f2 100644 --- a/tests/Tests/ORM/Cache/Persister/Collection/ReadWriteCachedCollectionPersisterTest.php +++ b/tests/Tests/ORM/Cache/Persister/Collection/ReadWriteCachedCollectionPersisterTest.php @@ -253,7 +253,7 @@ public function testDeleteLockFailureShouldIgnoreQueue(): void $this->region->expects(self::once()) ->method('lock') ->with(self::equalTo($key)) - ->will(self::returnValue(null)); + ->willReturn(null); $this->collectionPersister->expects(self::once()) ->method('delete') @@ -278,7 +278,7 @@ public function testUpdateLockFailureShouldIgnoreQueue(): void $this->region->expects(self::once()) ->method('lock') ->with(self::equalTo($key)) - ->will(self::returnValue(null)); + ->willReturn(null); $this->collectionPersister->expects(self::once()) ->method('update') diff --git a/tests/Tests/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersisterTest.php b/tests/Tests/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersisterTest.php index 71ae563bdde..35ea9ca86b6 100644 --- a/tests/Tests/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersisterTest.php +++ b/tests/Tests/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersisterTest.php @@ -63,7 +63,7 @@ public function testInsertTransactionCommitShouldPutCache(): void $this->entityPersister->expects(self::once()) ->method('getInserts') - ->will(self::returnValue([$entity])); + ->willReturn([$entity]); $this->entityPersister->expects(self::once()) ->method('executeInserts'); diff --git a/tests/Tests/ORM/Cache/Persister/Entity/ReadWriteCachedEntityPersisterTest.php b/tests/Tests/ORM/Cache/Persister/Entity/ReadWriteCachedEntityPersisterTest.php index b7c279c6d2b..e8f2e38db4c 100644 --- a/tests/Tests/ORM/Cache/Persister/Entity/ReadWriteCachedEntityPersisterTest.php +++ b/tests/Tests/ORM/Cache/Persister/Entity/ReadWriteCachedEntityPersisterTest.php @@ -39,7 +39,7 @@ public function testDeleteShouldLockItem(): void $this->region->expects(self::once()) ->method('lock') ->with(self::equalTo($key)) - ->will(self::returnValue($lock)); + ->willReturn($lock); $this->em->getUnitOfWork()->registerManaged($entity, ['id' => 1], ['id' => 1, 'name' => 'Foo']); @@ -56,7 +56,7 @@ public function testUpdateShouldLockItem(): void $this->region->expects(self::once()) ->method('lock') ->with(self::equalTo($key)) - ->will(self::returnValue($lock)); + ->willReturn($lock); $this->em->getUnitOfWork()->registerManaged($entity, ['id' => 1], ['id' => 1, 'name' => 'Foo']); @@ -73,12 +73,12 @@ public function testUpdateTransactionRollBackShouldEvictItem(): void $this->region->expects(self::once()) ->method('lock') ->with(self::equalTo($key)) - ->will(self::returnValue($lock)); + ->willReturn($lock); $this->region->expects(self::once()) ->method('evict') ->with(self::equalTo($key)) - ->will(self::returnValue($lock)); + ->willReturn($lock); $this->em->getUnitOfWork()->registerManaged($entity, ['id' => 1], ['id' => 1, 'name' => 'Foo']); @@ -96,7 +96,7 @@ public function testDeleteTransactionRollBackShouldEvictItem(): void $this->region->expects(self::once()) ->method('lock') ->with(self::equalTo($key)) - ->will(self::returnValue($lock)); + ->willReturn($lock); $this->region->expects(self::once()) ->method('evict') @@ -121,7 +121,7 @@ public function testTransactionRollBackShouldClearQueue(): void $this->region->expects(self::exactly(2)) ->method('lock') ->with(self::equalTo($key)) - ->will(self::returnValue($lock)); + ->willReturn($lock); $this->region->expects(self::exactly(2)) ->method('evict') @@ -152,7 +152,7 @@ public function testTransactionCommitShouldClearQueue(): void $this->region->expects(self::exactly(2)) ->method('lock') ->with(self::equalTo($key)) - ->will(self::returnValue($lock)); + ->willReturn($lock); $this->region->expects(self::exactly(2)) ->method('evict') @@ -182,7 +182,7 @@ public function testDeleteLockFailureShouldIgnoreQueue(): void $this->region->expects(self::once()) ->method('lock') ->with(self::equalTo($key)) - ->will(self::returnValue(null)); + ->willReturn(null); $this->entityPersister->expects(self::once()) ->method('delete') @@ -206,7 +206,7 @@ public function testUpdateLockFailureShouldIgnoreQueue(): void $this->region->expects(self::once()) ->method('lock') ->with(self::equalTo($key)) - ->will(self::returnValue(null)); + ->willReturn(null); $this->entityPersister->expects(self::once()) ->method('update') diff --git a/tests/Tests/ORM/Functional/PostLoadEventTest.php b/tests/Tests/ORM/Functional/PostLoadEventTest.php index 7963ee89774..8d6ee3b9c15 100644 --- a/tests/Tests/ORM/Functional/PostLoadEventTest.php +++ b/tests/Tests/ORM/Functional/PostLoadEventTest.php @@ -35,8 +35,7 @@ public function testLoadedEntityUsingFindShouldTriggerEvent(): void // CmsUser and CmsAddres, because it's a ToOne inverse side on CmsUser $mockListener ->expects(self::exactly(2)) - ->method('postLoad') - ->will(self::returnValue(true)); + ->method('postLoad'); $eventManager = $this->_em->getEventManager(); @@ -52,8 +51,7 @@ public function testLoadedEntityUsingQueryShouldTriggerEvent(): void // CmsUser and CmsAddres, because it's a ToOne inverse side on CmsUser $mockListener ->expects(self::exactly(2)) - ->method('postLoad') - ->will(self::returnValue(true)); + ->method('postLoad'); $eventManager = $this->_em->getEventManager(); @@ -72,8 +70,7 @@ public function testLoadedAssociationToOneShouldTriggerEvent(): void // CmsUser (root), CmsAddress (ToOne inverse side), CmsEmail (joined association) $mockListener ->expects(self::exactly(3)) - ->method('postLoad') - ->will(self::returnValue(true)); + ->method('postLoad'); $eventManager = $this->_em->getEventManager(); @@ -92,8 +89,7 @@ public function testLoadedAssociationToManyShouldTriggerEvent(): void // CmsUser (root), CmsAddress (ToOne inverse side), 2 CmsPhonenumber (joined association) $mockListener ->expects(self::exactly(4)) - ->method('postLoad') - ->will(self::returnValue(true)); + ->method('postLoad'); $eventManager = $this->_em->getEventManager(); @@ -114,8 +110,7 @@ public function testLoadedProxyEntityShouldTriggerEvent(): void $mockListener ->expects(self::never()) - ->method('postLoad') - ->will(self::returnValue(true)); + ->method('postLoad'); $eventManager->addEventListener([Events::postLoad], $mockListener); @@ -128,8 +123,7 @@ public function testLoadedProxyEntityShouldTriggerEvent(): void $mockListener2 ->expects(self::exactly(2)) - ->method('postLoad') - ->will(self::returnValue(true)); + ->method('postLoad'); $eventManager->addEventListener([Events::postLoad], $mockListener2); @@ -146,8 +140,7 @@ public function testLoadedProxyPartialShouldTriggerEvent(): void // CmsUser (partially loaded), CmsAddress (inverse ToOne), 2 CmsPhonenumber $mockListener ->expects(self::exactly(4)) - ->method('postLoad') - ->will(self::returnValue(true)); + ->method('postLoad'); $eventManager->addEventListener([Events::postLoad], $mockListener); @@ -166,8 +159,7 @@ public function testLoadedProxyAssociationToOneShouldTriggerEvent(): void // CmsEmail (proxy) $mockListener ->expects(self::exactly(1)) - ->method('postLoad') - ->will(self::returnValue(true)); + ->method('postLoad'); $eventManager = $this->_em->getEventManager(); @@ -187,8 +179,7 @@ public function testLoadedProxyAssociationToManyShouldTriggerEvent(): void // 2 CmsPhonenumber (proxy) $mockListener ->expects(self::exactly(2)) - ->method('postLoad') - ->will(self::returnValue(true)); + ->method('postLoad'); $eventManager = $this->_em->getEventManager(); diff --git a/tests/Tests/ORM/Functional/SQLFilterTest.php b/tests/Tests/ORM/Functional/SQLFilterTest.php index 8abb2b6636a..a4c8823c834 100644 --- a/tests/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Tests/ORM/Functional/SQLFilterTest.php @@ -255,7 +255,7 @@ private function addMockFilterCollection(EntityManagerInterface $em): FilterColl $em->expects(self::any()) ->method('getFilters') - ->will(self::returnValue($filterCollection)); + ->willReturn($filterCollection); return $filterCollection; } @@ -267,12 +267,12 @@ public function testSQLFilterGetSetParameter(): void $conn->expects(self::once()) ->method('quote') ->with(self::equalTo('en')) - ->will(self::returnValue("'en'")); + ->willReturn("'en'"); $em = $this->getMockEntityManager(); $em->expects(self::once()) ->method('getConnection') - ->will(self::returnValue($conn)); + ->willReturn($conn); $filterCollection = $this->addMockFilterCollection($em); $filterCollection @@ -298,7 +298,7 @@ public function testSQLFilterGetConnection(): void $em = $this->getMockEntityManager(); $em->expects(self::once()) ->method('getConnection') - ->will(self::returnValue($conn)); + ->willReturn($conn); $filter = new MyLocaleFilter($em); @@ -315,12 +315,12 @@ public function testSQLFilterSetParameterInfersType(): void $conn->expects(self::once()) ->method('quote') ->with(self::equalTo('en')) - ->will(self::returnValue("'en'")); + ->willReturn("'en'"); $em = $this->getMockEntityManager(); $em->expects(self::once()) ->method('getConnection') - ->will(self::returnValue($conn)); + ->willReturn($conn); $filterCollection = $this->addMockFilterCollection($em); $filterCollection @@ -339,13 +339,13 @@ public function testSQLFilterSetArrayParameterInfersType(): void // Setup mock connection $conn = $this->getMockConnection(); $conn->method('quote') - ->will(self::returnCallback(static function ($value) { + ->willReturnCallback(static function ($value) { return "'" . $value . "'"; - })); + }); $em = $this->getMockEntityManager(); $em->method('getConnection') - ->will(self::returnValue($conn)); + ->willReturn($conn); $filterCollection = $this->addMockFilterCollection($em); $filterCollection diff --git a/tests/Tests/ORM/Functional/Ticket/DDC2359Test.php b/tests/Tests/ORM/Functional/Ticket/DDC2359Test.php index 29f82d0c56d..882f6bcee60 100644 --- a/tests/Tests/ORM/Functional/Ticket/DDC2359Test.php +++ b/tests/Tests/ORM/Functional/Ticket/DDC2359Test.php @@ -45,15 +45,15 @@ public function testIssue(): void $configuration ->method('getMetadataDriverImpl') - ->will(self::returnValue($mockDriver)); + ->willReturn($mockDriver); - $entityManager->expects(self::any())->method('getConfiguration')->will(self::returnValue($configuration)); - $entityManager->expects(self::any())->method('getConnection')->will(self::returnValue($connection)); + $entityManager->expects(self::any())->method('getConfiguration')->willReturn($configuration); + $entityManager->expects(self::any())->method('getConnection')->willReturn($connection); $entityManager ->method('getEventManager') - ->will(self::returnValue($this->createMock(EventManager::class))); + ->willReturn($this->createMock(EventManager::class)); - $metadataFactory->method('newClassMetadataInstance')->will(self::returnValue($mockMetadata)); + $metadataFactory->method('newClassMetadataInstance')->willReturn($mockMetadata); $metadataFactory->expects(self::once())->method('wakeupReflection'); $metadataFactory->setEntityManager($entityManager); diff --git a/tests/Tests/ORM/Hydration/ObjectHydratorTest.php b/tests/Tests/ORM/Hydration/ObjectHydratorTest.php index 37c36d18a8e..712a8cf411c 100644 --- a/tests/Tests/ORM/Hydration/ObjectHydratorTest.php +++ b/tests/Tests/ORM/Hydration/ObjectHydratorTest.php @@ -1036,7 +1036,7 @@ public function testCreatesProxyForLazyLoadingWithForeignKeys(): void $proxyFactory->expects(self::once()) ->method('getProxy') ->with(self::equalTo(ECommerceShipping::class), ['id' => 42]) - ->will(self::returnValue($proxyInstance)); + ->willReturn($proxyInstance); $this->entityManager->setProxyFactory($proxyFactory); @@ -1084,7 +1084,7 @@ public function testCreatesProxyForLazyLoadingWithForeignKeysWithAliasedProductE $proxyFactory->expects(self::once()) ->method('getProxy') ->with(self::equalTo(ECommerceShipping::class), ['id' => 42]) - ->will(self::returnValue($proxyInstance)); + ->willReturn($proxyInstance); $this->entityManager->setProxyFactory($proxyFactory); diff --git a/tests/Tests/ORM/Internal/HydrationCompleteHandlerTest.php b/tests/Tests/ORM/Internal/HydrationCompleteHandlerTest.php index ff2e023791f..a9402481e9e 100644 --- a/tests/Tests/ORM/Internal/HydrationCompleteHandlerTest.php +++ b/tests/Tests/ORM/Internal/HydrationCompleteHandlerTest.php @@ -53,7 +53,7 @@ public function testDefersPostLoadOfEntity(int $listenersFlag): void ->expects(self::any()) ->method('getSubscribedSystems') ->with($metadata) - ->will(self::returnValue($listenersFlag)); + ->willReturn($listenersFlag); $this->handler->deferPostLoadInvoking($metadata, $entity); @@ -86,7 +86,7 @@ public function testDefersPostLoadOfEntityOnlyOnce(int $listenersFlag): void ->expects(self::any()) ->method('getSubscribedSystems') ->with($metadata) - ->will(self::returnValue($listenersFlag)); + ->willReturn($listenersFlag); $this->handler->deferPostLoadInvoking($metadata, $entity); @@ -110,7 +110,7 @@ public function testDefersMultiplePostLoadOfEntity(int $listenersFlag): void ->expects(self::any()) ->method('getSubscribedSystems') ->with(self::logicalOr($metadata1, $metadata2)) - ->will(self::returnValue($listenersFlag)); + ->willReturn($listenersFlag); $this->handler->deferPostLoadInvoking($metadata1, $entity1); $this->handler->deferPostLoadInvoking($metadata2, $entity2); @@ -144,7 +144,7 @@ public function testSkipsDeferredPostLoadOfMetadataWithNoInvokedListeners(): voi ->expects(self::any()) ->method('getSubscribedSystems') ->with($metadata) - ->will(self::returnValue(ListenersInvoker::INVOKE_NONE)); + ->willReturn(ListenersInvoker::INVOKE_NONE); $this->handler->deferPostLoadInvoking($metadata, $entity); diff --git a/tests/Tests/ORM/LazyCriteriaCollectionTest.php b/tests/Tests/ORM/LazyCriteriaCollectionTest.php index 02489d9f54e..6b8776c130d 100644 --- a/tests/Tests/ORM/LazyCriteriaCollectionTest.php +++ b/tests/Tests/ORM/LazyCriteriaCollectionTest.php @@ -33,7 +33,7 @@ protected function setUp(): void public function testCountIsCached(): void { - $this->persister->expects(self::once())->method('count')->with($this->criteria)->will(self::returnValue(10)); + $this->persister->expects(self::once())->method('count')->with($this->criteria)->willReturn(10); self::assertSame(10, $this->lazyCriteriaCollection->count()); self::assertSame(10, $this->lazyCriteriaCollection->count()); @@ -42,7 +42,7 @@ public function testCountIsCached(): void public function testCountIsCachedEvenWithZeroResult(): void { - $this->persister->expects(self::once())->method('count')->with($this->criteria)->will(self::returnValue(0)); + $this->persister->expects(self::once())->method('count')->with($this->criteria)->willReturn(0); self::assertSame(0, $this->lazyCriteriaCollection->count()); self::assertSame(0, $this->lazyCriteriaCollection->count()); @@ -56,7 +56,7 @@ public function testCountUsesWrappedCollectionWhenInitialized(): void ->expects(self::once()) ->method('loadCriteria') ->with($this->criteria) - ->will(self::returnValue(['foo', 'bar', 'baz'])); + ->willReturn(['foo', 'bar', 'baz']); // should never call the persister's count $this->persister->expects(self::never())->method('count'); @@ -81,7 +81,7 @@ public function testMatchingUsesThePersisterOnlyOnce(): void ->expects(self::once()) ->method('loadCriteria') ->with($this->criteria) - ->will(self::returnValue([$foo, $bar, $baz])); + ->willReturn([$foo, $bar, $baz]); $criteria = new Criteria(); @@ -97,14 +97,14 @@ public function testMatchingUsesThePersisterOnlyOnce(): void public function testIsEmptyUsesCountWhenNotInitialized(): void { - $this->persister->expects(self::once())->method('count')->with($this->criteria)->will(self::returnValue(0)); + $this->persister->expects(self::once())->method('count')->with($this->criteria)->willReturn(0); self::assertTrue($this->lazyCriteriaCollection->isEmpty()); } public function testIsEmptyIsFalseIfCountIsNotZero(): void { - $this->persister->expects(self::once())->method('count')->with($this->criteria)->will(self::returnValue(1)); + $this->persister->expects(self::once())->method('count')->with($this->criteria)->willReturn(1); self::assertFalse($this->lazyCriteriaCollection->isEmpty()); } @@ -116,7 +116,7 @@ public function testIsEmptyUsesWrappedCollectionWhenInitialized(): void ->expects(self::once()) ->method('loadCriteria') ->with($this->criteria) - ->will(self::returnValue(['foo', 'bar', 'baz'])); + ->willReturn(['foo', 'bar', 'baz']); // should never call the persister's count $this->persister->expects(self::never())->method('count'); diff --git a/tests/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index 00f85b01f5d..bea5e2578da 100644 --- a/tests/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -320,7 +320,7 @@ public function testGetAllMetadataWorksWithBadConnection(): void $conn->expects(self::any()) ->method('getDatabasePlatform') - ->will(self::throwException(new Exception('Exception thrown in test when calling getDatabasePlatform'))); + ->willThrowException(new Exception('Exception thrown in test when calling getDatabasePlatform')); $cmf = new ClassMetadataFactory(); $cmf->setEntityManager($em); diff --git a/tests/Tests/ORM/Mapping/Reflection/ReflectionPropertiesGetterTest.php b/tests/Tests/ORM/Mapping/Reflection/ReflectionPropertiesGetterTest.php index d608b939efc..9d5271add83 100644 --- a/tests/Tests/ORM/Mapping/Reflection/ReflectionPropertiesGetterTest.php +++ b/tests/Tests/ORM/Mapping/Reflection/ReflectionPropertiesGetterTest.php @@ -101,10 +101,10 @@ public function testPropertyGetterWillSkipPropertiesNotRetrievedByTheRuntimeRefl ->expects(self::exactly(2)) ->method('getClass') ->with(self::logicalOr(ClassWithMixedProperties::class, ParentClass::class)) - ->will(self::returnValueMap([ + ->willReturnMap([ [ClassWithMixedProperties::class, new ReflectionClass(ClassWithMixedProperties::class)], [ParentClass::class, new ReflectionClass(ParentClass::class)], - ])); + ]); $reflectionService ->expects(self::atLeastOnce()) diff --git a/tests/Tests/ORM/Proxy/ProxyFactoryTest.php b/tests/Tests/ORM/Proxy/ProxyFactoryTest.php index e6335c46c8f..1b622f814b7 100644 --- a/tests/Tests/ORM/Proxy/ProxyFactoryTest.php +++ b/tests/Tests/ORM/Proxy/ProxyFactoryTest.php @@ -76,7 +76,7 @@ public function testReferenceProxyDelegatesLoadingToThePersister(): void ->expects(self::atLeastOnce()) ->method('loadById') ->with(self::equalTo($identifier)) - ->will(self::returnValue($proxy)); + ->willReturn($proxy); $proxy->getDescription(); } @@ -133,7 +133,7 @@ public function testFailedProxyLoadingDoesNotMarkTheProxyAsInitialized(): void $persister ->expects(self::atLeastOnce()) ->method('load') - ->will(self::returnValue(null)); + ->willReturn(null); try { $proxy->getDescription(); @@ -160,7 +160,7 @@ public function testExceptionOnProxyLoadingDoesNotMarkTheProxyAsInitialized(): v $persister ->expects(self::atLeastOnce()) ->method('load') - ->will(self::throwException($exception)); + ->willThrowException($exception); try { $proxy->getDescription(); @@ -186,7 +186,7 @@ public function testFailedProxyCloningDoesNotMarkTheProxyAsInitialized(): void $persister ->expects(self::atLeastOnce()) ->method('load') - ->will(self::returnValue(null)); + ->willReturn(null); try { $cloned = clone $proxy; diff --git a/tests/Tests/ORM/Query/SqlExpressionVisitorTest.php b/tests/Tests/ORM/Query/SqlExpressionVisitorTest.php index 140e0a540c8..680d8ca1ccd 100644 --- a/tests/Tests/ORM/Query/SqlExpressionVisitorTest.php +++ b/tests/Tests/ORM/Query/SqlExpressionVisitorTest.php @@ -41,7 +41,7 @@ public function testWalkNotCompositeExpression(): void $this->persister ->expects(self::once()) ->method('getSelectConditionStatementSQL') - ->will(self::returnValue('dummy expression')); + ->willReturn('dummy expression'); $expr = $this->visitor->walkCompositeExpression( $cb->not( diff --git a/tests/Tests/ORM/Repository/DefaultRepositoryFactoryTest.php b/tests/Tests/ORM/Repository/DefaultRepositoryFactoryTest.php index cfc2fc4f85d..f4260d232a7 100644 --- a/tests/Tests/ORM/Repository/DefaultRepositoryFactoryTest.php +++ b/tests/Tests/ORM/Repository/DefaultRepositoryFactoryTest.php @@ -40,7 +40,7 @@ protected function setUp(): void $this->configuration ->expects(self::any()) ->method('getDefaultRepositoryClassName') - ->will(self::returnValue(DDC869PaymentRepository::class)); + ->willReturn(DDC869PaymentRepository::class); } public function testCreatesRepositoryFromDefaultRepositoryClass(): void @@ -48,7 +48,7 @@ public function testCreatesRepositoryFromDefaultRepositoryClass(): void $this->entityManager ->expects(self::any()) ->method('getClassMetadata') - ->will(self::returnCallback(Closure::fromCallable([$this, 'buildClassMetadata']))); + ->willReturnCallback(Closure::fromCallable([$this, 'buildClassMetadata'])); self::assertInstanceOf( DDC869PaymentRepository::class, @@ -61,7 +61,7 @@ public function testCreatedRepositoriesAreCached(): void $this->entityManager ->expects(self::any()) ->method('getClassMetadata') - ->will(self::returnCallback(Closure::fromCallable([$this, 'buildClassMetadata']))); + ->willReturnCallback(Closure::fromCallable([$this, 'buildClassMetadata'])); self::assertSame( $this->repositoryFactory->getRepository($this->entityManager, self::class), @@ -77,7 +77,7 @@ public function testCreatesRepositoryFromCustomClassMetadata(): void $this->entityManager ->expects(self::any()) ->method('getClassMetadata') - ->will(self::returnValue($customMetadata)); + ->willReturn($customMetadata); self::assertInstanceOf( DDC753DefaultRepository::class, @@ -92,11 +92,11 @@ public function testCachesDistinctRepositoriesPerDistinctEntityManager(): void $em1->expects(self::any()) ->method('getClassMetadata') - ->will(self::returnCallback(Closure::fromCallable([$this, 'buildClassMetadata']))); + ->willReturnCallback(Closure::fromCallable([$this, 'buildClassMetadata'])); $em2->expects(self::any()) ->method('getClassMetadata') - ->will(self::returnCallback(Closure::fromCallable([$this, 'buildClassMetadata']))); + ->willReturnCallback(Closure::fromCallable([$this, 'buildClassMetadata'])); $repo1 = $this->repositoryFactory->getRepository($em1, self::class); $repo2 = $this->repositoryFactory->getRepository($em2, self::class); From 982d6060a3c71574a986da0f0e466669052791a5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Oct 2024 08:56:04 +0200 Subject: [PATCH 4/6] Bump doctrine/.github from 5.1.0 to 5.2.0 (#11680) From e47398ecc5eea7c6cc05e97c6086b1419298af59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 16 Oct 2024 22:08:16 +0200 Subject: [PATCH 5/6] Remove leftovers from Sphinx (#11683) We use phpDocumentor/guides now, no need for this. --- docs/en/_exts/configurationblock.py | 93 ----------------------- docs/en/make.bat | 113 ---------------------------- 2 files changed, 206 deletions(-) delete mode 100644 docs/en/_exts/configurationblock.py delete mode 100644 docs/en/make.bat diff --git a/docs/en/_exts/configurationblock.py b/docs/en/_exts/configurationblock.py deleted file mode 100644 index 36ca61f5b15..00000000000 --- a/docs/en/_exts/configurationblock.py +++ /dev/null @@ -1,93 +0,0 @@ -#Copyright (c) 2010 Fabien Potencier -# -#Permission is hereby granted, free of charge, to any person obtaining a copy -#of this software and associated documentation files (the "Software"), to deal -#in the Software without restriction, including without limitation the rights -#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -#copies of the Software, and to permit persons to whom the Software is furnished -#to do so, subject to the following conditions: -# -#The above copyright notice and this permission notice shall be included in all -#copies or substantial portions of the Software. -# -#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -#THE SOFTWARE. - -from docutils.parsers.rst import Directive, directives -from docutils import nodes -from string import upper - -class configurationblock(nodes.General, nodes.Element): - pass - -class ConfigurationBlock(Directive): - has_content = True - required_arguments = 0 - optional_arguments = 0 - final_argument_whitespace = True - option_spec = {} - formats = { - 'html': 'HTML', - 'xml': 'XML', - 'php': 'PHP', - 'yaml': 'YAML', - 'jinja': 'Twig', - 'html+jinja': 'Twig', - 'jinja+html': 'Twig', - 'php+html': 'PHP', - 'html+php': 'PHP', - 'ini': 'INI', - 'php-annotations': 'Annotations', - } - - def run(self): - env = self.state.document.settings.env - - node = nodes.Element() - node.document = self.state.document - self.state.nested_parse(self.content, self.content_offset, node) - - entries = [] - for i, child in enumerate(node): - if isinstance(child, nodes.literal_block): - # add a title (the language name) before each block - #targetid = "configuration-block-%d" % env.new_serialno('configuration-block') - #targetnode = nodes.target('', '', ids=[targetid]) - #targetnode.append(child) - - innernode = nodes.emphasis(self.formats[child['language']], self.formats[child['language']]) - - para = nodes.paragraph() - para += [innernode, child] - - entry = nodes.list_item('') - entry.append(para) - entries.append(entry) - - resultnode = configurationblock() - resultnode.append(nodes.bullet_list('', *entries)) - - return [resultnode] - -def visit_configurationblock_html(self, node): - self.body.append(self.starttag(node, 'div', CLASS='configuration-block')) - -def depart_configurationblock_html(self, node): - self.body.append('\n') - -def visit_configurationblock_latex(self, node): - pass - -def depart_configurationblock_latex(self, node): - pass - -def setup(app): - app.add_node(configurationblock, - html=(visit_configurationblock_html, depart_configurationblock_html), - latex=(visit_configurationblock_latex, depart_configurationblock_latex)) - app.add_directive('configuration-block', ConfigurationBlock) diff --git a/docs/en/make.bat b/docs/en/make.bat deleted file mode 100644 index 38fcba6007a..00000000000 --- a/docs/en/make.bat +++ /dev/null @@ -1,113 +0,0 @@ -@ECHO OFF - -REM Command file for Sphinx documentation - -set SPHINXBUILD=sphinx-build -set BUILDDIR=_build -set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . -if NOT "%PAPER%" == "" ( - set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% -) - -if "%1" == "" goto help - -if "%1" == "help" ( - :help - echo.Please use `make ^` where ^ is one of - echo. html to make standalone HTML files - echo. dirhtml to make HTML files named index.html in directories - echo. pickle to make pickle files - echo. json to make JSON files - echo. htmlhelp to make HTML files and a HTML help project - echo. qthelp to make HTML files and a qthelp project - echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter - echo. changes to make an overview over all changed/added/deprecated items - echo. linkcheck to check all external links for integrity - echo. doctest to run all doctests embedded in the documentation if enabled - goto end -) - -if "%1" == "clean" ( - for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i - del /q /s %BUILDDIR%\* - goto end -) - -if "%1" == "html" ( - %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html - echo. - echo.Build finished. The HTML pages are in %BUILDDIR%/html. - goto end -) - -if "%1" == "dirhtml" ( - %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml - echo. - echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. - goto end -) - -if "%1" == "pickle" ( - %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle - echo. - echo.Build finished; now you can process the pickle files. - goto end -) - -if "%1" == "json" ( - %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json - echo. - echo.Build finished; now you can process the JSON files. - goto end -) - -if "%1" == "htmlhelp" ( - %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp - echo. - echo.Build finished; now you can run HTML Help Workshop with the ^ -.hhp project file in %BUILDDIR%/htmlhelp. - goto end -) - -if "%1" == "qthelp" ( - %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp - echo. - echo.Build finished; now you can run "qcollectiongenerator" with the ^ -.qhcp project file in %BUILDDIR%/qthelp, like this: - echo.^> qcollectiongenerator %BUILDDIR%\qthelp\Doctrine2ORM.qhcp - echo.To view the help file: - echo.^> assistant -collectionFile %BUILDDIR%\qthelp\Doctrine2ORM.ghc - goto end -) - -if "%1" == "latex" ( - %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex - echo. - echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. - goto end -) - -if "%1" == "changes" ( - %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes - echo. - echo.The overview file is in %BUILDDIR%/changes. - goto end -) - -if "%1" == "linkcheck" ( - %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck - echo. - echo.Link check complete; look for any errors in the above output ^ -or in %BUILDDIR%/linkcheck/output.txt. - goto end -) - -if "%1" == "doctest" ( - %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest - echo. - echo.Testing of doctests in the sources finished, look at the ^ -results in %BUILDDIR%/doctest/output.txt. - goto end -) - -:end From 182469b346f4de0677efccf43380e26b52eda568 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 16 Oct 2024 22:59:19 +0200 Subject: [PATCH 6/6] Fix copy/paste/adapt mistake (#11684) The last step was missing. --- docs/en/tutorials/working-with-indexed-associations.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/tutorials/working-with-indexed-associations.rst b/docs/en/tutorials/working-with-indexed-associations.rst index 81032ee8e4a..e6822de3952 100644 --- a/docs/en/tutorials/working-with-indexed-associations.rst +++ b/docs/en/tutorials/working-with-indexed-associations.rst @@ -40,7 +40,7 @@ The code and mappings for the Market entity looks like this: .. literalinclude:: working-with-indexed-associations/market.xml :language: xml - .. literalinclude:: working-with-indexed-associations/market.xml + .. literalinclude:: working-with-indexed-associations/market.yaml :language: yaml