LintingTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 23
c 0
b 0
f 0
dl 0
loc 46
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testExecuteInvalidPHP() 0 16 1
A testExecuteValidPHP() 0 14 1
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