GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Failed
Push — master ( 2c1dbb...6a0f46 )
by Matthias
03:18
created

EndToEndTest::renderTwig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
nc 1
nop 3
dl 0
loc 13
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Webfactory\ShortcodeBundle\Tests\Functional;
4
5
use Generator;
6
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
7
use Symfony\Component\HttpFoundation\Request;
8
use Symfony\Component\HttpFoundation\RequestStack;
9
10
/**
11
 * Test that given test shortcodes are found in a Twig template and being replaced with the
12
 * corresponding test controller's response content.
13
 */
14
final class EndToEndTest extends KernelTestCase
15
{
16
    /** @test */
17
    public function paragraphs_wrapping_shortcodes_get_removed(): void
18
    {
19
        $this->assertEquals(
20
            'test',
21
            $this->renderTwig("{{ '<p>[test-config-inline]</p>' | shortcodes }}")
22
        );
23
    }
24
25
    /** @test */
26
    public function content_without_shortcodes_wont_be_changed(): void
27
    {
28
        $this->assertEquals(
29
            '<p>Content without shortcode</p>',
30
            $this->renderTwig("{{ '<p>Content without shortcode</p>' | shortcodes }}")
31
        );
32
    }
33
34
    /**
35
     * @test
36
     * @dataProvider provideShortcodeNames
37
     */
38
    public function expand_shortcode_in__twig(string $shortcodeName): void
39
    {
40
        $result = $this->renderTwig('{{ content | shortcodes }}', ['content' => "[$shortcodeName foo=bar]"]);
41
42
        self::assertSame('test foo=bar', $result);
43
    }
44
45
    public function provideShortcodeNames(): Generator
46
    {
47
        yield 'Inline shortcode defined in bundle config' => ['test-config-inline'];
48
        yield 'ESI-based shortcode defined in bundle config' => ['test-config-esi'];
49
        yield 'Inline shortcode defined in service definitions' => ['test-service-inline'];
50
        yield 'ESI-based shortcode defined in service definitions' => ['test-service-esi'];
51
    }
52
53
    /**
54
     * @test
55
     * @dataProvider provideEsiShortcodes
56
     */
57
    public function uses_esi_fragments(string $shortcodeName): void
58
    {
59
        $request = new Request([], [], [], [], [], ['SCRIPT_URL' => '/', 'HTTP_HOST' => 'localhost']);
60
        $request->headers->set('Surrogate-Capability', 'ESI/1.0');
61
62
        $result = $this->renderTwig('{{ content | shortcodes }}', ['content' => "[$shortcodeName foo=bar]"], $request);
63
64
        self::assertStringContainsString('<esi:include ', $result);
65
    }
66
67
    public function provideEsiShortcodes(): Generator
68
    {
69
        yield 'ESI-based shortcode defined in bundle configuration' => ['test-config-esi'];
70
        yield 'ESI-based shortcode defined in service configuration' => ['test-service-esi'];
71
    }
72
73
    private function renderTwig(string $templateCode, array $context = [], Request $request = null): string
74
    {
75
        self::bootKernel();
76
        $container = static::$container;
77
78
        $requestStack = $container->get(RequestStack::class);
79
        $requestStack->push($request ?? new Request());
80
81
        $twig = $container->get('twig');
82
83
        $template = $twig->createTemplate($templateCode);
84
85
        return $twig->render($template, $context);
86
    }
87
}
88