1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of CaptainHook. |
4
|
|
|
* |
5
|
|
|
* (c) Sebastian Feldmann <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace CaptainHook\App\Runner; |
11
|
|
|
|
12
|
|
|
use CaptainHook\App\Hook\Condition\FileChanged\Any; |
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
use CaptainHook\App\Config; |
15
|
|
|
use CaptainHook\App\Console\IO\Mockery as IOMockery; |
16
|
|
|
use CaptainHook\App\Mockery as CHMockery; |
17
|
|
|
|
18
|
|
|
class ConditionTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
use IOMockery; |
21
|
|
|
use CHMockery; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Tests Condition::doesConditionApply |
25
|
|
|
*/ |
26
|
|
|
public function testDoesConditionApply(): void |
27
|
|
|
{ |
28
|
|
|
$io = $this->createIOMock(); |
29
|
|
|
$io->expects($this->exactly(2))->method('getArgument')->willReturn(''); |
|
|
|
|
30
|
|
|
|
31
|
|
|
$operator = $this->createGitDiffOperator(['fiz.php', 'baz.php', 'foo.php']); |
32
|
|
|
$repository = $this->createRepositoryMock(''); |
33
|
|
|
$repository->expects($this->once())->method('getDiffOperator')->willReturn($operator); |
|
|
|
|
34
|
|
|
|
35
|
|
|
$conditionConfig = new Config\Condition( |
36
|
|
|
'\\' . Any::class, |
37
|
|
|
[ |
38
|
|
|
['foo.php', 'bar.php'] |
39
|
|
|
] |
40
|
|
|
); |
41
|
|
|
|
42
|
|
|
$runner = new Condition($io, $repository); |
43
|
|
|
$this->assertTrue($runner->doesConditionApply($conditionConfig)); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Test Condition::doesConditionApply |
48
|
|
|
*/ |
49
|
|
|
public function testClassNotFound(): void |
50
|
|
|
{ |
51
|
|
|
$this->expectException(\Exception::class); |
52
|
|
|
|
53
|
|
|
$conditionConfig = new Config\Condition('\\NotFoundForSure', []); |
54
|
|
|
|
55
|
|
|
$runner = new Condition($this->createIOMock(), $this->createRepositoryMock()); |
56
|
|
|
$runner->doesConditionApply($conditionConfig); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Test Condition::doesConditionApply |
61
|
|
|
*/ |
62
|
|
|
public function testDoesConditionApplyCli(): void |
63
|
|
|
{ |
64
|
|
|
if (\defined('PHP_WINDOWS_VERSION_MAJOR')) { |
65
|
|
|
$this->markTestSkipped('not tested on windows'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$io = $this->createIOMock(); |
69
|
|
|
$repository = $this->createRepositoryMock(''); |
70
|
|
|
|
71
|
|
|
$conditionConfig = new Config\Condition(CH_PATH_FILES . '/bin/phpunit'); |
72
|
|
|
|
73
|
|
|
$runner = new Condition($io, $repository); |
74
|
|
|
$this->assertTrue($runner->doesConditionApply($conditionConfig)); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
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.