From a472ffe8d25e03b31bea95970f600de4bf9cb7d2 Mon Sep 17 00:00:00 2001 From: Nisiah78 Date: Thu, 30 Oct 2025 14:09:37 +0300 Subject: [PATCH 1/9] replace old listener sf into attribute --- src/Subscriber/LoggerSubscriber.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Subscriber/LoggerSubscriber.php b/src/Subscriber/LoggerSubscriber.php index 81b870c..777404c 100755 --- a/src/Subscriber/LoggerSubscriber.php +++ b/src/Subscriber/LoggerSubscriber.php @@ -8,6 +8,7 @@ use AssoConnect\LogBundle\Factory\LogFactoryInterface; use AssoConnect\LogBundle\Factory\RequestContextAwareLogFactoryInterface; use AssoConnect\LogBundle\Factory\SecurityContextAwareLogFactoryInterface; +use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener; use Doctrine\Common\EventSubscriber; use Doctrine\ORM\Event\OnFlushEventArgs; use Doctrine\ORM\Events; @@ -16,7 +17,8 @@ * This Doctrine subscriber creates a Log entity every time * a fully Doctrine-managed entity is persisted, updated, or removed. */ -class LoggerSubscriber implements EventSubscriber +#[AsDoctrineListener(event: Events::onFlush)] +class LoggerSubscriber { public function __construct( private readonly LogFactoryInterface $factory, @@ -25,11 +27,6 @@ public function __construct( ) { } - public function getSubscribedEvents(): array - { - return [Events::onFlush]; - } - public function onFlush(OnFlushEventArgs $eventArgs): void { $em = $eventArgs->getEntityManager(); From a675c9f9b0f24496801d120b72d7118288dfcb4e Mon Sep 17 00:00:00 2001 From: Nisiah78 Date: Thu, 30 Oct 2025 14:48:36 +0300 Subject: [PATCH 2/9] update unit test to handle the change from annotation to attribute --- src/Subscriber/LoggerSubscriber.php | 1 - tests/Factory/LogDataFactoryTest.php | 3 ++- tests/Functional/App/config/config.yml | 2 +- tests/Subscriber/LoggerSubscriberTest.php | 24 ++++++++++------------- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/Subscriber/LoggerSubscriber.php b/src/Subscriber/LoggerSubscriber.php index 777404c..a038e29 100755 --- a/src/Subscriber/LoggerSubscriber.php +++ b/src/Subscriber/LoggerSubscriber.php @@ -9,7 +9,6 @@ use AssoConnect\LogBundle\Factory\RequestContextAwareLogFactoryInterface; use AssoConnect\LogBundle\Factory\SecurityContextAwareLogFactoryInterface; use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener; -use Doctrine\Common\EventSubscriber; use Doctrine\ORM\Event\OnFlushEventArgs; use Doctrine\ORM\Events; diff --git a/tests/Factory/LogDataFactoryTest.php b/tests/Factory/LogDataFactoryTest.php index 7831492..2c41d3e 100644 --- a/tests/Factory/LogDataFactoryTest.php +++ b/tests/Factory/LogDataFactoryTest.php @@ -14,7 +14,8 @@ use PHPUnit\Framework\MockObject\MockObject; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; -class LogDataFactoryTest extends KernelTestCase +class +LogDataFactoryTest extends KernelTestCase { public function testExcludedEntityIsIgnored(): void { diff --git a/tests/Functional/App/config/config.yml b/tests/Functional/App/config/config.yml index f130885..386375d 100755 --- a/tests/Functional/App/config/config.yml +++ b/tests/Functional/App/config/config.yml @@ -5,7 +5,7 @@ framework: enabled: false validation: enabled: true - enable_annotations: true + enable_attributes: true doctrine: orm: mappings: diff --git a/tests/Subscriber/LoggerSubscriberTest.php b/tests/Subscriber/LoggerSubscriberTest.php index 78e70d4..a64405b 100755 --- a/tests/Subscriber/LoggerSubscriberTest.php +++ b/tests/Subscriber/LoggerSubscriberTest.php @@ -6,11 +6,10 @@ use AssoConnect\LogBundle\Entity\Log; use AssoConnect\LogBundle\Factory\LogDataFactory; -use AssoConnect\LogBundle\Factory\LogFactoryInterface; use AssoConnect\LogBundle\Subscriber\LoggerSubscriber; use AssoConnect\LogBundle\Tests\Functional\Entity\Address; use AssoConnect\LogBundle\Tests\Functional\Service\LogFactory; -use Doctrine\Common\EventManager; +use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Event\OnFlushEventArgs; use Doctrine\ORM\Events; @@ -21,16 +20,15 @@ class LoggerSubscriberTest extends KernelTestCase { - public function testEventSubscription(): void + public function testEventSubscriptionAsAnAttribute(): void { - self::assertSame( - [Events::onFlush], - (new LoggerSubscriber( - $this->createMock(LogFactoryInterface::class), - $this->createMock(LogDataFactory::class), - realpath(__DIR__ . '/../..') - ))->getSubscribedEvents() - ); + $reflection = new \ReflectionClass(LoggerSubscriber::class); + $attributes = $reflection->getAttributes(AsDoctrineListener::class); + + self::assertCount(1, $attributes, 'LoggerSubscriber should have AsDoctrineListener attribute'); + + $attribute = $attributes[0]->newInstance(); + self::assertSame(Events::onFlush, $attribute->event); } public function testSubscriberPersistsLogs(): void @@ -71,8 +69,6 @@ public function testSubscriberPersistsLogs(): void realpath(__DIR__ . '/../..') ); - $dispatcher = new EventManager(); - $dispatcher->addEventSubscriber($subscriber); - $dispatcher->dispatchEvent(Events::onFlush, $event); + $subscriber->onFlush($event); } } From d8206500f915c40ead9ee3c5616824da16a10f4f Mon Sep 17 00:00:00 2001 From: Nisiah78 Date: Thu, 30 Oct 2025 14:52:32 +0300 Subject: [PATCH 3/9] fix phpcs error --- tests/Factory/LogDataFactoryTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/Factory/LogDataFactoryTest.php b/tests/Factory/LogDataFactoryTest.php index 2c41d3e..7831492 100644 --- a/tests/Factory/LogDataFactoryTest.php +++ b/tests/Factory/LogDataFactoryTest.php @@ -14,8 +14,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; -class -LogDataFactoryTest extends KernelTestCase +class LogDataFactoryTest extends KernelTestCase { public function testExcludedEntityIsIgnored(): void { From cd9c95f0145da87f8ff20ffd5d9fb45fb616627f Mon Sep 17 00:00:00 2001 From: Nisiah78 Date: Thu, 30 Oct 2025 14:54:59 +0300 Subject: [PATCH 4/9] fix phpstan error from use of DateTime --- tests/Factory/LogDataFactoryTest.php | 2 +- tests/Functional/Entity/AbstractEntity.php | 4 ++-- tests/Functional/Entity/Author.php | 2 +- tests/Serializer/LogSerializerTest.php | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Factory/LogDataFactoryTest.php b/tests/Factory/LogDataFactoryTest.php index 7831492..95d39e6 100644 --- a/tests/Factory/LogDataFactoryTest.php +++ b/tests/Factory/LogDataFactoryTest.php @@ -71,7 +71,7 @@ public function testUpdatedEntityIsLogged(): void $unitOfWork->method('getEntityChangeSet')->with($updatedAuthor)->willReturn( [ 'email' => ['test@gmail.com'], - 'registeredAt' => [new \DateTime('2020-10-06')], + 'registeredAt' => [new \DateTimeImmutable('2020-10-06')], 'unmappedField' => ['test'], 'address' => [new Address()], ] diff --git a/tests/Functional/Entity/AbstractEntity.php b/tests/Functional/Entity/AbstractEntity.php index c104ca2..2e60c89 100755 --- a/tests/Functional/Entity/AbstractEntity.php +++ b/tests/Functional/Entity/AbstractEntity.php @@ -16,8 +16,8 @@ abstract class AbstractEntity public function __construct() { $this->id = rand(0, 10000000); - $this->createdAt = new DateTime(); - $this->updatedAt = new DateTime(); + $this->createdAt = new \DateTimeImmutable(); + $this->updatedAt = new \DateTimeImmutable(); } public function __toString(): string diff --git a/tests/Functional/Entity/Author.php b/tests/Functional/Entity/Author.php index 7ae3019..133153d 100755 --- a/tests/Functional/Entity/Author.php +++ b/tests/Functional/Entity/Author.php @@ -13,7 +13,7 @@ class Author extends AbstractEntity public function __construct() { parent::__construct(); - $this->registeredAt = new \DateTime(); + $this->registeredAt = new \DateTimeImmutable(); } #[ORM\Column(type: 'email')] diff --git a/tests/Serializer/LogSerializerTest.php b/tests/Serializer/LogSerializerTest.php index 122784e..fe7c096 100755 --- a/tests/Serializer/LogSerializerTest.php +++ b/tests/Serializer/LogSerializerTest.php @@ -104,8 +104,8 @@ public function providerFormatValueAsString(): iterable yield [1.5, '1.5']; yield [[1.5], '[1.5]']; - yield [new DateTime('@1529500134'), '"2018-06-20T13:08:54+0000"']; - yield [[new DateTime('@1529500134')], '["2018-06-20T13:08:54+0000"]']; + yield [new \DateTimeImmutable('@1529500134'), '"2018-06-20T13:08:54+0000"']; + yield [[new \DateTimeImmutable('@1529500134')], '["2018-06-20T13:08:54+0000"]']; yield [new DateTimeZone('Europe/Paris'), '"Europe\/Paris"']; yield [[new DateTimeZone('Europe/Paris')], '["Europe\/Paris"]']; From a645b1d06c98fc348f5f849dd1b7a1e5205b8e88 Mon Sep 17 00:00:00 2001 From: Nisiah78 Date: Thu, 30 Oct 2025 16:13:40 +0300 Subject: [PATCH 5/9] remove old version of symfony on composer --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f2b34ec..90330d9 100755 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ }, "require": { "php": "^8.2", - "symfony/framework-bundle": "^5.3|^6.0|^7.0", + "symfony/framework-bundle": "^6.2|^7.0", "doctrine/dbal": "^2.10|^3.0", "symfony/serializer": "^5.1|^6.0", "symfony/property-access": "^5.4|^6.0", From 436cd3119b8b59fb4b7df498e096e1fdfb405611 Mon Sep 17 00:00:00 2001 From: Nisiah78 Date: Thu, 30 Oct 2025 16:23:28 +0300 Subject: [PATCH 6/9] fix old version of symfony component to recent --- composer.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 90330d9..f62cde8 100755 --- a/composer.json +++ b/composer.json @@ -31,19 +31,19 @@ } }, "require-dev": { - "symfony/yaml": "^5.0|^6.0", - "symfony/validator": "^5.2|^6.0", + "symfony/yaml": "^6.2", + "symfony/validator": "^6.2", "phpstan/phpstan-symfony": "^1.0", "assoconnect/php-quality-config": "^1.10", - "symfony/security-core": "^5.0|^6.0", + "symfony/security-core": "^6.2", "rector/rector": "^1.2" }, "require": { "php": "^8.2", "symfony/framework-bundle": "^6.2|^7.0", "doctrine/dbal": "^2.10|^3.0", - "symfony/serializer": "^5.1|^6.0", - "symfony/property-access": "^5.4|^6.0", + "symfony/serializer": "^6.2", + "symfony/property-access": "^6.2", "doctrine/doctrine-bundle": "^2.11", "doctrine/orm": "^2.9", "moneyphp/money": "^3.2|^4.0", From b5db7313ac8281997b2ef9bcf7c2781d5f1b1b30 Mon Sep 17 00:00:00 2001 From: Nisiah78 Date: Thu, 30 Oct 2025 16:29:57 +0300 Subject: [PATCH 7/9] upgrade acceptable version of symfony to 6.4 --- composer.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index f62cde8..18082c3 100755 --- a/composer.json +++ b/composer.json @@ -31,19 +31,19 @@ } }, "require-dev": { - "symfony/yaml": "^6.2", - "symfony/validator": "^6.2", + "symfony/yaml": "^6.4", + "symfony/validator": "^6.4", "phpstan/phpstan-symfony": "^1.0", "assoconnect/php-quality-config": "^1.10", - "symfony/security-core": "^6.2", + "symfony/security-core": "^6.4", "rector/rector": "^1.2" }, "require": { "php": "^8.2", - "symfony/framework-bundle": "^6.2|^7.0", + "symfony/framework-bundle": "^6.4|^7.0", "doctrine/dbal": "^2.10|^3.0", - "symfony/serializer": "^6.2", - "symfony/property-access": "^6.2", + "symfony/serializer": "^6.4", + "symfony/property-access": "^6.4", "doctrine/doctrine-bundle": "^2.11", "doctrine/orm": "^2.9", "moneyphp/money": "^3.2|^4.0", From 96ec19496684811d398eb6557c66cd2807af5b8b Mon Sep 17 00:00:00 2001 From: Nisiah78 Date: Thu, 30 Oct 2025 17:00:55 +0300 Subject: [PATCH 8/9] removed unused import on test --- tests/Functional/Entity/AbstractEntity.php | 1 - tests/Serializer/LogSerializerTest.php | 1 - 2 files changed, 2 deletions(-) diff --git a/tests/Functional/Entity/AbstractEntity.php b/tests/Functional/Entity/AbstractEntity.php index 2e60c89..f0ccc2c 100755 --- a/tests/Functional/Entity/AbstractEntity.php +++ b/tests/Functional/Entity/AbstractEntity.php @@ -4,7 +4,6 @@ namespace AssoConnect\LogBundle\Tests\Functional\Entity; -use DateTime; use DateTimeInterface; use Doctrine\ORM\Mapping as ORM; diff --git a/tests/Serializer/LogSerializerTest.php b/tests/Serializer/LogSerializerTest.php index fe7c096..45eff35 100755 --- a/tests/Serializer/LogSerializerTest.php +++ b/tests/Serializer/LogSerializerTest.php @@ -12,7 +12,6 @@ use AssoConnect\LogBundle\Tests\Functional\Entity\ObjectWithoutId; use AssoConnect\LogBundle\Tests\Functional\Entity\Post; use AssoConnect\LogBundle\Tests\Functional\Entity\Tag; -use DateTime; use DateTimeZone; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\EntityManagerInterface; From 2539136e1f994ea19ebbcaaaccbc515fd5075f00 Mon Sep 17 00:00:00 2001 From: Nisiah78 Date: Thu, 30 Oct 2025 18:34:58 +0300 Subject: [PATCH 9/9] increase lowest acceptable version for assoconnect php quality config --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 18082c3..499ee60 100755 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ "symfony/yaml": "^6.4", "symfony/validator": "^6.4", "phpstan/phpstan-symfony": "^1.0", - "assoconnect/php-quality-config": "^1.10", + "assoconnect/php-quality-config": "^1.16", "symfony/security-core": "^6.4", "rector/rector": "^1.2" },