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
2 changes: 1 addition & 1 deletion src/HttpCache/SouinPurger.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SouinPurger extends SurrogateKeysPurger
/**
* @param HttpClientInterface[] $clients
*/
public function __construct(array $clients)
public function __construct(iterable $clients)
{
parent::__construct($clients, self::MAX_HEADER_SIZE_PER_BATCH, self::HEADER, self::SEPARATOR);
}
Expand Down
2 changes: 1 addition & 1 deletion src/HttpCache/SurrogateKeysPurger.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SurrogateKeysPurger implements PurgerInterface
/**
* @param HttpClientInterface[] $clients
*/
public function __construct(protected readonly array $clients, protected readonly int $maxHeaderLength = self::MAX_HEADER_SIZE_PER_BATCH, protected readonly string $header = self::HEADER, protected readonly string $separator = self::SEPARATOR)
public function __construct(protected readonly iterable $clients, protected readonly int $maxHeaderLength = self::MAX_HEADER_SIZE_PER_BATCH, protected readonly string $header = self::HEADER, protected readonly string $separator = self::SEPARATOR)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/HttpCache/VarnishPurger.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class VarnishPurger implements PurgerInterface
/**
* @param HttpClientInterface[] $clients
*/
public function __construct(private readonly array $clients, int $maxHeaderLength = self::DEFAULT_VARNISH_MAX_HEADER_LENGTH)
public function __construct(private readonly iterable $clients, int $maxHeaderLength = self::DEFAULT_VARNISH_MAX_HEADER_LENGTH)
{
$this->maxHeaderLength = $maxHeaderLength - mb_strlen(self::REGEXP_PATTERN) + 2; // 2 for %s
}
Expand Down
2 changes: 1 addition & 1 deletion src/HttpCache/VarnishXKeyPurger.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class VarnishXKeyPurger extends SurrogateKeysPurger
/**
* @param HttpClientInterface[] $clients
*/
public function __construct(array $clients, int $maxHeaderLength = self::VARNISH_MAX_HEADER_LENGTH, string $xkeyGlue = self::VARNISH_SEPARATOR)
public function __construct(iterable $clients, int $maxHeaderLength = self::VARNISH_MAX_HEADER_LENGTH, string $xkeyGlue = self::VARNISH_SEPARATOR)
{
parent::__construct($clients, $maxHeaderLength, 'xkey', $xkeyGlue);
}
Expand Down
12 changes: 12 additions & 0 deletions tests/HttpCache/VarnishPurgerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
use Symfony\Contracts\HttpClient\HttpClientInterface;

/**
Expand Down Expand Up @@ -175,4 +176,15 @@ public function provideChunkHeaderCases(): \Generator
],
];
}

public function testConstructor(): void
{
$clientProphecy = $this->prophesize(HttpClientInterface::class);
$clientProphecy->request('BAN', '', ['headers' => ['ApiPlatform-Ban-Regex' => '(/foo)($|\,)']])->shouldBeCalled();
$purger = new VarnishPurger(new RewindableGenerator(static function () use ($clientProphecy) {
yield $clientProphecy->reveal();
}, 1));

$purger->purge(['/foo']);
}
}
12 changes: 12 additions & 0 deletions tests/HttpCache/VarnishXKeyPurgerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
use Symfony\Contracts\HttpClient\HttpClientInterface;

/**
Expand Down Expand Up @@ -205,4 +206,15 @@ public function provideChunkHeaderCases(): \Generator
],
];
}

public function testConstructor(): void
{
$clientProphecy = $this->prophesize(ClientInterface::class);
$clientProphecy->request('PURGE', '', ['headers' => ['xkey' => '/foo']])->willReturn(new Response())->shouldBeCalled();
$purger = new VarnishXKeyPurger(new RewindableGenerator(static function () use ($clientProphecy) {
yield $clientProphecy->reveal();
}, 1));

$purger->purge(['/foo']);
}
}