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\Hook; |
11
|
|
|
|
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
use RuntimeException; |
14
|
|
|
|
15
|
|
|
class UtilTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Tests Util::isValid |
19
|
|
|
*/ |
20
|
|
|
public function testIsValid(): void |
21
|
|
|
{ |
22
|
|
|
$this->assertTrue(Util::isValid('pre-commit')); |
23
|
|
|
$this->assertTrue(Util::isValid('pre-push')); |
24
|
|
|
$this->assertTrue(Util::isValid('commit-msg')); |
25
|
|
|
$this->assertFalse(Util::isValid('foo')); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Tests Util::getValidHooks |
30
|
|
|
*/ |
31
|
|
|
public function testGetValidHooks(): void |
32
|
|
|
{ |
33
|
|
|
$this->assertArrayHasKey('pre-commit', Util::getValidHooks()); |
34
|
|
|
$this->assertArrayHasKey('pre-push', Util::getValidHooks()); |
35
|
|
|
$this->assertArrayHasKey('commit-msg', Util::getValidHooks()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Tests Util::getHookCommand |
40
|
|
|
* |
41
|
|
|
* @dataProvider providerValidCommands |
42
|
|
|
* |
43
|
|
|
* @param string $class |
44
|
|
|
* @param string $hook |
45
|
|
|
*/ |
46
|
|
|
public function testGetHookCommandValid(string $class, string $hook): void |
47
|
|
|
{ |
48
|
|
|
$this->assertEquals($class, Util::getHookCommand($hook)); |
49
|
|
|
$this->assertEquals('PreCommit', Util::getHookCommand('pre-commit')); |
50
|
|
|
$this->assertEquals('PrepareCommitMsg', Util::getHookCommand('prepare-commit-msg')); |
51
|
|
|
$this->assertEquals('PrePush', Util::getHookCommand('pre-push')); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
|
|
public function providerValidCommands(): array |
58
|
|
|
{ |
59
|
|
|
return [ |
60
|
|
|
['CommitMsg', 'commit-msg'], |
61
|
|
|
['PreCommit', 'pre-commit'], |
62
|
|
|
['PrepareCommitMsg', 'prepare-commit-msg'], |
63
|
|
|
['PrePush', 'pre-push'], |
64
|
|
|
]; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Tests Util::getHookCommand |
69
|
|
|
* |
70
|
|
|
* @dataProvider providerInvalidCommands |
71
|
|
|
*/ |
72
|
|
|
public function testGetHookCommandInvalid(string $hook): void |
73
|
|
|
{ |
74
|
|
|
$this->expectException(RuntimeException::class); |
75
|
|
|
|
76
|
|
|
$this->assertEquals('', Util::getHookCommand($hook)); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return array |
81
|
|
|
*/ |
82
|
|
|
public function providerInvalidCommands(): array |
83
|
|
|
{ |
84
|
|
|
return [ |
85
|
|
|
[''], |
86
|
|
|
['foo'], |
87
|
|
|
]; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Tests Util::getHooks |
92
|
|
|
*/ |
93
|
|
|
public function testGetHooks(): void |
94
|
|
|
{ |
95
|
|
|
$this->assertContains('pre-commit', Util::getHooks()); |
96
|
|
|
$this->assertContains('pre-push', Util::getHooks()); |
97
|
|
|
$this->assertContains('commit-msg', Util::getHooks()); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|