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\PHP\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 LintingTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
use Mockery; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Tests Linter::execute |
26
|
|
|
* |
27
|
|
|
* @throws \Exception |
28
|
|
|
*/ |
29
|
|
|
public function testExecuteValidPHP(): void |
30
|
|
|
{ |
31
|
|
|
$io = new NullIO(); |
32
|
|
|
$config = new Config(CH_PATH_FILES . '/captainhook.json'); |
33
|
|
|
$repo = $this->createRepositoryMock(); |
34
|
|
|
$files = [CH_PATH_FILES . '/php/valid.txt']; |
35
|
|
|
$resolver = $this->createGitIndexOperator(); |
36
|
|
|
$resolver->expects($this->once())->method('getStagedFilesOfType')->willReturn($files); |
37
|
|
|
$repo->expects($this->once())->method('getIndexOperator')->willReturn($resolver); |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
$action = new Config\Action(Linting::class, []); |
41
|
|
|
$standard = new Linting(); |
42
|
|
|
$standard->execute($config, $io, $repo, $action); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Tests Linter::execute |
47
|
|
|
* |
48
|
|
|
* @throws \Exception |
49
|
|
|
*/ |
50
|
|
|
public function testExecuteInvalidPHP(): void |
51
|
|
|
{ |
52
|
|
|
$this->expectException(Exception::class); |
53
|
|
|
|
54
|
|
|
$io = new NullIO(); |
55
|
|
|
$config = new Config(CH_PATH_FILES . '/captainhook.json'); |
56
|
|
|
$repo = $this->createRepositoryMock(); |
57
|
|
|
$files = [CH_PATH_FILES . '/php/invalid.txt']; |
58
|
|
|
$resolver = $this->createGitIndexOperator(); |
59
|
|
|
$resolver->expects($this->once())->method('getStagedFilesOfType')->willReturn($files); |
60
|
|
|
$repo->expects($this->once())->method('getIndexOperator')->willReturn($resolver); |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
$action = new Config\Action(Linting::class, []); |
64
|
|
|
$standard = new Linting(); |
65
|
|
|
$standard->execute($config, $io, $repo, $action); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|