Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@
"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",
"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",
Expand Down
3 changes: 1 addition & 2 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Test/Functional/App/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ framework:
enabled: false
validation:
enabled: true
enable_annotations: true
enable_attributes: true
doctrine:
orm:
mappings:
Expand Down
57 changes: 57 additions & 0 deletions tests/Functional/PublicSuffixListCacheChainTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace AssoConnect\ValidatorBundle\Tests\Functional;

use AssoConnect\ValidatorBundle\Cache\PublicSuffixListCacheWarmer;
use AssoConnect\ValidatorBundle\Tests\Stub\PublicSuffixListClientStub;
use AssoConnect\ValidatorBundle\Validator\Constraints\EmailValidator;
use Pdp\Storage\RulesStorage;
use Psr\SimpleCache\CacheInterface;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

class PublicSuffixListCacheChainTest extends KernelTestCase
{
protected function tearDown(): void
{
parent::tearDown();
restore_exception_handler();
}

public function testCacheWarmerRunsTheWholePsr16CacheChain(): void
{
self::bootKernel();
$container = self::getContainer();

$rulesStorage = $container->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();

// The kernel boot may already have run the warmer, depending on the Symfony version
$requestsBeforeWarmup = $stub->getRequestCount();

self::assertSame([], $warmer->warmUp($cacheDir));
self::assertSame($requestsBeforeWarmup + 1, $stub->getRequestCount());

self::assertSame([], $warmer->warmUp($cacheDir));
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));
}
}
27 changes: 27 additions & 0 deletions tests/Stub/PublicSuffixListClientStub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace AssoConnect\ValidatorBundle\Tests\Stub;

use GuzzleHttp\Psr7\Response;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

final class PublicSuffixListClientStub implements ClientInterface
{
private int $requestCount = 0;

public function sendRequest(RequestInterface $request): ResponseInterface
{
$this->requestCount++;

return new Response(200, [], "// public suffix list fixture\ncom\n");
}

public function getRequestCount(): int
{
return $this->requestCount;
}
}
11 changes: 3 additions & 8 deletions tests/TestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
11 changes: 11 additions & 0 deletions tests/config/config.yml
Original file line number Diff line number Diff line change
@@ -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
Loading