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

api-platform / core / 10315659289

09 Aug 2024 07:49AM UTC coverage: 7.841% (-0.006%) from 7.847%
10315659289

push

github

soyuka
style: cs fixes

70 of 529 new or added lines in 176 files covered. (13.23%)

160 existing lines in 58 files now uncovered.

12688 of 161818 relevant lines covered (7.84%)

26.86 hits per line

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

0.0
/tests/Behat/HttpCacheContext.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\Tests\Behat;
15

16
use ApiPlatform\Tests\Fixtures\TestBundle\HttpCache\TagCollectorCustom;
17
use Behat\Behat\Context\Context;
18
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
19
use Behat\Mink\Driver\BrowserKitDriver;
20
use Behat\MinkExtension\Context\MinkContext;
21
use FriendsOfBehat\SymfonyExtension\Context\Environment\InitializedSymfonyExtensionEnvironment;
22
use PHPUnit\Framework\ExpectationFailedException;
23
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
24
use Symfony\Component\DependencyInjection\ContainerInterface;
25
use Symfony\Component\HttpKernel\KernelInterface;
26

27
/**
28
 * @author Kévin Dunglas <dunglas@gmail.com>
29
 */
30
final class HttpCacheContext implements Context
31
{
32
    public function __construct(private readonly KernelInterface $kernel, private ContainerInterface $driverContainer)
33
    {
34
    }
×
35

36
    /**
37
     * @BeforeScenario @customTagCollector
38
     */
39
    public function registerCustomTagCollector(BeforeScenarioScope $scope): void
40
    {
41
        $this->disableReboot($scope);
×
42
        /** @phpstan-ignore-next-line */
43
        $iriConverter = $this->driverContainer->get('api_platform.iri_converter');
×
44
        $this->driverContainer->set('api_platform.http_cache.tag_collector', new TagCollectorCustom($iriConverter));
×
45
    }
46

47
    /**
48
     * @Then :iris IRIs should be purged
49
     */
50
    public function irisShouldBePurged(string $iris): void
51
    {
52
        $purger = $this->kernel->getContainer()->get('behat.driver.service_container')->get('test.api_platform.http_cache.purger');
×
53

54
        $purgedIris = implode(',', $purger->getIris());
×
55
        $purger->clear();
×
56

57
        if ($iris !== $purgedIris) {
×
NEW
58
            throw new ExpectationFailedException(\sprintf('IRIs "%s" does not match expected "%s".', $purgedIris, $iris));
×
59
        }
60
    }
61

62
    /**
63
     * this is necessary to allow overriding services
64
     * see https://github.com/FriendsOfBehat/SymfonyExtension/issues/149 for details.
65
     */
66
    private function disableReboot(BeforeScenarioScope $scope): void
67
    {
68
        $env = $scope->getEnvironment();
×
69
        if (!$env instanceof InitializedSymfonyExtensionEnvironment) {
×
70
            return;
×
71
        }
72

73
        $driver = $env->getContext(MinkContext::class)->getSession()->getDriver();
×
74
        if (!$driver instanceof BrowserKitDriver) {
×
75
            return;
×
76
        }
77

78
        $client = $driver->getClient();
×
79
        if (!$client instanceof KernelBrowser) {
×
80
            return;
×
81
        }
82

83
        $client->disableReboot();
×
84
    }
85
}
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