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.
Passed
Push — master ( c7c802...71c991 )
by Malte
03:14
created

ShortcodeFacadeTest::renderTwigTemplate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Webfactory\ShortcodeBundle\Tests\Functional;
4
5
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
6
use Symfony\Component\HttpKernel\Controller\ControllerReference;
7
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
8
9
final class ShortcodeFacadeTest extends KernelTestCase
10
{
11
    /**
12
     * @var array [
13
     *     [
14
     *         'controller' => 'app.controller.myFilter:myfilterPartialAction',
15
     *         'renderer' => 'esi',
16
     *         'name' => 'myShortcode',
17
     *     ]
18
     * ]
19
     */
20
    static protected $shortcodesToRegister = [];
21
22
    protected static function createKernel(array $options = array())
23
    {
24
        return new TestKernel('test', true, static::$shortcodesToRegister);
25
    }
26
27
    /** @test */
28 View Code Duplication
    public function shortcode_leads_to_rendering_of_controller_reference()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style Naming introduced by
The method shortcode_leads_to_rendering_of_controller_reference is not named in camelCase.

This check marks method names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style introduced by
Method name "ShortcodeFacadeTest::shortcode_leads_to_rendering_of_controller_reference" is not in camel caps format
Loading history...
29
    {
30
        static::$shortcodesToRegister = [
31
            [
32
                'controller' => 'app.controller.myFilter:myfilterPartialAction',
33
                'renderer' => 'esi',
34
                'name' => 'myShortcode',
35
            ]
36
        ];
37
        static::bootKernel();
38
39
        // Replace fragment renderer in test kernel, as we only want to assert it is called with the correct parameters,
40
        // but not it's result.
41
        $container = static::$kernel->getContainer();
42
        $fragmentHandler = $this->getMockBuilder(FragmentHandler::class)->disableOriginalConstructor()->getMock();
43
        $fragmentHandler->expects($this->once())
44
            ->method('render')
45
            ->with(new ControllerReference('app.controller.myFilter:myfilterPartialAction', ['id' => 42]), 'esi')
46
            ->willReturn($mockedRenderResult = 'OK');
47
        $container->set('fragment.handler', $fragmentHandler);
48
49
        $this->assertEquals(
50
            $mockedRenderResult,
51
            $this->renderTwigTemplate('{{ content |shortcodes }}', ['content' => '[myShortcode id=42]'])
52
        );        
53
    }
54
55
    /** @test */
56 View Code Duplication
    public function paragraphs_wrapping_shortcodes_get_removed()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style Naming introduced by
The method paragraphs_wrapping_shortcodes_get_removed is not named in camelCase.

This check marks method names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style introduced by
Method name "ShortcodeFacadeTest::paragraphs_wrapping_shortcodes_get_removed" is not in camel caps format
Loading history...
57
    {
58
        static::$shortcodesToRegister = [
59
            [
60
                'controller' => 'app.controller.myFilter:myfilterPartialAction',
61
                'renderer' => 'esi',
62
                'name' => 'myShortcode',
63
            ]
64
        ];
65
        static::bootKernel();
66
67
        // Replace fragment renderer in test kernel, as we only want to assert it is called with the correct parameters,
68
        // but not it's result.
69
        $container = static::$kernel->getContainer();
70
        $fragmentHandler = $this->getMockBuilder(FragmentHandler::class)->disableOriginalConstructor()->getMock();
71
        $fragmentHandler->expects($this->once())
72
            ->method('render')
73
            ->with(new ControllerReference('app.controller.myFilter:myfilterPartialAction', ['id' => 42]), 'esi')
74
            ->willReturn($mockedRenderResult = 'OK');
75
        $container->set('fragment.handler', $fragmentHandler);
76
77
        $this->assertEquals(
78
            $mockedRenderResult,
79
            $this->renderTwigTemplate('{{ content |shortcodes }}', ['content' => '<p> [myShortcode id=42] </p>'])
80
        );
81
    }
82
83
    /** @test */
84
    public function content_without_shortcodes_wont_be_changed()
0 ignored issues
show
Coding Style Naming introduced by
The method content_without_shortcodes_wont_be_changed is not named in camelCase.

This check marks method names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style introduced by
Method name "ShortcodeFacadeTest::content_without_shortcodes_wont_be_changed" is not in camel caps format
Loading history...
85
    {
86
        static::bootKernel();
87
88
        $this->assertEquals(
89
            '<p>Content without shortcode</p>',
90
            $this->renderTwigTemplate('{{ \'<p>Content without shortcode</p>\' | shortcodes }}', [])
91
        );
92
    }
93
94
    /**
95
     * @param string $templateCode
96
     * @param array $context
97
     * @return string
98
     */
99
    protected function renderTwigTemplate($templateCode, array $context)
100
    {
101
        /** @var $container ContainerInterface */
102
        $container = static::$kernel->getContainer();
103
104
        /** @var \Twig_Environment $twig */
105
        $twig = $container->get('twig');
106
        $template = $twig->createTemplate($templateCode);
107
108
        return $template->render($context);
109
    }
110
}
111