TestPluginTest::testSupportsControllerAndAction()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 81

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 81
rs 8.4145
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Vectorface\SnappyRouterTests\Plugin;
4
5
use PHPUnit\Framework\TestCase;
6
use Vectorface\SnappyRouter\Plugin\AbstractPlugin;
7
8
class TestPluginTest extends TestCase
9
{
10
    /**
11
     * A demonstrate of a simple test plugin.
12
     * @test
13
     */
14
    public function synopsis()
15
    {
16
        $options = array();
17
        $plugin = new TestPlugin($options);
18
19
        $this->assertEquals(
20
            AbstractPlugin::PRIORITY_DEFAULT,
21
            $plugin->getExecutionOrder()
22
        );
23
24
        $plugin->setWhitelist(
25
            array(
26
                'TestController' => AbstractPlugin::ALL_ACTIONS
27
            )
28
        );
29
        $this->assertTrue(
30
            $plugin->supportsControllerAndAction(
31
                'TestController',
32
                'someAction'
33
            )
34
        );
35
    }
36
37
    /**
38
     * Tests the supportsControllerAndAction methods.
39
     */
40
    public function testSupportsControllerAndAction()
41
    {
42
        $plugin = new TestPlugin(array());
43
44
        // no lists yet, so plugin supports everything
45
        $this->assertTrue(
46
            $plugin->supportsControllerAndAction(
47
                'TestController',
48
                'anyAction'
49
            )
50
        );
51
52
        // set a whitelist
53
        $plugin->setWhitelist(
54
            array(
55
                'TestController' => AbstractPlugin::ALL_ACTIONS,
56
                'AnotherController' => array(
57
                    'specificAction'
58
                )
59
            )
60
        );
61
        // all actions enabled for this controller
62
        $this->assertTrue(
63
            $plugin->supportsControllerAndAction(
64
                'TestController',
65
                'anyAction'
66
            )
67
        );
68
        // specific action enabled
69
        $this->assertTrue(
70
            $plugin->supportsControllerAndAction(
71
                'AnotherController',
72
                'specificAction'
73
            )
74
        );
75
        // controller is missing from whitelist
76
        $this->assertFalse(
77
            $plugin->supportsControllerAndAction(
78
                'MissingController',
79
                'anyAction'
80
            )
81
        );
82
        // action is missing from whitelist
83
        $this->assertFalse(
84
            $plugin->supportsControllerAndAction(
85
                'AnotherController',
86
                'differentAction'
87
            )
88
        );
89
90
        // now the reverse logic for the blacklist
91
        $plugin->setBlacklist(
92
            array(
93
                'TestController' => array(
94
                    'bannedAction'
95
                ),
96
                'BannedController' => AbstractPlugin::ALL_ACTIONS
97
            )
98
        );
99
        // controller is missing from blacklist
100
        $this->assertTrue(
101
            $plugin->supportsControllerAndAction(
102
                'MissingController',
103
                'anyAction'
104
            )
105
        );
106
        // action is blacklisted specifically
107
        $this->assertFalse(
108
            $plugin->supportsControllerAndAction(
109
                'TestController',
110
                'bannedAction'
111
            )
112
        );
113
        // all actions for the controller are banned
114
        $this->assertFalse(
115
            $plugin->supportsControllerAndAction(
116
                'BannedController',
117
                'anyAction'
118
            )
119
        );
120
    }
121
}
122