|
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\Hook\Message\Action; |
|
13
|
|
|
|
|
14
|
|
|
use CaptainHook\App\Config; |
|
15
|
|
|
use CaptainHook\App\Console\IO\NullIO; |
|
16
|
|
|
use CaptainHook\App\Mockery; |
|
17
|
|
|
use Exception; |
|
18
|
|
|
use SebastianFeldmann\Git\CommitMessage; |
|
19
|
|
|
use PHPUnit\Framework\TestCase; |
|
20
|
|
|
|
|
21
|
|
|
class BeamsTest extends TestCase |
|
22
|
|
|
{ |
|
23
|
|
|
use Mockery; |
|
24
|
|
|
|
|
25
|
|
|
public function testConstraint(): void |
|
26
|
|
|
{ |
|
27
|
|
|
$this->assertTrue(Beams::getRestriction()->isApplicableFor('commit-msg')); |
|
28
|
|
|
$this->assertFalse(Beams::getRestriction()->isApplicableFor('pre-push')); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testExecute(): void |
|
32
|
|
|
{ |
|
33
|
|
|
$io = new NullIO(); |
|
34
|
|
|
$config = new Config(CH_PATH_FILES . '/captainhook.json'); |
|
35
|
|
|
$action = new Config\Action(Beams::class); |
|
36
|
|
|
$repo = $this->createRepositoryMock(); |
|
37
|
|
|
$repo->method('getCommitMsg')->willReturn(new CommitMessage('Foo bar baz')); |
|
38
|
|
|
|
|
39
|
|
|
$standard = new Beams(); |
|
40
|
|
|
$standard->execute($config, $io, $repo, $action); |
|
41
|
|
|
|
|
42
|
|
|
$this->assertTrue(true); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testExecuteImperativeBeginning(): void |
|
46
|
|
|
{ |
|
47
|
|
|
$this->expectException(Exception::class); |
|
48
|
|
|
|
|
49
|
|
|
$io = new NullIO(); |
|
50
|
|
|
$config = new Config(CH_PATH_FILES . '/captainhook.json'); |
|
51
|
|
|
$action = new Config\Action(Beams::class, ['checkImperativeBeginningOnly' => true]); |
|
52
|
|
|
$repo = $this->createRepositoryMock(); |
|
53
|
|
|
$repo->method('getCommitMsg')->willReturn(new CommitMessage('foo added foo bar baz.')); |
|
54
|
|
|
|
|
55
|
|
|
$standard = new Beams(); |
|
56
|
|
|
$standard->execute($config, $io, $repo, $action); |
|
57
|
|
|
|
|
58
|
|
|
$this->assertTrue(true); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testExecuteFail(): void |
|
62
|
|
|
{ |
|
63
|
|
|
$this->expectException(Exception::class); |
|
64
|
|
|
|
|
65
|
|
|
$io = new NullIO(); |
|
66
|
|
|
$config = new Config(CH_PATH_FILES . '/captainhook.json'); |
|
67
|
|
|
$action = new Config\Action(Beams::class); |
|
68
|
|
|
$repo = $this->createRepositoryMock(); |
|
69
|
|
|
$repo->method('getCommitMsg')->willReturn(new CommitMessage('added foo bar baz.')); |
|
70
|
|
|
|
|
71
|
|
|
$standard = new Beams(); |
|
72
|
|
|
$standard->execute($config, $io, $repo, $action); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|