Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 186cd69

Browse files
authored
fix(symfony): wrong purger clients type (#5373)
fixes #5365
1 parent 78ae122 commit 186cd69

6 files changed

Lines changed: 28 additions & 4 deletions

File tree

src/HttpCache/SouinPurger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class SouinPurger extends SurrogateKeysPurger
2929
/**
3030
* @param HttpClientInterface[] $clients
3131
*/
32-
public function __construct(array $clients)
32+
public function __construct(iterable $clients)
3333
{
3434
parent::__construct($clients, self::MAX_HEADER_SIZE_PER_BATCH, self::HEADER, self::SEPARATOR);
3535
}

src/HttpCache/SurrogateKeysPurger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class SurrogateKeysPurger implements PurgerInterface
3131
/**
3232
* @param HttpClientInterface[] $clients
3333
*/
34-
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)
34+
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)
3535
{
3636
}
3737

src/HttpCache/VarnishPurger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class VarnishPurger implements PurgerInterface
2929
/**
3030
* @param HttpClientInterface[] $clients
3131
*/
32-
public function __construct(private readonly array $clients, int $maxHeaderLength = self::DEFAULT_VARNISH_MAX_HEADER_LENGTH)
32+
public function __construct(private readonly iterable $clients, int $maxHeaderLength = self::DEFAULT_VARNISH_MAX_HEADER_LENGTH)
3333
{
3434
$this->maxHeaderLength = $maxHeaderLength - mb_strlen(self::REGEXP_PATTERN) + 2; // 2 for %s
3535
}

src/HttpCache/VarnishXKeyPurger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ final class VarnishXKeyPurger extends SurrogateKeysPurger
2828
/**
2929
* @param HttpClientInterface[] $clients
3030
*/
31-
public function __construct(array $clients, int $maxHeaderLength = self::VARNISH_MAX_HEADER_LENGTH, string $xkeyGlue = self::VARNISH_SEPARATOR)
31+
public function __construct(iterable $clients, int $maxHeaderLength = self::VARNISH_MAX_HEADER_LENGTH, string $xkeyGlue = self::VARNISH_SEPARATOR)
3232
{
3333
parent::__construct($clients, $maxHeaderLength, 'xkey', $xkeyGlue);
3434
}

tests/HttpCache/VarnishPurgerTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Prophecy\PhpUnit\ProphecyTrait;
2222
use Psr\Http\Message\RequestInterface;
2323
use Psr\Http\Message\ResponseInterface;
24+
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
2425
use Symfony\Contracts\HttpClient\HttpClientInterface;
2526

2627
/**
@@ -175,4 +176,15 @@ public function provideChunkHeaderCases(): \Generator
175176
],
176177
];
177178
}
179+
180+
public function testConstructor(): void
181+
{
182+
$clientProphecy = $this->prophesize(HttpClientInterface::class);
183+
$clientProphecy->request('BAN', '', ['headers' => ['ApiPlatform-Ban-Regex' => '(/foo)($|\,)']])->shouldBeCalled();
184+
$purger = new VarnishPurger(new RewindableGenerator(static function () use ($clientProphecy) {
185+
yield $clientProphecy->reveal();
186+
}, 1));
187+
188+
$purger->purge(['/foo']);
189+
}
178190
}

tests/HttpCache/VarnishXKeyPurgerTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Prophecy\PhpUnit\ProphecyTrait;
2222
use Psr\Http\Message\RequestInterface;
2323
use Psr\Http\Message\ResponseInterface;
24+
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
2425
use Symfony\Contracts\HttpClient\HttpClientInterface;
2526

2627
/**
@@ -205,4 +206,15 @@ public function provideChunkHeaderCases(): \Generator
205206
],
206207
];
207208
}
209+
210+
public function testConstructor(): void
211+
{
212+
$clientProphecy = $this->prophesize(ClientInterface::class);
213+
$clientProphecy->request('PURGE', '', ['headers' => ['xkey' => '/foo']])->willReturn(new Response())->shouldBeCalled();
214+
$purger = new VarnishXKeyPurger(new RewindableGenerator(static function () use ($clientProphecy) {
215+
yield $clientProphecy->reveal();
216+
}, 1));
217+
218+
$purger->purge(['/foo']);
219+
}
208220
}

0 commit comments

Comments
 (0)