InDirectoryTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
c 0
b 0
f 0
dl 0
loc 40
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testStagedTrue() 0 9 1
A testPreCommitRestriction() 0 4 1
A testStagedFalse() 0 9 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\Condition\FileStaged;
13
14
use PHPUnit\Framework\TestCase;
15
use CaptainHook\App\Mockery as AppMockery;
16
use CaptainHook\App\Console\IO\Mockery as IOMockery;
17
18
class InDirectoryTest extends TestCase
19
{
20
    use AppMockery;
21
    use IOMockery;
22
23
    /**
24
     * Tests InDirectory::getRestriction
25
     */
26
    public function testPreCommitRestriction(): void
27
    {
28
        $this->assertTrue(InDirectory::getRestriction()->isApplicableFor('pre-commit'));
29
        $this->assertFalse(InDirectory::getRestriction()->isApplicableFor('pre-push'));
30
    }
31
32
    /**
33
     * Tests InDirectory::isTrue
34
     */
35
    public function testStagedTrue(): void
36
    {
37
        $io    = $this->createIOMock();
38
        $repo  = $this->createRepositoryMock();
39
        $index = $this->createGitIndexOperator(['src/foo.php', 'tests/foo.php']);
40
        $repo->expects($this->once())->method('getIndexOperator')->willReturn($index);
41
42
        $condition = new InDirectory('src/');
43
        $this->assertTrue($condition->isTrue($io, $repo));
44
    }
45
46
    /**
47
     * Tests InDirectory:isTrue
48
     */
49
    public function testStagedFalse(): void
50
    {
51
        $io    = $this->createIOMock();
52
        $repo  = $this->createRepositoryMock();
53
        $index = $this->createGitIndexOperator(['src/foo.php', 'src/bar.php']);
54
        $repo->expects($this->once())->method('getIndexOperator')->willReturn($index);
55
56
        $condition = new InDirectory('tests/', ['A', 'C']);
57
        $this->assertFalse($condition->isTrue($io, $repo));
58
    }
59
}
60