diff --git a/UPGRADE.md b/UPGRADE.md index 06190a641c..411e5e618e 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -2301,7 +2301,7 @@ from 2.0 have to configure the annotation driver if they don't use `Configuratio ## Scalar mappings can now be omitted from DQL result -You are now allowed to mark scalar SELECT expressions as HIDDEN an they are not hydrated anymore. +You are now allowed to mark scalar SELECT expressions as HIDDEN and they are not hydrated anymore. Example: SELECT u, SUM(a.id) AS HIDDEN numArticles FROM User u LEFT JOIN u.Articles a ORDER BY numArticles DESC HAVING numArticles > 10 diff --git a/docs/en/reference/second-level-cache.rst b/docs/en/reference/second-level-cache.rst index a762b8574a..af6e78ea5a 100644 --- a/docs/en/reference/second-level-cache.rst +++ b/docs/en/reference/second-level-cache.rst @@ -133,7 +133,7 @@ Caching mode * Read Write cache employs locks before update/delete. * Use if data needs to be updated. * Slowest strategy. - * To use it a the cache region implementation must support locking. + * To use it the cache region implementation must support locking. Built-in cached persisters diff --git a/docs/en/reference/tools.rst b/docs/en/reference/tools.rst index 101c51ad01..d759ac1a82 100644 --- a/docs/en/reference/tools.rst +++ b/docs/en/reference/tools.rst @@ -22,7 +22,7 @@ have to register them yourself. All the commands of the Doctrine Console require access to the ``EntityManager``. You have to inject it into the console application. -Here is an example of a the project-specific ``bin/doctrine`` binary. +Here is an example of a project-specific ``bin/doctrine`` binary. .. code-block:: php diff --git a/src/AbstractQuery.php b/src/AbstractQuery.php index 6aa0094ef1..908ac99bb6 100644 --- a/src/AbstractQuery.php +++ b/src/AbstractQuery.php @@ -1065,7 +1065,7 @@ public function setResultCacheId(string|null $id): static } /** - * Executes the query and returns a the resulting Statement object. + * Executes the query and returns the resulting Statement object. * * @return Result|int The executed database statement that holds * the results, or an integer indicating how diff --git a/src/Mapping/MappingException.php b/src/Mapping/MappingException.php index 8450a35065..524c867263 100644 --- a/src/Mapping/MappingException.php +++ b/src/Mapping/MappingException.php @@ -179,7 +179,7 @@ public static function oneToManyRequiresMappedBy(string $entityName, string $fie public static function joinTableRequired(string $fieldName): self { - return new self(sprintf("The mapping of field '%s' requires an the 'joinTable' attribute.", $fieldName)); + return new self(sprintf("The mapping of field '%s' requires the 'joinTable' attribute.", $fieldName)); } /** diff --git a/tests/Tests/ORM/Functional/Ticket/DDC2359Test.php b/tests/Tests/ORM/Functional/Ticket/DDC2359Test.php index 7e8a753d53..495cd6d4ef 100644 --- a/tests/Tests/ORM/Functional/Ticket/DDC2359Test.php +++ b/tests/Tests/ORM/Functional/Ticket/DDC2359Test.php @@ -49,7 +49,7 @@ public function testIssue(): void $entityManager->expects(self::any())->method('getConnection')->willReturn($connection); $entityManager ->method('getEventManager') - ->willReturn($this->createMock(EventManager::class)); + ->willReturn(new EventManager()); $metadataFactory->method('newClassMetadataInstance')->willReturn($mockMetadata); $metadataFactory->expects(self::once())->method('wakeupReflection'); diff --git a/tests/Tests/ORM/Functional/Ticket/GH10387Test.php b/tests/Tests/ORM/Functional/Ticket/GH10387Test.php index ccf802a6b0..a83330790a 100644 --- a/tests/Tests/ORM/Functional/Ticket/GH10387Test.php +++ b/tests/Tests/ORM/Functional/Ticket/GH10387Test.php @@ -34,7 +34,7 @@ public static function classHierachies(): Generator { yield 'hierarchy with Entity classes only' => [[GH10387EntitiesOnlyRoot::class, GH10387EntitiesOnlyMiddle::class, GH10387EntitiesOnlyLeaf::class]]; yield 'MappedSuperclass in the middle of the hierarchy' => [[GH10387MappedSuperclassRoot::class, GH10387MappedSuperclassMiddle::class, GH10387MappedSuperclassLeaf::class]]; - yield 'abstract entity the the root and in the middle of the hierarchy' => [[GH10387AbstractEntitiesRoot::class, GH10387AbstractEntitiesMiddle::class, GH10387AbstractEntitiesLeaf::class]]; + yield 'abstract entity at the root and in the middle of the hierarchy' => [[GH10387AbstractEntitiesRoot::class, GH10387AbstractEntitiesMiddle::class, GH10387AbstractEntitiesLeaf::class]]; } } diff --git a/tests/Tests/ORM/Functional/Ticket/GH6394Test.php b/tests/Tests/ORM/Functional/Ticket/GH6394Test.php index 1bcfe4a69b..1b7d0db200 100644 --- a/tests/Tests/ORM/Functional/Ticket/GH6394Test.php +++ b/tests/Tests/ORM/Functional/Ticket/GH6394Test.php @@ -23,7 +23,7 @@ protected function setUp(): void } /** - * Test the the version of an entity can be fetched, when the id field and + * Test the version of an entity can be fetched, when the id field and * the id column are different. */ #[Group('6393')] diff --git a/tests/Tests/ORM/Hydration/AbstractHydratorTest.php b/tests/Tests/ORM/Hydration/AbstractHydratorTest.php index 3369d2e88f..4e85aaff4b 100644 --- a/tests/Tests/ORM/Hydration/AbstractHydratorTest.php +++ b/tests/Tests/ORM/Hydration/AbstractHydratorTest.php @@ -27,7 +27,7 @@ #[CoversClass(AbstractHydrator::class)] class AbstractHydratorTest extends OrmFunctionalTestCase { - private EventManager&MockObject $mockEventManager; + private EventManager $eventManager; private Result&MockObject $mockResult; private ResultSetMapping&MockObject $mockResultMapping; private DummyHydrator $hydrator; @@ -38,7 +38,7 @@ protected function setUp(): void $mockConnection = $this->createMock(Connection::class); $mockEntityManagerInterface = $this->createMock(EntityManagerInterface::class); - $this->mockEventManager = $this->createMock(EventManager::class); + $this->eventManager = new EventManager(); $this->mockResult = $this->createMock(Result::class); $this->mockResultMapping = $this->createMock(ResultSetMapping::class); @@ -47,7 +47,7 @@ protected function setUp(): void ->willReturn($this->createMock(AbstractPlatform::class)); $mockEntityManagerInterface ->method('getEventManager') - ->willReturn($this->mockEventManager); + ->willReturn($this->eventManager); $mockEntityManagerInterface ->method('getConnection') ->willReturn($mockConnection); @@ -66,85 +66,29 @@ protected function setUp(): void #[Group('#1515')] public function testOnClearEventListenerIsDetachedOnCleanup(): void { - $eventListenerHasBeenRegistered = false; - - $this - ->mockEventManager - ->expects(self::once()) - ->method('addEventListener') - ->with([Events::onClear], $this->hydrator) - ->willReturnCallback(function () use (&$eventListenerHasBeenRegistered): void { - $this->assertFalse($eventListenerHasBeenRegistered); - $eventListenerHasBeenRegistered = true; - }); - - $this - ->mockEventManager - ->expects(self::once()) - ->method('removeEventListener') - ->with([Events::onClear], $this->hydrator) - ->willReturnCallback(function () use (&$eventListenerHasBeenRegistered): void { - $this->assertTrue($eventListenerHasBeenRegistered); - }); - - iterator_to_array($this->hydrator->toIterable($this->mockResult, $this->mockResultMapping)); + $iterator = $this->hydrator->toIterable($this->mockResult, $this->mockResultMapping); + iterator_to_array($iterator); + self::assertTrue($this->hydrator->hasListener); + self::assertFalse($this->eventManager->hasListeners(Events::onClear)); } #[Group('#6623')] public function testHydrateAllRegistersAndClearsAllAttachedListeners(): void { - $eventListenerHasBeenRegistered = false; - - $this - ->mockEventManager - ->expects(self::once()) - ->method('addEventListener') - ->with([Events::onClear], $this->hydrator) - ->willReturnCallback(function () use (&$eventListenerHasBeenRegistered): void { - $this->assertFalse($eventListenerHasBeenRegistered); - $eventListenerHasBeenRegistered = true; - }); - - $this - ->mockEventManager - ->expects(self::once()) - ->method('removeEventListener') - ->with([Events::onClear], $this->hydrator) - ->willReturnCallback(function () use (&$eventListenerHasBeenRegistered): void { - $this->assertTrue($eventListenerHasBeenRegistered); - }); - $this->hydrator->hydrateAll($this->mockResult, $this->mockResultMapping); + self::assertTrue($this->hydrator->hasListener); + self::assertFalse($this->eventManager->hasListeners(Events::onClear)); } #[Group('#8482')] public function testHydrateAllClearsAllAttachedListenersEvenOnError(): void { - $eventListenerHasBeenRegistered = false; - - $this - ->mockEventManager - ->expects(self::once()) - ->method('addEventListener') - ->with([Events::onClear], $this->hydrator) - ->willReturnCallback(function () use (&$eventListenerHasBeenRegistered): void { - $this->assertFalse($eventListenerHasBeenRegistered); - $eventListenerHasBeenRegistered = true; - }); - - $this - ->mockEventManager - ->expects(self::once()) - ->method('removeEventListener') - ->with([Events::onClear], $this->hydrator) - ->willReturnCallback(function () use (&$eventListenerHasBeenRegistered): void { - $this->assertTrue($eventListenerHasBeenRegistered); - }); - $this->hydrator->throwException = true; $this->expectException(LogicException::class); $this->hydrator->hydrateAll($this->mockResult, $this->mockResultMapping); + self::assertTrue($this->hydrator->hasListener); + self::assertFalse($this->eventManager->hasListeners(Events::onClear)); } public function testEnumCastsIntegerBackedEnumValues(): void @@ -198,6 +142,7 @@ public function testToIterableIfYieldAndBreakBeforeFinishAlwaysCleansUp(): void class DummyHydrator extends AbstractHydrator { public bool $throwException = false; + public bool $hasListener = false; public function buildEnumForTesting(mixed $value, string $enumType): BackedEnum|array { @@ -213,4 +158,9 @@ protected function hydrateAllData(): array return []; } + + public function prepare(): void + { + $this->hasListener = $this->em->getEventManager()->hasListeners(Events::onClear); + } }