Completed
Pull Request — master (#192)
by
unknown
01:36
created

testMultipleAddonsCanBeMarkedAsSupported()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
/**
4
 * @mixin PHPUnit_Framework_TestCase
5
 */
6
class SetSupportedAddonsTaskTest extends FunctionalTest
7
{
8
    protected static $fixture_file = 'SetSupportedAddonsTaskTest.yml';
9
10
    public function testHelpIsShownWithNoArguments()
11
    {
12
        $output = $this->runTask();
13
14
        $this->assertContains('Usage:', $output);
15
    }
16
17
    public function testAddonsAreMarkedAsSupported()
18
    {
19
        $this->assertAddonsAreNotSupported('foo/unsupported-bar-a');
20
21
        $this->runTask('foo/unsupported-bar-a');
22
23
        $this->assertAddonsAreSupported('foo/unsupported-bar-a');
24
    }
25
26
    public function testAddonsAreNotReplaced()
27
    {
28
        $this->assertAddonsAreSupported('foo/supported-bar-a');
29
30
        $this->runTask('foo/unsupported-bar-a');
31
32
        $this->assertAddonsAreSupported('foo/supported-bar-a');
33
    }
34
35
    public function testMultipleAddonsCanBeMarkedAsSupported()
36
    {
37
        $this->assertAddonsAreNotSupported(['foo/unsupported-bar-a', 'foo/unsupported-bar-b']);
38
39
        $this->runTask('foo/unsupported-bar-a,foo/unsupported-bar-b');
40
41
        $this->assertAddonsAreSupported(['foo/unsupported-bar-a', 'foo/unsupported-bar-b']);
42
    }
43
44
    public function testReplaceFlagWillReplaceSupportedAddons()
45
    {
46
        $this->assertAddonsAreSupported('foo/supported-bar-a');
47
        $this->assertAddonsAreNotSupported('foo/unsupported-bar-a');
48
49
        $this->runTask('foo/unsupported-bar-a', ['-r']);
50
51
        $this->assertAddonsAreSupported('foo/unsupported-bar-a');
52
        $this->assertAddonsAreNotSupported('foo/supported-bar-a');
53
    }
54
55
    public function testReplaceFlagWithNoAddonsWillNotDeleteEverything()
56
    {
57
        $this->assertAddonsAreSupported('foo/supported-bar-a');
58
59
        $response = $this->runTask(null, ['-r']);
60
61
        $this->assertAddonsAreSupported('foo/supported-bar-a');
62
        $this->assertContains('Use -f to force', $response);
63
    }
64
65
    public function testReplaceFlagWithNoAddonsWillDeleteEverything()
66
    {
67
        $this->assertAddonsAreSupported('foo/supported-bar-a');
68
69
        $this->runTask(null, ['-rf']);
70
71
        $this->assertAddonsAreNotSupported('foo/supported-bar-a');
72
    }
73
74 View Code Duplication
    protected function assertAddonsAreSupported($addons)
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...
75
    {
76
        $addons = (array) $addons;
77
78
        $supportedAddons = Addon::get()->filter('Supported', true)->column('Name');
79
80
        foreach ($addons as $addon) {
81
            $this->assertContains($addon, $supportedAddons, $addon . ' is not supported');
82
        }
83
    }
84
85 View Code Duplication
    protected function assertAddonsAreNotSupported($addons)
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...
86
    {
87
        $addons = (array) $addons;
88
89
        $unsupportedAddons = Addon::get()->filter('Supported', false)->column('Name');
90
91
        foreach ($addons as $addon) {
92
            $this->assertContains($addon, $unsupportedAddons, $addon . ' is supported');
93
        }
94
    }
95
96
    protected function runTask($addons = null, array $args = [])
97
    {
98
        $vars = $addons ? ['addons' => $addons] : [];
99
100
        $request = $this->getMockBuilder(SS_HTTPRequest::class)
0 ignored issues
show
Bug introduced by
The method getMockBuilder() does not seem to exist on object<SetSupportedAddonsTaskTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
101
            ->setConstructorArgs(array('GET', 'test', $vars))
102
            ->getMock();
103
104
        $request->method('getVars')->willReturn($vars);
105
        $request->method('getVar')->will($this->onConsecutiveCalls($args, $addons));
0 ignored issues
show
Bug introduced by
The method onConsecutiveCalls() does not seem to exist on object<SetSupportedAddonsTaskTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
106
107
        $task = new SetSupportedAddonsTask();
108
109
        ob_start();
110
        $task->run($request);
111
        return ob_get_clean();
112
    }
113
}
114