• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 15999509586

01 Jul 2025 12:36PM UTC coverage: 21.821% (-0.2%) from 22.065%
15999509586

push

github

web-flow
chore: more phpstan fixes (#7265)

2 of 25 new or added lines in 6 files covered. (8.0%)

38 existing lines in 6 files now uncovered.

11388 of 52189 relevant lines covered (21.82%)

10.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/HttpCache/Tests/SouinPurgerTest.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\HttpCache\Tests;
15

16
use ApiPlatform\HttpCache\SouinPurger;
17
use PHPUnit\Framework\TestCase;
18
use Prophecy\PhpUnit\ProphecyTrait;
19
use Symfony\Component\HttpClient\Response\MockResponse;
20
use Symfony\Component\HttpFoundation\Request;
21
use Symfony\Contracts\HttpClient\HttpClientInterface;
22
use Symfony\Contracts\HttpClient\ResponseInterface;
23
use Symfony\Contracts\HttpClient\ResponseStreamInterface;
24

25
/**
26
 * @author Sylvain Combraque <darkweak@protonmail.com>
27
 */
28
class SouinPurgerTest extends TestCase
29
{
30
    use ProphecyTrait;
31

32
    public function testPurge(): void
33
    {
34
        $clientProphecy1 = $this->prophesize(HttpClientInterface::class);
×
35
        $clientProphecy1->request('PURGE', '', ['headers' => ['Surrogate-Key' => '/foo']])->shouldBeCalled();
×
36
        $clientProphecy1->request('PURGE', '', ['headers' => ['Surrogate-Key' => '/foo, /bar']])->shouldBeCalled();
×
37

38
        $clientProphecy2 = $this->prophesize(HttpClientInterface::class);
×
39
        $clientProphecy2->request('PURGE', '', ['headers' => ['Surrogate-Key' => '/foo']])->shouldBeCalled();
×
40
        $clientProphecy2->request('PURGE', '', ['headers' => ['Surrogate-Key' => '/foo, /bar']])->shouldBeCalled();
×
41

42
        $purger = new SouinPurger([$clientProphecy1->reveal(), $clientProphecy2->reveal()]);
×
43
        $purger->purge(['/foo']);
×
44
        $purger->purge(['/foo' => '/foo', '/bar' => '/bar']);
×
45
    }
46

47
    private function generateXResourcesTags(int $number, int $minimum = 0): array
48
    {
49
        $stack = [];
×
50

51
        for ($i = $minimum; $i < $number; ++$i) {
×
52
            $stack[] = \sprintf('/tags/%d', $i);
×
53
        }
54

55
        return $stack;
×
56
    }
57

58
    public function testMultiChunkedTags(): void
59
    {
NEW
60
        $client = new class implements HttpClientInterface {
×
61
            public array $sentRegexes = [];
62

63
            public function request(string $method, string $url, array $options = []): ResponseInterface
64
            {
65
                $this->sentRegexes[] = $options['headers']['Surrogate-Key'];
×
66

NEW
67
                return new MockResponse();
×
68
            }
69

70
            public function stream(ResponseInterface|iterable $responses, ?float $timeout = null): ResponseStreamInterface
71
            {
72
                throw new \LogicException('Not implemented');
×
73
            }
74

75
            public function withOptions(array $options): static
76
            {
NEW
77
                return $this;
×
78
            }
79
        };
×
80
        $purger = new SouinPurger([$client]);
×
81
        $purger->purge($this->generateXResourcesTags(200));
×
82

83
        self::assertSame([
×
84
            implode(', ', $this->generateXResourcesTags(146)),
×
85
            implode(', ', $this->generateXResourcesTags(200, 146)),
×
NEW
86
        ], $client->sentRegexes);
×
87
    }
88

89
    public function testPurgeWithMultipleClients(): void
90
    {
NEW
91
        $client1 = new class implements HttpClientInterface {
×
92
            public array $requests = [];
93

94
            public function request(string $method, string $url, array $options = []): ResponseInterface
95
            {
96
                $this->requests[] = [$method, 'http://dummy_host/dummy_api_path/souin_api', $options];
×
97

NEW
98
                return new MockResponse();
×
99
            }
100

101
            public function stream(ResponseInterface|iterable $responses, ?float $timeout = null): ResponseStreamInterface
102
            {
103
                throw new \LogicException('Not implemented');
×
104
            }
105

106
            public function withOptions(array $options): static
107
            {
NEW
108
                return $this;
×
109
            }
110
        };
×
NEW
111
        $client2 = new class implements HttpClientInterface {
×
112
            public array $requests = [];
113

114
            public function request(string $method, string $url, array $options = []): ResponseInterface
115
            {
116
                $this->requests[] = [$method, 'http://dummy_host/dummy_api_path/souin_api', $options];
×
117

NEW
118
                return new MockResponse();
×
119
            }
120

121
            public function stream(ResponseInterface|iterable $responses, ?float $timeout = null): ResponseStreamInterface
122
            {
123
                throw new \LogicException('Not implemented');
×
124
            }
125

126
            public function withOptions(array $options): static
127
            {
NEW
128
                return $this;
×
129
            }
130
        };
×
131

132
        $purger = new SouinPurger([$client1, $client2]);
×
133
        $purger->purge(['/foo']);
×
134
        self::assertSame([
×
135
            Request::METHOD_PURGE,
×
136
            'http://dummy_host/dummy_api_path/souin_api',
×
137
            ['headers' => ['Surrogate-Key' => '/foo']],
×
NEW
138
        ], $client1->requests[0]);
×
139
        self::assertSame([
×
140
            Request::METHOD_PURGE,
×
141
            'http://dummy_host/dummy_api_path/souin_api',
×
142
            ['headers' => ['Surrogate-Key' => '/foo']],
×
NEW
143
        ], $client2->requests[0]);
×
144
    }
145

146
    public function testGetResponseHeaders(): void
147
    {
148
        $purger = new SouinPurger([]);
×
149
        self::assertSame(['Surrogate-Key' => ''], $purger->getResponseHeaders([]));
×
150
        self::assertSame(['Surrogate-Key' => 'first-value/, second'], $purger->getResponseHeaders(['first-value/', 'second']));
×
151
        self::assertSame(['Surrogate-Key' => 'C0mplex_Value/, The value with spaces'], $purger->getResponseHeaders(['C0mplex_Value/', 'The value with spaces']));
×
152
    }
153
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc