onKernelRequestNormallyRedirect()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 43
Code Lines 24

Duplication

Lines 43
Ratio 100 %

Importance

Changes 0
Metric Value
dl 43
loc 43
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 24
nc 1
nop 0
1
<?php
2
3
/**
4
 * Created by PhpStorm.
5
 * User: iulianp
6
 * Date: 15.10.2016
7
 * Time: 19:14.
8
 */
9
class MaintenanceSubscriberTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
10
{
11
    const MAINTENANCE_ROUTE_URI = '/maintenance';
12
    const MAINTENANCE_ROUTE = 'iulyanp_maintenance_homepage';
13
14
    const TEST_ROUTE_URI = '/test';
15
    const TEST_ROUTE = 'iulyanp_maintenance_test';
16
17
    /**
18
     * @test
19
     */
20 View Code Duplication
    public function onKernelRequestRedirectToMaintenance()
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...
21
    {
22
        $request = $this->getStub(
23
            'Symfony\Component\HttpFoundation\Request',
0 ignored issues
show
Documentation introduced by
'Symfony\\Component\\HttpFoundation\\Request' is of type string, but the function expects a object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
24
            [
25
                'getRequestUri' => self::TEST_ROUTE_URI,
26
                'get'           => self::TEST_ROUTE,
27
            ]
28
        );
29
30
        $event = $this->getStub(
31
            'Symfony\Component\HttpKernel\Event\GetResponseEvent',
0 ignored issues
show
Documentation introduced by
'Symfony\\Component\\Htt...vent\\GetResponseEvent' is of type string, but the function expects a object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
32
            [
33
                'isMasterRequest' => true,
34
                'getRequest'      => $request,
35
                'setResponse'     => new \Symfony\Component\HttpFoundation\RedirectResponse(
36
                    self::MAINTENANCE_ROUTE_URI
37
                ),
38
                'getResponse'     => new \Symfony\Component\HttpFoundation\RedirectResponse(
39
                    self::MAINTENANCE_ROUTE_URI
40
                ),
41
            ]
42
        );
43
44
        $router = $this->getStub(
45
            'Symfony\Bundle\FrameworkBundle\Routing\Router',
0 ignored issues
show
Documentation introduced by
'Symfony\\Bundle\\Framew...undle\\Routing\\Router' is of type string, but the function expects a object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
46
            [
47
                'generate' => self::MAINTENANCE_ROUTE_URI,
48
            ]
49
        );
50
51
        $subscriber = new \Iulyanp\MaintenanceBundle\EventListener\MaintenanceSubscriber(
52
            $router, [
0 ignored issues
show
Documentation introduced by
array('enabled' => true,...elf::MAINTENANCE_ROUTE) is of type array<string,boolean|str...nance_route":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
53
                'enabled'           => true,
54
                'due_date'          => (new \DateTime('+1 day'))->format('d-m-Y H:i:s'),
55
                'maintenance_route' => self::MAINTENANCE_ROUTE,
56
            ]
57
        );
58
59
        $subscriber->onKernelRequest($event);
60
61
        $this->assertEquals(self::MAINTENANCE_ROUTE_URI, $event->getResponse()->getTargetUrl());
62
        $this->assertContains(
63
            sprintf('Redirecting to <a href="%s">%s</a>', self::MAINTENANCE_ROUTE_URI, self::MAINTENANCE_ROUTE_URI),
64
            $event->getResponse()->getContent()
65
        );
66
    }
67
68
    /**
69
     * @test
70
     */
71 View Code Duplication
    public function onKernelRequestNormallyRedirect()
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...
72
    {
73
        $request = $this->getStub(
74
            'Symfony\Component\HttpFoundation\Request',
0 ignored issues
show
Documentation introduced by
'Symfony\\Component\\HttpFoundation\\Request' is of type string, but the function expects a object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
75
            [
76
                'getRequestUri' => self::TEST_ROUTE_URI,
77
                'get'           => self::TEST_ROUTE,
78
            ]
79
        );
80
81
        $event = $this->getStub(
82
            'Symfony\Component\HttpKernel\Event\GetResponseEvent',
0 ignored issues
show
Documentation introduced by
'Symfony\\Component\\Htt...vent\\GetResponseEvent' is of type string, but the function expects a object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
83
            [
84
                'isMasterRequest' => true,
85
                'getRequest'      => $request,
86
                'setResponse'     => new \Symfony\Component\HttpFoundation\RedirectResponse(self::TEST_ROUTE_URI),
87
                'getResponse'     => new \Symfony\Component\HttpFoundation\RedirectResponse(self::TEST_ROUTE_URI),
88
            ]
89
        );
90
91
        $router = $this->getStub(
92
            'Symfony\Bundle\FrameworkBundle\Routing\Router',
0 ignored issues
show
Documentation introduced by
'Symfony\\Bundle\\Framew...undle\\Routing\\Router' is of type string, but the function expects a object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
93
            [
94
                'generate' => self::MAINTENANCE_ROUTE_URI,
95
            ]
96
        );
97
98
        $subscriber = new \Iulyanp\MaintenanceBundle\EventListener\MaintenanceSubscriber(
99
            $router, [
0 ignored issues
show
Documentation introduced by
array('enabled' => false...elf::MAINTENANCE_ROUTE) is of type array<string,false|strin...nance_route":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
100
                'enabled'           => false,
101
                'due_date'          => (new \DateTime('+1 day'))->format('d-m-Y H:i:s'),
102
                'maintenance_route' => self::MAINTENANCE_ROUTE,
103
            ]
104
        );
105
106
        $subscriber->onKernelRequest($event);
107
108
        $this->assertEquals(self::TEST_ROUTE_URI, $event->getResponse()->getTargetUrl());
109
        $this->assertContains(
110
            sprintf('Redirecting to <a href="%s">%s</a>', self::TEST_ROUTE_URI, self::TEST_ROUTE_URI),
111
            $event->getResponse()->getContent()
112
        );
113
    }
114
115
    /**
116
     * @test
117
     */
118
    public function onKernelRequestRedirectToHomepageWhenMaintenanceDisabled()
119
    {
120
        $request = $this->getStub(
121
            'Symfony\Component\HttpFoundation\Request',
0 ignored issues
show
Documentation introduced by
'Symfony\\Component\\HttpFoundation\\Request' is of type string, but the function expects a object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
122
            [
123
                'getRequestUri' => self::MAINTENANCE_ROUTE_URI,
124
                'get'           => self::MAINTENANCE_ROUTE,
125
            ]
126
        );
127
128
        $event = $this->getStub(
129
            'Symfony\Component\HttpKernel\Event\GetResponseEvent',
0 ignored issues
show
Documentation introduced by
'Symfony\\Component\\Htt...vent\\GetResponseEvent' is of type string, but the function expects a object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
130
            [
131
                'isMasterRequest' => true,
132
                'getRequest'      => $request,
133
                'setResponse'     => new \Symfony\Component\HttpFoundation\RedirectResponse('/'),
134
                'getResponse'     => new \Symfony\Component\HttpFoundation\RedirectResponse('/'),
135
            ]
136
        );
137
138
        $router = $this->getStub(
139
            'Symfony\Bundle\FrameworkBundle\Routing\Router',
0 ignored issues
show
Documentation introduced by
'Symfony\\Bundle\\Framew...undle\\Routing\\Router' is of type string, but the function expects a object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
140
            [
141
                'generate' => self::MAINTENANCE_ROUTE_URI,
142
            ]
143
        );
144
145
        $subscriber = new \Iulyanp\MaintenanceBundle\EventListener\MaintenanceSubscriber(
146
            $router, [
0 ignored issues
show
Documentation introduced by
array('enabled' => false...elf::MAINTENANCE_ROUTE) is of type array<string,false|strin...nance_route":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
147
                'enabled'           => false,
148
                'due_date'          => (new \DateTime('-1 day'))->format('d-m-Y H:i:s'),
149
                'maintenance_route' => self::MAINTENANCE_ROUTE,
150
            ]
151
        );
152
153
        $subscriber->onKernelRequest($event);
154
155
        $this->assertEquals('/', $event->getResponse()->getTargetUrl());
156
        $this->assertContains('Redirecting to <a href="/">/</a>', $event->getResponse()->getContent());
157
    }
158
159
    /**
160
     * @param object $class
161
     * @param array  $getters
162
     *
163
     * @return PHPUnit_Framework_MockObject_MockObject
164
     */
165
    private function getStub($class, array $getters = [])
166
    {
167
        $stub = $this->getMockBuilder($class)
0 ignored issues
show
Documentation introduced by
$class is of type object, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
168
            ->disableOriginalConstructor()
169
            ->getMock();
170
171
        foreach ($getters as $method => $value) {
172
            $stub->method($method)->willReturn($value);
173
        }
174
175
        return $stub;
176
    }
177
}
178