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\Setup; |
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 PHPUnit\Framework\TestCase; |
18
|
|
|
|
19
|
|
|
class AdvancedTest extends TestCase |
20
|
|
|
{ |
21
|
|
|
use ConfigMockery; |
22
|
|
|
use IOMockery; |
23
|
|
|
use CHMockery; |
24
|
|
|
|
25
|
|
|
public function testConfigureCliHook(): void |
26
|
|
|
{ |
27
|
|
|
$invocations = $this->atLeast(3); |
28
|
|
|
$io = $this->createIOMock(); |
29
|
|
|
$config = $this->createConfigMock(); |
30
|
|
|
$config->expects($this->exactly(9))->method('getHookConfig')->willReturn($this->createHookConfigMock()); |
31
|
|
|
$io->expects($invocations) |
32
|
|
|
->method('ask') |
33
|
|
|
->willReturnCallback(function ($parameters) use ($invocations) { |
|
|
|
|
34
|
|
|
$results = ['y', 'y', 'echo \'foo\'', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n']; |
35
|
|
|
return $results[$invocations->numberOfInvocations() - 1] ?? ''; |
36
|
|
|
}); |
37
|
|
|
|
38
|
|
|
$setup = new Advanced($io); |
39
|
|
|
$setup->configureHooks($config); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testConfigurePHPHook(): void |
43
|
|
|
{ |
44
|
|
|
$invocations = $this->atLeast(3); |
45
|
|
|
$io = $this->createIOMock(); |
46
|
|
|
$config = $this->createConfigMock(); |
47
|
|
|
$config->method('getHookConfig')->willReturn($this->createHookConfigMock()); |
48
|
|
|
$io->expects($invocations) |
49
|
|
|
->method('ask') |
50
|
|
|
->willReturnCallback(function ($parameters) use ($invocations) { |
|
|
|
|
51
|
|
|
$results = ['y', 'y', '\\Foo\\Bar', 'y', 'foo:bar', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n']; |
52
|
|
|
return $results[$invocations->numberOfInvocations() - 1] ?? ''; |
53
|
|
|
}); |
54
|
|
|
|
55
|
|
|
$io->expects($this->once())->method('askAndValidate')->willReturn('foo:bar'); |
56
|
|
|
|
57
|
|
|
$setup = new Advanced($io); |
58
|
|
|
$setup->configureHooks($config); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.