diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 5aafb5f..9646a1f 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -9,28 +9,9 @@ $config = new PhpCsFixer\Config(); return $config->setRules([ - '@PER-CS2.0' => true, - 'array_syntax' => ['syntax' => 'short'], - - // imports - 'fully_qualified_strict_types' => true, - 'global_namespace_import' => [ - 'import_classes' => false, - 'import_constants' => false, - 'import_functions' => false, - ], - 'no_leading_import_slash' => true, - 'no_unneeded_import_alias' => true, - 'no_unused_imports' => true, - 'ordered_imports' => [ - 'sort_algorithm' => 'alpha', - 'imports_order' => ['const', 'class', 'function'] - ], - 'single_line_after_imports' => true, - 'no_useless_else' => true, - 'no_useless_return' => true, + '@PhpCsFixer:risky' => true, 'declare_strict_types' => true, - 'native_function_invocation' => ['include' => ['@compiler_optimized']], + 'php_unit_strict' => false, 'header_comment' => [ 'header' => <<cachedResult; } - $decoded = base64_decode($this->event); + $decoded = base64_decode($this->event, true); + + if ($decoded === false) { + throw new UnserializeFailureException($this->event); + } + $result = unserialize($decoded); if (false === $result) { diff --git a/packages/domain-event/src/EventDispatcher/ImmediateEventDispatchingDomainEventDispatcher.php b/packages/domain-event/src/EventDispatcher/ImmediateEventDispatchingDomainEventDispatcher.php index 6f6e075..1eb4388 100644 --- a/packages/domain-event/src/EventDispatcher/ImmediateEventDispatchingDomainEventDispatcher.php +++ b/packages/domain-event/src/EventDispatcher/ImmediateEventDispatchingDomainEventDispatcher.php @@ -31,7 +31,7 @@ public function __construct( private readonly PsrEventDispatcherInterface $defaultEventDispatcher, ) {} - // @phpstan-ignore-next-line + /** @phpstan-ignore-next-line */ #[\Override] public function addListener(string $eventName, callable|array $listener, int $priority = 0): void { @@ -45,7 +45,7 @@ public function addSubscriber(EventSubscriberInterface $subscriber): void $this->decorated->addSubscriber($subscriber); } - // @phpstan-ignore-next-line + /** @phpstan-ignore-next-line */ #[\Override] public function removeListener(string $eventName, callable|array $listener): void { @@ -65,7 +65,7 @@ public function getListeners(?string $eventName = null): array return $this->decorated->getListeners($eventName); } - // @phpstan-ignore-next-line + /** @phpstan-ignore-next-line */ #[\Override] public function getListenerPriority(string $eventName, callable|array $listener): ?int { diff --git a/tests/Framework/Security/AccessTokenHandler.php b/tests/Framework/Security/AccessTokenHandler.php index db21584..6705a88 100644 --- a/tests/Framework/Security/AccessTokenHandler.php +++ b/tests/Framework/Security/AccessTokenHandler.php @@ -26,7 +26,7 @@ public function getUserBadgeFrom(string $accessToken): UserBadge return match ($accessToken) { 'user' => new UserBadge( 'user', - fn(string $userIdentifier): User => new User(), + static fn(string $userIdentifier): User => new User(), ), default => throw new BadCredentialsException('Invalid credentials.'), }; diff --git a/tests/Framework/Tests/BasicDomainEventTest.php b/tests/Framework/Tests/BasicDomainEventTest.php index 7ad796a..043f554 100644 --- a/tests/Framework/Tests/BasicDomainEventTest.php +++ b/tests/Framework/Tests/BasicDomainEventTest.php @@ -23,50 +23,50 @@ final class BasicDomainEventTest extends DomainEventTestCase public function testImmediateListener(): void { $listener = static::getContainer()->get(BookEventImmediateListener::class); - $this->assertInstanceOf(BookEventImmediateListener::class, $listener); + self::assertInstanceOf(BookEventImmediateListener::class, $listener); - $this->assertFalse($listener->onCreateCalled()); + self::assertFalse($listener->onCreateCalled()); new Book('title', 'description'); - $this->assertTrue($listener->onCreateCalled()); + self::assertTrue($listener->onCreateCalled()); } public function testPreFlushListener(): void { $listener = static::getContainer()->get(BookEventPreFlushListener::class); - $this->assertInstanceOf(BookEventPreFlushListener::class, $listener); + self::assertInstanceOf(BookEventPreFlushListener::class, $listener); - $this->assertFalse($listener->onCreateCalled()); + self::assertFalse($listener->onCreateCalled()); $book = new Book('title', 'description'); static::getEntityManager()->persist($book); static::getEntityManager()->flush(); - $this->assertTrue($listener->onCreateCalled()); + self::assertTrue($listener->onCreateCalled()); } public function testPostFlushListener(): void { $listener = static::getContainer()->get(BookEventPostFlushListener::class); - $this->assertInstanceOf(BookEventPostFlushListener::class, $listener); + self::assertInstanceOf(BookEventPostFlushListener::class, $listener); - $this->assertFalse($listener->onCreateCalled()); + self::assertFalse($listener->onCreateCalled()); $book = new Book('title', 'description'); static::getEntityManager()->persist($book); static::getEntityManager()->flush(); - $this->assertTrue($listener->onCreateCalled()); + self::assertTrue($listener->onCreateCalled()); } public function testManualPreFlush(): void { $entityManager = static::getEntityManager(); $listener = static::getContainer()->get(BookEventPreFlushListener::class); - $this->assertInstanceOf(BookEventPreFlushListener::class, $listener); + self::assertInstanceOf(BookEventPreFlushListener::class, $listener); $entityManager->setAutoDispatchDomainEvents(false); - $this->assertFalse($listener->onCreateCalled()); + self::assertFalse($listener->onCreateCalled()); $book = new Book('title', 'description'); $entityManager->persist($book); @@ -74,24 +74,24 @@ public function testManualPreFlush(): void $entityManager->flush(); $entityManager->clearDomainEvents(); - $this->assertTrue($listener->onCreateCalled()); + self::assertTrue($listener->onCreateCalled()); } public function testManualPostFlush(): void { $entityManager = static::getEntityManager(); $listener = static::getContainer()->get(BookEventPostFlushListener::class); - $this->assertInstanceOf(BookEventPostFlushListener::class, $listener); + self::assertInstanceOf(BookEventPostFlushListener::class, $listener); $entityManager->setAutoDispatchDomainEvents(false); - $this->assertFalse($listener->onCreateCalled()); + self::assertFalse($listener->onCreateCalled()); $book = new Book('title', 'description'); $entityManager->persist($book); $entityManager->flush(); $entityManager->dispatchPostFlushDomainEvents(); - $this->assertTrue($listener->onCreateCalled()); + self::assertTrue($listener->onCreateCalled()); } } diff --git a/tests/Framework/Tests/DecorationTest.php b/tests/Framework/Tests/DecorationTest.php index 775f976..89448df 100644 --- a/tests/Framework/Tests/DecorationTest.php +++ b/tests/Framework/Tests/DecorationTest.php @@ -26,25 +26,25 @@ final class DecorationTest extends DomainEventTestCase { /** - * @dataProvider entityManagerDecorationProvider + * @dataProvider provideEntityManagerDecorationFromContainerCases */ public function testEntityManagerDecorationFromContainer(string $serviceId): void { $entityManager = static::getContainer()->get($serviceId); - $this->assertInstanceOf(EntityManagerInterface::class, $entityManager); - $this->assertInstanceOf(DomainEventAwareEntityManager::class, $entityManager); + self::assertInstanceOf(EntityManagerInterface::class, $entityManager); + self::assertInstanceOf(DomainEventAwareEntityManager::class, $entityManager); // @phpstan-ignore-next-line - $this->assertInstanceOf(DomainEventAwareEntityManagerInterface::class, $entityManager); + self::assertInstanceOf(DomainEventAwareEntityManagerInterface::class, $entityManager); // @phpstan-ignore-next-line - $this->assertInstanceOf(ObjectManager::class, $entityManager); + self::assertInstanceOf(ObjectManager::class, $entityManager); // @phpstan-ignore-next-line - $this->assertInstanceOf(DomainEventAwareObjectManager::class, $entityManager); + self::assertInstanceOf(DomainEventAwareObjectManager::class, $entityManager); } /** * @return array> */ - public static function entityManagerDecorationProvider(): array + public static function provideEntityManagerDecorationFromContainerCases(): iterable { return [ ['doctrine.orm.entity_manager'], @@ -59,39 +59,39 @@ public static function entityManagerDecorationProvider(): array public function testEntityManagerDecorationFromRegistry(): void { $managerRegistry = static::getContainer()->get('doctrine'); - $this->assertInstanceOf(DomainEventAwareManagerRegistry::class, $managerRegistry); - $this->assertInstanceOf(DomainEventAwareManagerRegistryImplementation::class, $managerRegistry); + self::assertInstanceOf(DomainEventAwareManagerRegistry::class, $managerRegistry); + self::assertInstanceOf(DomainEventAwareManagerRegistryImplementation::class, $managerRegistry); - $this->assertInstanceOf(DomainEventAwareEntityManager::class, $managerRegistry->getManager()); - $this->assertInstanceOf(DomainEventAwareEntityManager::class, $managerRegistry->getManager('default')); - $this->assertInstanceOf(DomainEventAwareEntityManager::class, $managerRegistry->getManager('other')); + self::assertInstanceOf(DomainEventAwareEntityManager::class, $managerRegistry->getManager()); + self::assertInstanceOf(DomainEventAwareEntityManager::class, $managerRegistry->getManager('default')); + self::assertInstanceOf(DomainEventAwareEntityManager::class, $managerRegistry->getManager('other')); $managers = $managerRegistry->getManagers(); foreach ($managers as $manager) { - $this->assertInstanceOf(DomainEventAwareEntityManager::class, $manager); + self::assertInstanceOf(DomainEventAwareEntityManager::class, $manager); } } public function testEntityManagerDecorationFromRepository(): void { $entityManager = static::getContainer()->get('doctrine.orm.default_entity_manager'); - $this->assertInstanceOf(DomainEventAwareEntityManager::class, $entityManager); + self::assertInstanceOf(DomainEventAwareEntityManager::class, $entityManager); $repository = $entityManager->getRepository(Book::class); - $this->assertInstanceOf(BookRepository::class, $repository); - $this->assertInstanceOf(DomainEventAwareEntityManager::class, $repository->getEntityManager()); + self::assertInstanceOf(BookRepository::class, $repository); + self::assertInstanceOf(DomainEventAwareEntityManager::class, $repository->getEntityManager()); } public function testGetManagerNameFromManager(): void { $managerRegistry = static::getContainer()->get('doctrine'); - $this->assertInstanceOf(DomainEventAwareManagerRegistry::class, $managerRegistry); + self::assertInstanceOf(DomainEventAwareManagerRegistry::class, $managerRegistry); $entityManager = $managerRegistry->getManager(); - $this->assertSame('default', $managerRegistry->getManagerName($entityManager)); + self::assertSame('default', $managerRegistry->getManagerName($entityManager)); $entityManager = $managerRegistry->getManager('other'); - $this->assertSame('other', $managerRegistry->getManagerName($entityManager)); + self::assertSame('other', $managerRegistry->getManagerName($entityManager)); } } diff --git a/tests/Framework/Tests/DomainEventTestCase.php b/tests/Framework/Tests/DomainEventTestCase.php index a447823..913bbeb 100644 --- a/tests/Framework/Tests/DomainEventTestCase.php +++ b/tests/Framework/Tests/DomainEventTestCase.php @@ -29,7 +29,7 @@ abstract class DomainEventTestCase extends KernelTestCase protected DomainEventAwareManagerRegistry $managerRegistry; - // @phpstan-ignore-next-line + /** @phpstan-ignore-next-line */ #[\Override] protected static function createKernel(array $options = []): KernelInterface { @@ -37,14 +37,14 @@ protected static function createKernel(array $options = []): KernelInterface } #[\Override] - public function setUp(): void + protected function setUp(): void { parent::setUp(); // setup manager registry $managerRegistry = static::getContainer()->get('doctrine'); - $this->assertInstanceOf(DomainEventAwareManagerRegistry::class, $managerRegistry); + self::assertInstanceOf(DomainEventAwareManagerRegistry::class, $managerRegistry); $this->managerRegistry = $managerRegistry; @@ -53,7 +53,7 @@ public function setUp(): void $managers = $managerRegistry->getManagers(); foreach ($managers as $manager) { - $this->assertInstanceOf(EntityManagerInterface::class, $manager); + self::assertInstanceOf(EntityManagerInterface::class, $manager); $schemaTool = new SchemaTool($manager); $schemaTool->createSchema($manager->getMetadataFactory()->getAllMetadata()); } @@ -61,7 +61,7 @@ public function setUp(): void // save entity manager to class property $entityManager = static::getContainer()->get('doctrine.orm.entity_manager'); - $this->assertInstanceOf(DomainEventAwareEntityManagerInterface::class, $entityManager); + self::assertInstanceOf(DomainEventAwareEntityManagerInterface::class, $entityManager); $this->entityManager = $entityManager; } @@ -86,14 +86,14 @@ public static function getEntityManager(): DomainEventAwareEntityManager } #[\Override] - public function tearDown(): void + protected function tearDown(): void { parent::tearDown(); $managers = $this->managerRegistry->getManagers(); foreach ($managers as $manager) { - $this->assertInstanceOf(DomainEventAwareEntityManagerInterface::class, $manager); + self::assertInstanceOf(DomainEventAwareEntityManagerInterface::class, $manager); $manager->clearDomainEvents(); } } diff --git a/tests/Framework/Tests/EquatableEventTest.php b/tests/Framework/Tests/EquatableEventTest.php index 23b9384..0d2ce6d 100644 --- a/tests/Framework/Tests/EquatableEventTest.php +++ b/tests/Framework/Tests/EquatableEventTest.php @@ -22,10 +22,10 @@ final class EquatableEventTest extends DomainEventTestCase public function testWithoutTransaction(): void { $preFlushListener = static::getContainer()->get(BookEventPreFlushListener::class); - $this->assertInstanceOf(BookEventPreFlushListener::class, $preFlushListener); + self::assertInstanceOf(BookEventPreFlushListener::class, $preFlushListener); $postFlushListener = static::getContainer()->get(BookEventPostFlushListener::class); - $this->assertInstanceOf(BookEventPostFlushListener::class, $postFlushListener); + self::assertInstanceOf(BookEventPostFlushListener::class, $postFlushListener); $book = new Book('Book A', 'Description A'); @@ -40,7 +40,7 @@ public function testWithoutTransaction(): void $this->entityManager->flush(); - $this->assertEquals(1, $preFlushListener->onChangeCalled()); - $this->assertEquals(1, $postFlushListener->onChangeCalled()); + self::assertEquals(1, $preFlushListener->onChangeCalled()); + self::assertEquals(1, $postFlushListener->onChangeCalled()); } } diff --git a/tests/Framework/Tests/IntegrationTest.php b/tests/Framework/Tests/IntegrationTest.php index cf61c4b..195a1a0 100644 --- a/tests/Framework/Tests/IntegrationTest.php +++ b/tests/Framework/Tests/IntegrationTest.php @@ -27,7 +27,7 @@ public function testEventDispatcherWiring(): void ]; foreach ($serviceIds as $serviceId) { - $this->assertInstanceOf( + self::assertInstanceOf( EventDispatcherInterface::class, static::getContainer()->get('test.' . $serviceId), ); diff --git a/tests/Framework/Tests/OutboxSetupTest.php b/tests/Framework/Tests/OutboxSetupTest.php index 4b9934b..71d6cf3 100644 --- a/tests/Framework/Tests/OutboxSetupTest.php +++ b/tests/Framework/Tests/OutboxSetupTest.php @@ -19,7 +19,7 @@ final class OutboxSetupTest extends DomainEventTestCase { /** - * @dataProvider databaseSetupProvider + * @dataProvider provideDatabaseSetupCases */ public function testDatabaseSetup(string $id): void { @@ -42,15 +42,15 @@ public function testDatabaseSetup(string $id): void $result = $queryBuilder->fetchAssociative(); - $this->assertIsArray($result); - $this->assertArrayHasKey('name', $result); - $this->assertEquals('rekalogika_event_outbox', $result['name']); + self::assertIsArray($result); + self::assertArrayHasKey('name', $result); + self::assertEquals('rekalogika_event_outbox', $result['name']); } /** * @return iterable> */ - public static function databaseSetupProvider(): iterable + public static function provideDatabaseSetupCases(): iterable { $managerRegistry = static::getContainer()->get('doctrine'); self::assertInstanceOf(ManagerRegistry::class, $managerRegistry); diff --git a/tests/Framework/Tests/OutboxTest.php b/tests/Framework/Tests/OutboxTest.php index f1b9dff..f0d8051 100644 --- a/tests/Framework/Tests/OutboxTest.php +++ b/tests/Framework/Tests/OutboxTest.php @@ -67,70 +67,70 @@ public function testOutboxQueuing(): void // get outbox reader factory $outboxReaderFactory = static::getContainer()->get(OutboxReaderFactoryInterface::class); - $this->assertInstanceOf(OutboxReaderFactoryInterface::class, $outboxReaderFactory); + self::assertInstanceOf(OutboxReaderFactoryInterface::class, $outboxReaderFactory); // default manager $outboxReader = $outboxReaderFactory->createOutboxReader('default'); $messages = $outboxReader->getOutboxMessages(100); $messages = array_values($messages instanceof \Traversable ? iterator_to_array($messages) : $messages); - $this->assertInstanceOf(Envelope::class, $messages[0]); - $this->assertInstanceOf(BookCreated::class, $messages[0]->getMessage()); - $this->assertInstanceOf(Envelope::class, $messages[1]); - $this->assertInstanceOf(BookChanged::class, $messages[1]->getMessage()); + self::assertInstanceOf(Envelope::class, $messages[0]); + self::assertInstanceOf(BookCreated::class, $messages[0]->getMessage()); + self::assertInstanceOf(Envelope::class, $messages[1]); + self::assertInstanceOf(BookChanged::class, $messages[1]->getMessage()); // other manager $outboxReader = $outboxReaderFactory->createOutboxReader('other'); $messages = $outboxReader->getOutboxMessages(100); $messages = array_values($messages instanceof \Traversable ? iterator_to_array($messages) : $messages); - $this->assertInstanceOf(Envelope::class, $messages[0]); - $this->assertInstanceOf(PostCreated::class, $messages[0]->getMessage()); - $this->assertInstanceOf(Envelope::class, $messages[1]); - $this->assertInstanceOf(PostChanged::class, $messages[1]->getMessage()); + self::assertInstanceOf(Envelope::class, $messages[0]); + self::assertInstanceOf(PostCreated::class, $messages[0]->getMessage()); + self::assertInstanceOf(Envelope::class, $messages[1]); + self::assertInstanceOf(PostChanged::class, $messages[1]->getMessage()); } private function assertMessagesInTransport(): void { // get transport $transport = $this->getContainer()->get('messenger.transport.async'); - $this->assertInstanceOf(InMemoryTransport::class, $transport); + self::assertInstanceOf(InMemoryTransport::class, $transport); // get sent messages $messages = $transport->getSent(); - $this->assertCount(2, $messages); + self::assertCount(2, $messages); // check first message $first = $messages[0]; - $this->assertInstanceOf(Envelope::class, $first); - $this->assertInstanceOf(BookChanged::class, $first->getMessage()); + self::assertInstanceOf(Envelope::class, $first); + self::assertInstanceOf(BookChanged::class, $first->getMessage()); $busNameStamp = $first->last(BusNameStamp::class); - $this->assertInstanceOf(BusNameStamp::class, $busNameStamp); - $this->assertEquals('rekalogika.domain_event.bus', $busNameStamp->getBusName()); + self::assertInstanceOf(BusNameStamp::class, $busNameStamp); + self::assertEquals('rekalogika.domain_event.bus', $busNameStamp->getBusName()); $sentStamp = $first->last(SentStamp::class); - $this->assertInstanceOf(SentStamp::class, $sentStamp); - $this->assertEquals('async', $sentStamp->getSenderAlias()); + self::assertInstanceOf(SentStamp::class, $sentStamp); + self::assertEquals('async', $sentStamp->getSenderAlias()); $objectManagerNameStamp = $first->last(ObjectManagerNameStamp::class); - $this->assertInstanceOf(ObjectManagerNameStamp::class, $objectManagerNameStamp); - $this->assertEquals('default', $objectManagerNameStamp->getObjectManagerName()); + self::assertInstanceOf(ObjectManagerNameStamp::class, $objectManagerNameStamp); + self::assertEquals('default', $objectManagerNameStamp->getObjectManagerName()); // check second message $second = $messages[1]; - $this->assertInstanceOf(Envelope::class, $second); - $this->assertInstanceOf(PostChanged::class, $second->getMessage()); + self::assertInstanceOf(Envelope::class, $second); + self::assertInstanceOf(PostChanged::class, $second->getMessage()); $busNameStamp = $second->last(BusNameStamp::class); - $this->assertInstanceOf(BusNameStamp::class, $busNameStamp); - $this->assertEquals('rekalogika.domain_event.bus', $busNameStamp->getBusName()); + self::assertInstanceOf(BusNameStamp::class, $busNameStamp); + self::assertEquals('rekalogika.domain_event.bus', $busNameStamp->getBusName()); $sentStamp = $second->last(SentStamp::class); - $this->assertInstanceOf(SentStamp::class, $sentStamp); - $this->assertEquals('async', $sentStamp->getSenderAlias()); + self::assertInstanceOf(SentStamp::class, $sentStamp); + self::assertEquals('async', $sentStamp->getSenderAlias()); $objectManagerNameStamp = $second->last(ObjectManagerNameStamp::class); - $this->assertInstanceOf(ObjectManagerNameStamp::class, $objectManagerNameStamp); - $this->assertEquals('other', $objectManagerNameStamp->getObjectManagerName()); + self::assertInstanceOf(ObjectManagerNameStamp::class, $objectManagerNameStamp); + self::assertEquals('other', $objectManagerNameStamp->getObjectManagerName()); } public function testMessageRelay(): void @@ -139,7 +139,7 @@ public function testMessageRelay(): void // get message relay $messageRelay = static::getContainer()->get(MessageRelayInterface::class); - $this->assertInstanceOf(MessageRelayInterface::class, $messageRelay); + self::assertInstanceOf(MessageRelayInterface::class, $messageRelay); // relay messages $messageRelay->relayMessages('default'); @@ -155,7 +155,7 @@ public function testMessageRelayHandler(): void // get message bus $messageBus = static::getContainer()->get(MessageBusInterface::class); - $this->assertInstanceOf(MessageBusInterface::class, $messageBus); + self::assertInstanceOf(MessageBusInterface::class, $messageBus); // tell to relay messages $messageBus->dispatch(new MessageRelayStartMessage('default')); @@ -196,7 +196,7 @@ public function testEquatableMessage(): void // get message relay $messageRelay = static::getContainer()->get(MessageRelayInterface::class); - $this->assertInstanceOf(MessageRelayInterface::class, $messageRelay); + self::assertInstanceOf(MessageRelayInterface::class, $messageRelay); // relay messages $messageRelay->relayMessages('default'); diff --git a/tests/Framework/Tests/PreFlushTest.php b/tests/Framework/Tests/PreFlushTest.php index f69db82..039d6a2 100644 --- a/tests/Framework/Tests/PreFlushTest.php +++ b/tests/Framework/Tests/PreFlushTest.php @@ -22,7 +22,7 @@ final class PreFlushTest extends DomainEventTestCase { #[\Override] - public function tearDown(): void + protected function tearDown(): void { static::getEntityManager()->clearDomainEvents(); parent::tearDown(); @@ -40,13 +40,13 @@ public function testFlushInPreFlush(): void public function testNestedRecordEvent(): void { $dummyMethodCalledListener = static::getContainer()->get(BookDummyMethodCalledListener::class); - $this->assertInstanceOf(BookDummyMethodCalledListener::class, $dummyMethodCalledListener); + self::assertInstanceOf(BookDummyMethodCalledListener::class, $dummyMethodCalledListener); $dummyMethodForNestedRecordEventListener = static::getContainer()->get(BookDummyMethodForNestedRecordEventListener::class); - $this->assertInstanceOf(BookDummyMethodForNestedRecordEventListener::class, $dummyMethodForNestedRecordEventListener); + self::assertInstanceOf(BookDummyMethodForNestedRecordEventListener::class, $dummyMethodForNestedRecordEventListener); - $this->assertFalse($dummyMethodCalledListener->isDummyMethodCalled()); - $this->assertFalse($dummyMethodForNestedRecordEventListener->isDummyMethodForNestedRecordEventCalled()); + self::assertFalse($dummyMethodCalledListener->isDummyMethodCalled()); + self::assertFalse($dummyMethodForNestedRecordEventListener->isDummyMethodForNestedRecordEventCalled()); $book = new Book('title', 'description'); static::getEntityManager()->persist($book); @@ -54,8 +54,8 @@ public function testNestedRecordEvent(): void $book->dummyMethodForNestedRecordEvent(); static::getEntityManager()->flush(); - $this->assertTrue($dummyMethodCalledListener->isDummyMethodCalled()); - $this->assertTrue($dummyMethodForNestedRecordEventListener->isDummyMethodForNestedRecordEventCalled()); + self::assertTrue($dummyMethodCalledListener->isDummyMethodCalled()); + self::assertTrue($dummyMethodForNestedRecordEventListener->isDummyMethodForNestedRecordEventCalled()); } public function testInfiniteLoopSafeguard(): void diff --git a/tests/Framework/Tests/RemoveTest.php b/tests/Framework/Tests/RemoveTest.php index e9dd707..fa30bd8 100644 --- a/tests/Framework/Tests/RemoveTest.php +++ b/tests/Framework/Tests/RemoveTest.php @@ -36,7 +36,7 @@ private function findBook(Uuid $id): Book { $entitymanager = static::getEntityManager(); $book = $entitymanager->find(Book::class, $id); - $this->assertInstanceOf(Book::class, $book); + self::assertInstanceOf(Book::class, $book); return $book; } @@ -47,11 +47,11 @@ public function testImmediateListener(): void $book = $this->findBook($id); $listener = static::getContainer()->get(BookEventImmediateListener::class); - $this->assertInstanceOf(BookEventImmediateListener::class, $listener); + self::assertInstanceOf(BookEventImmediateListener::class, $listener); - $this->assertFalse($listener->onRemoveCalled()); + self::assertFalse($listener->onRemoveCalled()); static::getEntityManager()->remove($book); - $this->assertTrue($listener->onRemoveCalled()); + self::assertTrue($listener->onRemoveCalled()); static::getEntityManager()->flush(); } @@ -62,18 +62,18 @@ public function testPrePostFlushListener(): void $book = $this->findBook($id); $preFlushListener = static::getContainer()->get(BookEventPreFlushListener::class); - $this->assertInstanceOf(BookEventPreFlushListener::class, $preFlushListener); + self::assertInstanceOf(BookEventPreFlushListener::class, $preFlushListener); $postFlushListener = static::getContainer()->get(BookEventPostFlushListener::class); - $this->assertInstanceOf(BookEventPostFlushListener::class, $postFlushListener); + self::assertInstanceOf(BookEventPostFlushListener::class, $postFlushListener); - $this->assertFalse($preFlushListener->onRemoveCalled()); - $this->assertFalse($postFlushListener->onRemoveCalled()); + self::assertFalse($preFlushListener->onRemoveCalled()); + self::assertFalse($postFlushListener->onRemoveCalled()); static::getEntityManager()->remove($book); static::getEntityManager()->flush(); - $this->assertTrue($preFlushListener->onRemoveCalled()); - $this->assertTrue($postFlushListener->onRemoveCalled()); + self::assertTrue($preFlushListener->onRemoveCalled()); + self::assertTrue($postFlushListener->onRemoveCalled()); } } diff --git a/tests/Framework/Tests/Transaction2Test.php b/tests/Framework/Tests/Transaction2Test.php index 1498960..fbba2be 100644 --- a/tests/Framework/Tests/Transaction2Test.php +++ b/tests/Framework/Tests/Transaction2Test.php @@ -23,7 +23,7 @@ final class Transaction2Test extends DomainEventTestCase private BookDummyChangedListener $listener; #[\Override] - public function setUp(): void + protected function setUp(): void { parent::setUp(); @@ -62,12 +62,12 @@ public function rollback(): void public function assertCountPreFlushEvents(int $expected): void { - $this->assertCount($expected, $this->listener->preFlush); + self::assertCount($expected, $this->listener->preFlush); } public function assertCountPostFlushEvents(int $expected): void { - $this->assertCount($expected, $this->listener->postFlush); + self::assertCount($expected, $this->listener->postFlush); } public function testChangeFlush(): void diff --git a/tests/Framework/Tests/TransactionTest.php b/tests/Framework/Tests/TransactionTest.php index 643b5c8..f91fe4e 100644 --- a/tests/Framework/Tests/TransactionTest.php +++ b/tests/Framework/Tests/TransactionTest.php @@ -22,10 +22,10 @@ final class TransactionTest extends DomainEventTestCase public function testWithoutTransaction(): void { $preFlushListener = static::getContainer()->get(BookEventPreFlushListener::class); - $this->assertInstanceOf(BookEventPreFlushListener::class, $preFlushListener); + self::assertInstanceOf(BookEventPreFlushListener::class, $preFlushListener); $postFlushListener = static::getContainer()->get(BookEventPostFlushListener::class); - $this->assertInstanceOf(BookEventPostFlushListener::class, $postFlushListener); + self::assertInstanceOf(BookEventPostFlushListener::class, $postFlushListener); $book = new Book('Book A', 'Description A'); $this->entityManager->persist($book); @@ -34,17 +34,17 @@ public function testWithoutTransaction(): void $book->setTitle('Book B'); $this->entityManager->flush(); - $this->assertEquals(1, $preFlushListener->onChangeCalled()); - $this->assertEquals(1, $postFlushListener->onChangeCalled()); + self::assertEquals(1, $preFlushListener->onChangeCalled()); + self::assertEquals(1, $postFlushListener->onChangeCalled()); } public function testTransaction(): void { $preFlushListener = static::getContainer()->get(BookEventPreFlushListener::class); - $this->assertInstanceOf(BookEventPreFlushListener::class, $preFlushListener); + self::assertInstanceOf(BookEventPreFlushListener::class, $preFlushListener); $postFlushListener = static::getContainer()->get(BookEventPostFlushListener::class); - $this->assertInstanceOf(BookEventPostFlushListener::class, $postFlushListener); + self::assertInstanceOf(BookEventPostFlushListener::class, $postFlushListener); $book = new Book('Book A', 'Description A'); $this->entityManager->persist($book); @@ -55,22 +55,22 @@ public function testTransaction(): void $book->setTitle('Book B'); $this->entityManager->flush(); - $this->assertEquals(1, $preFlushListener->onChangeCalled()); - $this->assertEquals(0, $postFlushListener->onChangeCalled()); + self::assertEquals(1, $preFlushListener->onChangeCalled()); + self::assertEquals(0, $postFlushListener->onChangeCalled()); $this->entityManager->commit(); - $this->assertEquals(1, $preFlushListener->onChangeCalled()); - $this->assertEquals(1, $postFlushListener->onChangeCalled()); + self::assertEquals(1, $preFlushListener->onChangeCalled()); + self::assertEquals(1, $postFlushListener->onChangeCalled()); } public function testNestedTransaction(): void { $preFlushListener = static::getContainer()->get(BookEventPreFlushListener::class); - $this->assertInstanceOf(BookEventPreFlushListener::class, $preFlushListener); + self::assertInstanceOf(BookEventPreFlushListener::class, $preFlushListener); $postFlushListener = static::getContainer()->get(BookEventPostFlushListener::class); - $this->assertInstanceOf(BookEventPostFlushListener::class, $postFlushListener); + self::assertInstanceOf(BookEventPostFlushListener::class, $postFlushListener); $book = new Book('Book A', 'Description A'); $this->entityManager->persist($book); @@ -81,35 +81,35 @@ public function testNestedTransaction(): void $book->setTitle('Book B'); $this->entityManager->flush(); - $this->assertEquals(1, $preFlushListener->onChangeCalled()); - $this->assertEquals(0, $postFlushListener->onChangeCalled()); + self::assertEquals(1, $preFlushListener->onChangeCalled()); + self::assertEquals(0, $postFlushListener->onChangeCalled()); $this->entityManager->beginTransaction(); // second transaction $book->setTitle('Book C'); $this->entityManager->flush(); - $this->assertEquals(2, $preFlushListener->onChangeCalled()); - $this->assertEquals(0, $postFlushListener->onChangeCalled()); + self::assertEquals(2, $preFlushListener->onChangeCalled()); + self::assertEquals(0, $postFlushListener->onChangeCalled()); $this->entityManager->commit(); // first commit - $this->assertEquals(2, $preFlushListener->onChangeCalled()); - $this->assertEquals(0, $postFlushListener->onChangeCalled()); + self::assertEquals(2, $preFlushListener->onChangeCalled()); + self::assertEquals(0, $postFlushListener->onChangeCalled()); $this->entityManager->commit(); // second commit - $this->assertEquals(2, $preFlushListener->onChangeCalled()); - $this->assertEquals(1, $postFlushListener->onChangeCalled()); + self::assertEquals(2, $preFlushListener->onChangeCalled()); + self::assertEquals(1, $postFlushListener->onChangeCalled()); } public function testRollbackTransaction(): void { $preFlushListener = static::getContainer()->get(BookEventPreFlushListener::class); - $this->assertInstanceOf(BookEventPreFlushListener::class, $preFlushListener); + self::assertInstanceOf(BookEventPreFlushListener::class, $preFlushListener); $postFlushListener = static::getContainer()->get(BookEventPostFlushListener::class); - $this->assertInstanceOf(BookEventPostFlushListener::class, $postFlushListener); + self::assertInstanceOf(BookEventPostFlushListener::class, $postFlushListener); $book = new Book('Book A', 'Description A'); $this->entityManager->persist($book); @@ -120,24 +120,24 @@ public function testRollbackTransaction(): void $book->setTitle('Book B'); $this->entityManager->flush(); - $this->assertEquals(1, $preFlushListener->onChangeCalled()); - $this->assertEquals(0, $postFlushListener->onChangeCalled()); + self::assertEquals(1, $preFlushListener->onChangeCalled()); + self::assertEquals(0, $postFlushListener->onChangeCalled()); $this->entityManager->rollback(); $events = $book->popRecordedEvents(); - $this->assertEmpty($events); - $this->assertEquals(1, $preFlushListener->onChangeCalled()); - $this->assertEquals(0, $postFlushListener->onChangeCalled()); + self::assertEmpty($events); + self::assertEquals(1, $preFlushListener->onChangeCalled()); + self::assertEquals(0, $postFlushListener->onChangeCalled()); } public function testEventsInQueueBeforeRollbackTransaction(): void { $preFlushListener = static::getContainer()->get(BookEventPreFlushListener::class); - $this->assertInstanceOf(BookEventPreFlushListener::class, $preFlushListener); + self::assertInstanceOf(BookEventPreFlushListener::class, $preFlushListener); $postFlushListener = static::getContainer()->get(BookEventPostFlushListener::class); - $this->assertInstanceOf(BookEventPostFlushListener::class, $postFlushListener); + self::assertInstanceOf(BookEventPostFlushListener::class, $postFlushListener); $book = new Book('Book A', 'Description A'); $this->entityManager->persist($book); @@ -148,12 +148,12 @@ public function testEventsInQueueBeforeRollbackTransaction(): void $book->setTitle('Book B'); $this->entityManager->flush(); - $this->assertEquals(1, $preFlushListener->onChangeCalled()); - $this->assertEquals(0, $postFlushListener->onChangeCalled()); + self::assertEquals(1, $preFlushListener->onChangeCalled()); + self::assertEquals(0, $postFlushListener->onChangeCalled()); $this->entityManager->rollback(); - $this->assertEquals(1, $preFlushListener->onChangeCalled()); - $this->assertEquals(0, $postFlushListener->onChangeCalled()); + self::assertEquals(1, $preFlushListener->onChangeCalled()); + self::assertEquals(0, $postFlushListener->onChangeCalled()); } }