From 91ff453bd2041b5c0854684a107bb48b16c092f3 Mon Sep 17 00:00:00 2001 From: Vincent QUATREVIEUX Date: Mon, 28 Apr 2025 14:15:07 +0200 Subject: [PATCH 1/5] feat: Add Repository attribute to inject the prime repository (#FRAM-205) --- .php-cs-fixer.dist.php | 1 + Attribute/Repository.php | 32 ++++++++++++++++++++++++++++++ Tests/BdfPrimeBundleTest.php | 18 +++++++++++++++++ Tests/Fixtures/Php81/MyService.php | 23 +++++++++++++++++++++ Tests/conf.yaml | 1 + 5 files changed, 75 insertions(+) create mode 100644 Attribute/Repository.php create mode 100644 Tests/Fixtures/Php81/MyService.php diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 693651f..1b9a51b 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -4,6 +4,7 @@ ->in(__DIR__) ->exclude('var') ->exclude('tmp') + ->exclude('Tests/Fixtures/Php81') // @todo remove this when we drop PHP 7.X support ; return (new PhpCsFixer\Config()) diff --git a/Attribute/Repository.php b/Attribute/Repository.php new file mode 100644 index 0000000..c70bd92 --- /dev/null +++ b/Attribute/Repository.php @@ -0,0 +1,32 @@ +assertEquals($e, WithEnumEntity::first()); } + public function testInjectRepositoryWithAttribute() + { + if (PHP_VERSION_ID < 80100) { + $this->markTestSkipped(); + } + + $kernel = new TestKernel('dev', true); + $kernel->boot(); + + /** @var MyService $service */ + $service = $kernel->getContainer()->get(MyService::class); + + $this->assertInstanceOf(EntityRepository::class, $service->repository); + $this->assertSame(TestEntity::class, $service->repository->entityClass()); + } + private function getCommand(Application $console, string $name): Command { $command = $console->get($name); diff --git a/Tests/Fixtures/Php81/MyService.php b/Tests/Fixtures/Php81/MyService.php new file mode 100644 index 0000000..66bd0bd --- /dev/null +++ b/Tests/Fixtures/Php81/MyService.php @@ -0,0 +1,23 @@ + + */ + #[Repository(TestEntity::class)] + public $repository; + + public function __construct( + #[Repository(TestEntity::class)] + EntityRepository $repository + ) { + $this->repository = $repository; + } +} diff --git a/Tests/conf.yaml b/Tests/conf.yaml index 79a9b1d..3557430 100644 --- a/Tests/conf.yaml +++ b/Tests/conf.yaml @@ -22,6 +22,7 @@ services: Bdf\PrimeBundle\Tests\Fixtures\: autowire: true autoconfigure: true + public: true resource: './Fixtures' exclude: - './Fixtures/Php81/*Enum.php' From 658b736736ad6ec00581b46f963e8fcf8ceeaef2 Mon Sep 17 00:00:00 2001 From: Vincent QUATREVIEUX Date: Mon, 28 Apr 2025 14:34:39 +0200 Subject: [PATCH 2/5] ci: fix test on PHP < 8.1 --- Tests/Fixtures/Php81/MyService.php | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/Tests/Fixtures/Php81/MyService.php b/Tests/Fixtures/Php81/MyService.php index 66bd0bd..c344d07 100644 --- a/Tests/Fixtures/Php81/MyService.php +++ b/Tests/Fixtures/Php81/MyService.php @@ -6,18 +6,23 @@ use Bdf\PrimeBundle\Attribute\Repository; use Bdf\PrimeBundle\Tests\Fixtures\TestEntity; -class MyService -{ - /** - * @var EntityRepository - */ - #[Repository(TestEntity::class)] - public $repository; - - public function __construct( +if (PHP_VERSION_ID >= 80100) { + class MyService + { + /** + * @var EntityRepository + */ #[Repository(TestEntity::class)] - EntityRepository $repository - ) { - $this->repository = $repository; + public $repository; + + public function __construct( + #[Repository(TestEntity::class)] + EntityRepository $repository + ) { + $this->repository = $repository; + } } +} else { + // Add class to avoid error in PHP 7.X + class MyService {} } From 9a6b85d5a3c425cdd96ee0a66dd2596eea396a4c Mon Sep 17 00:00:00 2001 From: Vincent QUATREVIEUX Date: Mon, 28 Apr 2025 14:37:47 +0200 Subject: [PATCH 3/5] ci: fix test on PHP < 8.1 --- Tests/conf.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Tests/conf.yaml b/Tests/conf.yaml index 3557430..f91d263 100644 --- a/Tests/conf.yaml +++ b/Tests/conf.yaml @@ -22,10 +22,14 @@ services: Bdf\PrimeBundle\Tests\Fixtures\: autowire: true autoconfigure: true - public: true resource: './Fixtures' exclude: - './Fixtures/Php81/*Enum.php' + Bdf\PrimeBundle\Tests\Fixtures\Php81\MyService: + autowire: true + autoconfigure: true + public: true + Bdf\PrimeBundle\Tests\Fixtures\A: arguments: ['bar'] From 1954c0b607ba10f383bc47a07107c944e9ef6e95 Mon Sep 17 00:00:00 2001 From: Vincent QUATREVIEUX Date: Mon, 28 Apr 2025 14:46:28 +0200 Subject: [PATCH 4/5] ci: fix test on PHP < 8.1 --- Tests/BdfPrimeBundleTest.php | 3 ++- Tests/Fixtures/Php81/MyService.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Tests/BdfPrimeBundleTest.php b/Tests/BdfPrimeBundleTest.php index bb39682..743bccb 100644 --- a/Tests/BdfPrimeBundleTest.php +++ b/Tests/BdfPrimeBundleTest.php @@ -47,6 +47,7 @@ use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\LazyCommand; +use Symfony\Component\DependencyInjection\Attribute\AutowireInline; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Kernel; @@ -541,7 +542,7 @@ public function testEnumTypes() public function testInjectRepositoryWithAttribute() { - if (PHP_VERSION_ID < 80100) { + if (PHP_VERSION_ID < 80100 || !class_exists(AutowireInline::class)) { $this->markTestSkipped(); } diff --git a/Tests/Fixtures/Php81/MyService.php b/Tests/Fixtures/Php81/MyService.php index c344d07..bcfe205 100644 --- a/Tests/Fixtures/Php81/MyService.php +++ b/Tests/Fixtures/Php81/MyService.php @@ -5,8 +5,9 @@ use Bdf\Prime\Repository\EntityRepository; use Bdf\PrimeBundle\Attribute\Repository; use Bdf\PrimeBundle\Tests\Fixtures\TestEntity; +use Symfony\Component\DependencyInjection\Attribute\AutowireInline; -if (PHP_VERSION_ID >= 80100) { +if (PHP_VERSION_ID >= 80100 && class_exists(AutowireInline::class)) { class MyService { /** From 9db55bf947eccbcd064c22f1948375a5933b7b69 Mon Sep 17 00:00:00 2001 From: Vincent QUATREVIEUX Date: Mon, 28 Apr 2025 14:57:13 +0200 Subject: [PATCH 5/5] chore: Update CHANGELOG + bump v1.10 on composer.json --- CHANGELOG | 5 +++++ composer.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 8e69f2b..118592c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ +v1.10.0 +------- + + * Feat: Add `Repository` attribute to inject repository in constructor (SF 7.1 minimum) + v1.9.0 ------ diff --git a/composer.json b/composer.json index 2dc3299..99d8e2e 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.9-dev" + "dev-master": "1.10-dev" } }, "suggest": {