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

api-platform / core / 18089937549

29 Sep 2025 07:56AM UTC coverage: 21.764% (-0.3%) from 22.093%
18089937549

Pull #7416

github

web-flow
Merge 061bcc790 into abe0438be
Pull Request #7416: fix(laravel): serializer attributes on Eloquent methods

0 of 151 new or added lines in 11 files covered. (0.0%)

5028 existing lines in 173 files now uncovered.

11889 of 54626 relevant lines covered (21.76%)

25.32 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
    {
UNCOV
34
        $clientProphecy1 = $this->prophesize(HttpClientInterface::class);
×
UNCOV
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);
×
UNCOV
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()]);
×
UNCOV
43
        $purger->purge(['/foo']);
×
44
        $purger->purge(['/foo' => '/foo', '/bar' => '/bar']);
×
45
    }
46

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

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

UNCOV
55
        return $stack;
×
56
    }
57

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

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

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

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

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

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

89
    public function testPurgeWithMultipleClients(): void
90
    {
UNCOV
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

98
                return new MockResponse();
×
99
            }
100

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

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

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

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

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

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

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

146
    public function testGetResponseHeaders(): void
147
    {
UNCOV
148
        $purger = new SouinPurger([]);
×
UNCOV
149
        self::assertSame(['Surrogate-Key' => ''], $purger->getResponseHeaders([]));
×
UNCOV
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