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

api-platform / core / 14445829754

14 Apr 2025 12:38PM UTC coverage: 8.402% (-0.09%) from 8.488%
14445829754

Pull #7088

github

web-flow
Merge 01f26cb47 into 0411cd9cc
Pull Request #7088: fix(symfony): correct class to exclude to avoid inheriting global default for internal resource

13267 of 157906 relevant lines covered (8.4%)

22.9 hits per line

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

0.0
/src/HttpCache/Tests/State/AddHeadersProcessorTest.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\State;
15

16
use ApiPlatform\HttpCache\State\AddHeadersProcessor;
17
use ApiPlatform\Metadata\Get;
18
use ApiPlatform\State\ProcessorInterface;
19
use PHPUnit\Framework\TestCase;
20
use Symfony\Component\HttpFoundation\Request;
21
use Symfony\Component\HttpFoundation\Response;
22

23
class AddHeadersProcessorTest extends TestCase
24
{
25
    public function testAddHeadersFromGlobalConfiguration(): void
26
    {
27
        $operation = new Get();
×
28
        $response = new Response('content');
×
29
        $request = new Request();
×
30
        $context = ['request' => $request];
×
31
        $decorated = $this->createMock(ProcessorInterface::class);
×
32
        $decorated->method('process')->willReturn($response);
×
33
        $processor = new AddHeadersProcessor($decorated, etag: true, maxAge: 100, sharedMaxAge: 200, vary: ['Accept', 'Accept-Encoding'], public: true, staleWhileRevalidate: 10, staleIfError: 10);
×
34

35
        $processor->process($response, $operation, [], $context);
×
36

37
        self::assertSame('max-age=100, public, s-maxage=200, stale-if-error=10, stale-while-revalidate=10', $response->headers->get('cache-control'));
×
38
        self::assertSame('"55f2b31a6acfaa64"', $response->headers->get('etag'));
×
39
        self::assertSame(['Accept', 'Accept-Encoding'], $response->headers->all('vary'));
×
40
    }
41

42
    public function testAddHeadersFromOperationConfiguration(): void
43
    {
44
        $operation = new Get(
×
45
            cacheHeaders: [
×
46
                'public' => false,
×
47
                'max_age' => 250,
×
48
                'shared_max_age' => 500,
×
49
                'stale_while_revalidate' => 30,
×
50
                'stale_if_error' => 15,
×
51
                'vary' => ['Authorization', 'Accept-Language'],
×
52
                'must_revalidate' => true,
×
53
                'proxy_revalidate' => true,
×
54
                'no_cache' => true,
×
55
                'no_store' => true,
×
56
                'no_transform' => true,
×
57
                'immutable' => true,
×
58
            ],
×
59
        );
×
60
        $response = new Response('content');
×
61
        $request = new Request();
×
62
        $context = ['request' => $request];
×
63
        $decorated = $this->createMock(ProcessorInterface::class);
×
64
        $decorated->method('process')->willReturn($response);
×
65
        $processor = new AddHeadersProcessor($decorated);
×
66

67
        $processor->process($response, $operation, [], $context);
×
68

69
        self::assertSame('immutable, max-age=250, must-revalidate, no-store, no-transform, private, proxy-revalidate, stale-if-error=15, stale-while-revalidate=30', $response->headers->get('cache-control'));
×
70
        self::assertSame(['Authorization', 'Accept-Language'], $response->headers->all('vary'));
×
71
    }
72
}
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