From 308b5748104b616483be1b1185189e639fd30174 Mon Sep 17 00:00:00 2001 From: Sylvain Fabre Date: Fri, 21 Aug 2026 12:14:33 +0200 Subject: [PATCH 1/3] Require symfony/cache, wired in services.yaml Co-Authored-By: Claude Fable 5 --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index dbe2bbf..0c7f6d5 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,8 @@ "assoconnect/php-percent":"^1.1", "assoconnect/absolute-percent-value-bundle": "^1.5", "webmozart/assert": "^1.11", - "psr/simple-cache": "^1.0" + "psr/simple-cache": "^1.0", + "symfony/cache": "^7.0" }, "require-dev": { "doctrine/cache": "~1.0", From 0e760e7132b65c88a65191690540a600ac6a48e4 Mon Sep 17 00:00:00 2001 From: Sylvain Fabre Date: Fri, 21 Aug 2026 15:29:43 +0200 Subject: [PATCH 2/3] Add functional smoke test covering the pdp PSR-16 cache chain The DI wiring in services.yaml was never exercised by the test suite: all tests build validators by hand, so a missing symfony/cache or psr/simple-cache package could not be detected. This boots the real container, runs PublicSuffixListCacheWarmer against a stubbed PSR-18 client, and asserts the second warm-up is served from the PSR-16 cache. The Pdp\Storage glob resource only resolved when the bundle was installed under a consumer vendor/ directory; it is replaced by the single explicit service that relied on it so the container can compile inside this repository too. Co-Authored-By: Claude Fable 5 --- composer.json | 1 + config/services.yaml | 3 +- src/Test/Functional/App/config/config.yml | 2 +- .../PublicSuffixListCacheChainTest.php | 50 +++++++++++++++++++ tests/Stub/PublicSuffixListClientStub.php | 27 ++++++++++ tests/TestKernel.php | 11 ++-- tests/config/config.yml | 11 ++++ 7 files changed, 94 insertions(+), 11 deletions(-) create mode 100644 tests/Functional/PublicSuffixListCacheChainTest.php create mode 100644 tests/Stub/PublicSuffixListClientStub.php create mode 100644 tests/config/config.yml diff --git a/composer.json b/composer.json index 0c7f6d5..f05444a 100644 --- a/composer.json +++ b/composer.json @@ -51,6 +51,7 @@ "doctrine/cache": "~1.0", "symfony/phpunit-bridge": "^7.0", "symfony/framework-bundle": "^7.0", + "symfony/var-exporter": "^7.0", "symfony/yaml": "^7.0", "dg/bypass-finals": "^1.1", "assoconnect/php-quality-config": "^2.2", diff --git a/config/services.yaml b/config/services.yaml index 50787a1..0187e61 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -9,8 +9,7 @@ services: AssoConnect\ValidatorBundle\Validator\ConstraintsSetProvider\: resource: '../src/Validator/ConstraintsSetProvider/*' - Pdp\Storage\: - resource: '../../../jeremykendall/php-domain-parser/src/Storage/*' + Pdp\Storage\PublicSuffixListPsr18Client: ~ pdp.cache: class: Symfony\Component\Cache\Psr16Cache diff --git a/src/Test/Functional/App/config/config.yml b/src/Test/Functional/App/config/config.yml index 0afc3d8..4c40186 100644 --- a/src/Test/Functional/App/config/config.yml +++ b/src/Test/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/Functional/PublicSuffixListCacheChainTest.php b/tests/Functional/PublicSuffixListCacheChainTest.php new file mode 100644 index 0000000..a22a969 --- /dev/null +++ b/tests/Functional/PublicSuffixListCacheChainTest.php @@ -0,0 +1,50 @@ +get(RulesStorage::class); + self::assertInstanceOf(RulesStorage::class, $rulesStorage); + $rulesStorage->delete(EmailValidator::PUBLIC_SUFFIX_LIST_URI); + + $stub = $container->get(PublicSuffixListClientStub::class); + self::assertInstanceOf(PublicSuffixListClientStub::class, $stub); + + $warmer = $container->get(PublicSuffixListCacheWarmer::class); + self::assertInstanceOf(PublicSuffixListCacheWarmer::class, $warmer); + self::assertFalse($warmer->isOptional()); + + $cacheDir = self::$kernel instanceof \Symfony\Component\HttpKernel\KernelInterface + ? self::$kernel->getCacheDir() + : sys_get_temp_dir(); + + self::assertSame([], $warmer->warmUp($cacheDir)); + self::assertSame(1, $stub->getRequestCount()); + + self::assertSame([], $warmer->warmUp($cacheDir)); + self::assertSame(1, $stub->getRequestCount(), 'The second warm-up must be served from the PSR-16 cache'); + + self::assertTrue(interface_exists(CacheInterface::class, false)); + } +} diff --git a/tests/Stub/PublicSuffixListClientStub.php b/tests/Stub/PublicSuffixListClientStub.php new file mode 100644 index 0000000..027f012 --- /dev/null +++ b/tests/Stub/PublicSuffixListClientStub.php @@ -0,0 +1,27 @@ +requestCount++; + + return new Response(200, [], "// public suffix list fixture\ncom\n"); + } + + public function getRequestCount(): int + { + return $this->requestCount; + } +} diff --git a/tests/TestKernel.php b/tests/TestKernel.php index 0081cab..a598237 100755 --- a/tests/TestKernel.php +++ b/tests/TestKernel.php @@ -4,19 +4,14 @@ namespace AssoConnect\ValidatorBundle\Tests; -use Symfony\Bundle\FrameworkBundle\FrameworkBundle; +use AssoConnect\ValidatorBundle\Test\Functional\App\TestKernel as FunctionalAppKernel; use Symfony\Component\Config\Loader\LoaderInterface; -use Symfony\Component\HttpKernel\Kernel; -class TestKernel extends Kernel +class TestKernel extends FunctionalAppKernel { - public function registerBundles(): iterable - { - return [new FrameworkBundle()]; - } - public function registerContainerConfiguration(LoaderInterface $loader): void { + parent::registerContainerConfiguration($loader); $loader->load(__DIR__ . '/config/config.yml'); } } diff --git a/tests/config/config.yml b/tests/config/config.yml new file mode 100644 index 0000000..491bbac --- /dev/null +++ b/tests/config/config.yml @@ -0,0 +1,11 @@ +framework: + test: true + +services: + AssoConnect\ValidatorBundle\Tests\Stub\PublicSuffixListClientStub: + public: true + + Psr\Http\Client\ClientInterface: '@AssoConnect\ValidatorBundle\Tests\Stub\PublicSuffixListClientStub' + + Psr\Http\Message\RequestFactoryInterface: + class: GuzzleHttp\Psr7\HttpFactory From b01f16a44d0769568079701dbb5b57f5fa0c007c Mon Sep 17 00:00:00 2001 From: Sylvain Fabre Date: Fri, 21 Aug 2026 15:36:48 +0200 Subject: [PATCH 3/3] Make the smoke test tolerant of boot-time cache warmup Symfony 7.0 runs non-optional warmers during kernel boot while 7.4 does not, so the stub request count is asserted relative to a post-boot baseline instead of an absolute value. Co-Authored-By: Claude Fable 5 --- tests/Functional/PublicSuffixListCacheChainTest.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/Functional/PublicSuffixListCacheChainTest.php b/tests/Functional/PublicSuffixListCacheChainTest.php index a22a969..1874815 100644 --- a/tests/Functional/PublicSuffixListCacheChainTest.php +++ b/tests/Functional/PublicSuffixListCacheChainTest.php @@ -39,11 +39,18 @@ public function testCacheWarmerRunsTheWholePsr16CacheChain(): void ? self::$kernel->getCacheDir() : sys_get_temp_dir(); + // The kernel boot may already have run the warmer, depending on the Symfony version + $requestsBeforeWarmup = $stub->getRequestCount(); + self::assertSame([], $warmer->warmUp($cacheDir)); - self::assertSame(1, $stub->getRequestCount()); + self::assertSame($requestsBeforeWarmup + 1, $stub->getRequestCount()); self::assertSame([], $warmer->warmUp($cacheDir)); - self::assertSame(1, $stub->getRequestCount(), 'The second warm-up must be served from the PSR-16 cache'); + self::assertSame( + $requestsBeforeWarmup + 1, + $stub->getRequestCount(), + 'The second warm-up must be served from the PSR-16 cache' + ); self::assertTrue(interface_exists(CacheInterface::class, false)); }