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.

ShortcodeCompilerPassTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Webfactory\ShortcodeBundle\Tests\DependencyInjection\Compiler;
4
5
use PHPUnit\Framework\MockObject\MockObject;
6
use PHPUnit\Framework\TestCase;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Definition;
9
use Symfony\Component\DependencyInjection\Reference;
10
use Thunder\Shortcode\HandlerContainer\HandlerContainer;
11
use Webfactory\ShortcodeBundle\Controller\GuideController;
12
use Webfactory\ShortcodeBundle\DependencyInjection\Compiler\ShortcodeCompilerPass;
13
14
final class ShortcodeCompilerPassTest extends TestCase
15
{
16
    /**
17
     * System under test.
18
     *
19
     * @var ShortcodeCompilerPass
20
     */
21
    private $compilerPass;
22
23
    /** @var ContainerBuilder|MockObject */
24
    private $containerBuilder;
25
26
    protected function setUp(): void
27
    {
28
        $this->compilerPass = new ShortcodeCompilerPass();
29
        $this->containerBuilder = $this->getMockBuilder(ContainerBuilder::class)
30
            ->disableOriginalConstructor()
31
            ->getMock();
32
    }
33
34
    /** @test */
35
    public function tagged_services_are_added_as_handlers_to_handler_container(): void
36
    {
37
        $this->containerBuilder->expects($this->once())
38
            ->method('findTaggedServiceIds')
39
            ->willReturn([
40
                'service_id1' => [
41
                    ['shortcode' => 'shortcode1'],
42
                ],
43
                'service_id2' => [
44
                    ['shortcode' => 'shortcode2'],
45
                ],
46
            ]);
47
48
        $mockedShortcodeHandlerContainer = $this->createMock(Definition::class);
49
        $mockedShortcodeHandlerContainer->expects($this->exactly(2))
50
            ->method('addMethodCall')
51
            ->with('add', $this->callback(function (array $argument) {
52
                static $count = 0;
53
                ++$count;
54
55
                return 'shortcode'.$count === $argument[0] && $argument[1] instanceof Reference;
56
            }));
57
58
        $this->containerBuilder->expects($this->once())
59
            ->method('findDefinition')
60
            ->with(HandlerContainer::class)
61
            ->willReturn($mockedShortcodeHandlerContainer);
62
63
        $this->compilerPass->process($this->containerBuilder);
64
    }
65
66
    /** @test */
67
    public function no_tagged_services_do_no_harm(): void
68
    {
69
        $this->containerBuilder->expects($this->once())
70
            ->method('findTaggedServiceIds')
71
            ->willReturn([]);
72
73
        $this->compilerPass->process($this->containerBuilder);
74
    }
75
76
    /** @test */
77
    public function shortcode_guide_service_gets_configured_if_set(): void
78
    {
79
        $this->containerBuilder->expects($this->once())
80
            ->method('findTaggedServiceIds')
81
            ->willReturn([
82
                'service_id1' => [
83
                    ['shortcode' => 'shortcode1'],
84
                ],
85
                'service_id2' => [
86
                    ['shortcode' => 'shortcode2'],
87
                ],
88
            ]);
89
90
        $this->containerBuilder->expects($this->once())
91
            ->method('findDefinition')
92
            ->with(HandlerContainer::class)
93
            ->willReturn($this->createMock(Definition::class));
94
95
        $this->containerBuilder->expects($this->once())
96
            ->method('has')
97
            ->with(GuideController::class)
98
            ->willReturn(true);
99
100
        $mockedShortcodeGuideServiceDefinition = $this->createMock(Definition::class);
101
        $mockedShortcodeGuideServiceDefinition->expects($this->once())
102
            ->method('setArgument')
103
            ->with(
104
                0,
105
                [
106
                    ['shortcode' => 'shortcode1'],
107
                    ['shortcode' => 'shortcode2'],
108
                ]
109
            );
110
111
        $this->containerBuilder->expects($this->once())
112
            ->method('getDefinition')
113
            ->with(GuideController::class)
114
            ->willReturn($mockedShortcodeGuideServiceDefinition);
115
116
        $this->compilerPass->process($this->containerBuilder);
117
    }
118
119
    /** @test */
120
    public function missing_shortcode_guide_service_does_no_harm(): void
121
    {
122
        $this->containerBuilder->expects($this->once())
123
            ->method('findTaggedServiceIds')
124
            ->willReturn([]);
125
126
        $this->containerBuilder->expects($this->once())
127
            ->method('has')
128
            ->with(GuideController::class)
129
            ->willReturn(false);
130
131
        $this->compilerPass->process($this->containerBuilder);
132
    }
133
}
134