|
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\File\Action; |
|
13
|
|
|
|
|
14
|
|
|
use CaptainHook\App\Config; |
|
15
|
|
|
use CaptainHook\App\Console\IO\NullIO; |
|
16
|
|
|
use CaptainHook\App\Mockery; |
|
17
|
|
|
use Exception; |
|
18
|
|
|
use PHPUnit\Framework\TestCase; |
|
19
|
|
|
|
|
20
|
|
|
class IsEmptyTest extends TestCase |
|
21
|
|
|
{ |
|
22
|
|
|
use Mockery; |
|
23
|
|
|
|
|
24
|
|
|
public function testInvalidConfiguration(): void |
|
25
|
|
|
{ |
|
26
|
|
|
$this->expectException(Exception::class); |
|
27
|
|
|
$this->expectExceptionMessage('Missing option "files" for IsEmpty action'); |
|
28
|
|
|
|
|
29
|
|
|
$io = new NullIO(); |
|
30
|
|
|
$config = new Config(CH_PATH_FILES . '/captainhook.json'); |
|
31
|
|
|
$action = new Config\Action(IsEmpty::class); |
|
32
|
|
|
|
|
33
|
|
|
$repo = $this->createRepositoryMock(); |
|
34
|
|
|
$repo->method('getIndexOperator')->willReturn($this->createGitIndexOperator(['foo.txt'])); |
|
35
|
|
|
|
|
36
|
|
|
$standard = new IsEmpty(); |
|
37
|
|
|
$standard->execute($config, $io, $repo, $action); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testCommitEmptyFile(): void |
|
41
|
|
|
{ |
|
42
|
|
|
$io = new NullIO(); |
|
43
|
|
|
$config = new Config(CH_PATH_FILES . '/captainhook.json'); |
|
44
|
|
|
$action = new Config\Action(IsEmpty::class, ['files' => [ |
|
45
|
|
|
CH_PATH_FILES . '/doesNotExist.txt', |
|
46
|
|
|
CH_PATH_FILES . '/storage/empty.log', |
|
47
|
|
|
]]); |
|
48
|
|
|
|
|
49
|
|
|
$stagedFiles = [CH_PATH_FILES . '/storage/empty.log']; |
|
50
|
|
|
$repo = $this->createRepositoryMock(); |
|
51
|
|
|
$repo->method('getIndexOperator')->willReturn($this->createGitIndexOperator($stagedFiles)); |
|
52
|
|
|
|
|
53
|
|
|
$standard = new IsEmpty(); |
|
54
|
|
|
$standard->execute($config, $io, $repo, $action); |
|
55
|
|
|
|
|
56
|
|
|
$this->assertTrue(true); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testCommitUnwatchedEmptyFile(): void |
|
60
|
|
|
{ |
|
61
|
|
|
$io = new NullIO(); |
|
62
|
|
|
$config = new Config(CH_PATH_FILES . '/captainhook.json'); |
|
63
|
|
|
$action = new Config\Action(IsEmpty::class, ['files' => [ |
|
64
|
|
|
CH_PATH_FILES . '/doesNotExist.txt', |
|
65
|
|
|
]]); |
|
66
|
|
|
|
|
67
|
|
|
$stagedFiles = [CH_PATH_FILES . '/empty.log']; |
|
68
|
|
|
$repo = $this->createRepositoryMock(); |
|
69
|
|
|
$repo->method('getIndexOperator')->willReturn($this->createGitIndexOperator($stagedFiles)); |
|
70
|
|
|
|
|
71
|
|
|
$standard = new IsEmpty(); |
|
72
|
|
|
$standard->execute($config, $io, $repo, $action); |
|
73
|
|
|
|
|
74
|
|
|
$this->assertTrue(true); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function testFailCommitFileWithContents(): void |
|
78
|
|
|
{ |
|
79
|
|
|
$this->expectException(Exception::class); |
|
80
|
|
|
|
|
81
|
|
|
$io = new NullIO(); |
|
82
|
|
|
$config = new Config(CH_PATH_FILES . '/captainhook.json'); |
|
83
|
|
|
$action = new Config\Action(IsEmpty::class, ['files' => [ |
|
84
|
|
|
CH_PATH_FILES . '/doesNotExist.txt', // pass |
|
85
|
|
|
CH_PATH_FILES . '/storage/empty.log', // pass |
|
86
|
|
|
CH_PATH_FILES . '/storage/test.json', // fail |
|
87
|
|
|
]]); |
|
88
|
|
|
|
|
89
|
|
|
$stagedFiles = [CH_PATH_FILES . '/storage/empty.log', CH_PATH_FILES . '/storage/test.json']; |
|
90
|
|
|
$repo = $this->createRepositoryMock(); |
|
91
|
|
|
$repo->method('getIndexOperator')->willReturn($this->createGitIndexOperator($stagedFiles)); |
|
92
|
|
|
|
|
93
|
|
|
$standard = new IsEmpty(); |
|
94
|
|
|
$standard->execute($config, $io, $repo, $action); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|