Passed
Push — master ( b89ee9...82ea21 )
by Sebastian
03:18
created

EditorTest::__testConfigureFileExtend()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 14
c 1
b 0
f 1
dl 0
loc 17
rs 9.7998
cc 1
nc 1
nop 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A EditorTest::testMissingHook() 0 11 1
1
<?php
2
3
/**
4
 * This file is part of CaptainHook
5
 *
6
 * (c) Sebastian Feldmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace CaptainHook\App\Runner\Config;
13
14
use CaptainHook\App\Config\Mockery as ConfigMockery;
15
use CaptainHook\App\Console\IO\Mockery as IOMockery;
16
use CaptainHook\App\Mockery as CHMockery;
17
use Exception;
18
use org\bovigo\vfs\vfsStream;
19
use PHPUnit\Framework\TestCase;
1 ignored issue
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
21
class EditorTest extends TestCase
22
{
23
    use ConfigMockery;
24
    use IOMockery;
25
    use CHMockery;
26
27
    /**
28
     * Tests Editor::run
29
     *
30
     * @throws \Exception
31
     */
32
    public function testInvalidHook(): void
33
    {
34
        $this->expectException(Exception::class);
35
36
        $io     = $this->createIOMock();
37
        $config = $this->createConfigMock();
38
39
        $runner = new Editor($io, $config);
40
        $runner->setHook('foo')
41
               ->setChange('EnableHook')
42
               ->run();
43
    }
44
45
    /**
46
     * Tests Editor::run
47
     */
48
    public function testNoHook(): void
49
    {
50
        $this->expectException(Exception::class);
51
52
        $io     = $this->createIOMock();
53
        $config = $this->createConfigMock();
54
        $config->expects($this->once())->method('isLoadedFromFile')->willReturn(true);
1 ignored issue
show
Bug introduced by
The method expects() does not exist on CaptainHook\App\Config. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
        $config->/** @scrutinizer ignore-call */ 
55
                 expects($this->once())->method('isLoadedFromFile')->willReturn(true);

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...
55
56
        $runner = new Editor($io, $config);
57
        $runner->setChange('EnableHook')
58
               ->run();
59
    }
60
61
    /**
62
     * Tests Editor::run
63
     *
64
     * @throws \Exception
65
     */
66
    public function testNoChange(): void
67
    {
68
        $this->expectException(Exception::class);
69
70
        $io     = $this->createIOMock();
71
        $config = $this->createConfigMock();
72
        $config->expects($this->once())->method('isLoadedFromFile')->willReturn(true);
73
74
        $runner = new Editor($io, $config);
75
        $runner->setHook('pre-commit')
76
               ->run();
77
    }
78
79
    /**
80
     * Tests Editor::run
81
     *
82
     * @throws \Exception
83
     */
84
    public function testInvalidChange(): void
85
    {
86
        $this->expectException(Exception::class);
87
        $this->expectExceptionMessage('Invalid change requested');
88
89
        $io     = $this->createIOMock();
90
        $config = $this->createConfigMock(true);
91
92
        $runner = new Editor($io, $config);
93
        $runner->setChange('InvalidChange')
94
               ->setHook('pre-commit')
95
               ->run();
96
    }
97
98
    /**
99
     * Tests Editor::run
100
     *
101
     * @throws \Exception
102
     */
103
    public function testMissingHook(): void
104
    {
105
        $this->expectException(Exception::class);
106
        $this->expectExceptionMessage('No hook set');
107
108
        $io     = $this->createIOMock();
109
        $config = $this->createConfigMock(true);
110
111
        $runner = new Editor($io, $config);
112
        $runner->setChange('EnableHook')
113
               ->run();
114
    }
115
116
    /**
117
     * Tests Editor::run
118
     *
119
     * @throws \Exception
120
     */
121
    public function testMissingChange(): void
122
    {
123
        $this->expectException(Exception::class);
124
        $this->expectExceptionMessage('No change set');
125
126
        $io     = $this->createIOMock();
127
        $config = $this->createConfigMock(true);
128
129
        $runner = new Editor($io, $config);
130
        $runner->setHook('pre-commit')
131
               ->run();
132
    }
133
134
    /**
135
     * Tests Editor::run
136
     *
137
     * @throws \Exception
138
     */
139
    public function testNoConfiguration()
140
    {
141
        $this->expectException(Exception::class);
142
143
        $io     = $this->createIOMock();
144
        $config = $this->createConfigMock();
145
        $config->expects($this->once())->method('isLoadedFromFile')->willReturn(false);
146
147
        $runner = new Editor($io, $config);
148
        $runner->setChange('AddAction')
149
               ->setHook('pre-commit')
150
               ->run();
151
    }
152
153
    /**
154
     * Tests Editor::run
155
     */
156
    public function testConfigureFileExtend()
157
    {
158
        $configDir = vfsStream::setup('root', null, ['captainhook.json' => '{}']);
159
160
        $io     = $this->createIOMock();
161
        $config = $this->createConfigMock(true, $configDir->url() . '/captainhook.json');
162
        $config->method('getHookConfig')->willReturn($this->createHookConfigMock());
1 ignored issue
show
Bug introduced by
The method method() does not exist on CaptainHook\App\Config. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

162
        $config->/** @scrutinizer ignore-call */ 
163
                 method('getHookConfig')->willReturn($this->createHookConfigMock());

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...
163
        $io->method('ask')->will($this->onConsecutiveCalls('y', 'y', '\\Foo\\Bar', 'y', 'n'));
1 ignored issue
show
Bug introduced by
The method method() does not exist on CaptainHook\App\Console\IO. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

163
        $io->/** @scrutinizer ignore-call */ 
164
             method('ask')->will($this->onConsecutiveCalls('y', 'y', '\\Foo\\Bar', 'y', 'n'));

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...
164
        $io->expects($this->once())->method('askAndValidate')->willReturn('foo:bar');
1 ignored issue
show
Bug introduced by
The method expects() does not exist on CaptainHook\App\Console\IO. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

164
        $io->/** @scrutinizer ignore-call */ 
165
             expects($this->once())->method('askAndValidate')->willReturn('foo:bar');

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...
165
166
        $runner = new Creator($io, $config);
167
        $runner->extend(true)
168
               ->advanced(true)
169
               ->run();
170
171
        $this->assertFileExists($configDir->url() . '/captainhook.json');
172
    }
173
}
174