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.

EndToEndTest::renderTwig()   A
last analyzed

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
     *
37
     * @dataProvider provideShortcodeNames
38
     */
39
    public function expand_shortcode_in__twig(string $shortcodeName): void
40
    {
41
        $result = $this->renderTwig('{{ content | shortcodes }}', ['content' => "[$shortcodeName foo=bar]"]);
42
43
        self::assertSame('test foo=bar', $result);
44
    }
45
46
    public static function provideShortcodeNames(): Generator
47
    {
48
        yield 'Inline shortcode defined in bundle config' => ['test-config-inline'];
49
        yield 'ESI-based shortcode defined in bundle config' => ['test-config-esi'];
50
        yield 'Inline shortcode defined in service definitions' => ['test-service-inline'];
51
        yield 'ESI-based shortcode defined in service definitions' => ['test-service-esi'];
52
    }
53
54
    /**
55
     * @test
56
     *
57
     * @dataProvider provideEsiShortcodes
58
     */
59
    public function uses_esi_fragments(string $shortcodeName): void
60
    {
61
        $request = new Request([], [], [], [], [], ['SCRIPT_URL' => '/', 'HTTP_HOST' => 'localhost']);
62
        $request->headers->set('Surrogate-Capability', 'ESI/1.0');
63
64
        $result = $this->renderTwig('{{ content | shortcodes }}', ['content' => "[$shortcodeName foo=bar]"], $request);
65
66
        self::assertStringContainsString('<esi:include ', $result);
67
    }
68
69
    public static function provideEsiShortcodes(): Generator
70
    {
71
        yield 'ESI-based shortcode defined in bundle configuration' => ['test-config-esi'];
72
        yield 'ESI-based shortcode defined in service configuration' => ['test-service-esi'];
73
    }
74
75
    private function renderTwig(string $templateCode, array $context = [], ?Request $request = null): string
76
    {
77
        self::bootKernel();
78
        $container = static::getContainer();
79
80
        $requestStack = $container->get(RequestStack::class);
81
        $requestStack->push($request ?? new Request());
82
83
        $twig = $container->get('twig');
84
85
        $template = $twig->createTemplate($templateCode);
86
87
        return $twig->render($template, $context);
88
    }
89
}
90