InDirectoryTest::testPreCommitRestriction()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
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
    public function testPreCommitRestriction(): void
24
    {
25
        $this->assertTrue(InDirectory::getRestriction()->isApplicableFor('pre-commit'));
26
        $this->assertFalse(InDirectory::getRestriction()->isApplicableFor('pre-push'));
27
    }
28
29
    public function testStagedTrue(): void
30
    {
31
        $io    = $this->createIOMock();
32
        $repo  = $this->createRepositoryMock();
33
        $index = $this->createGitIndexOperator(['src/foo.php', 'tests/foo.php']);
34
        $repo->expects($this->once())->method('getIndexOperator')->willReturn($index);
35
36
        $condition = new InDirectory('src/');
37
        $this->assertTrue($condition->isTrue($io, $repo));
38
    }
39
40
    public function testStagedFalse(): void
41
    {
42
        $io    = $this->createIOMock();
43
        $repo  = $this->createRepositoryMock();
44
        $index = $this->createGitIndexOperator(['src/foo.php', 'src/bar.php']);
45
        $repo->expects($this->once())->method('getIndexOperator')->willReturn($index);
46
47
        $condition = new InDirectory('tests/', ['A', 'C']);
48
        $this->assertFalse($condition->isTrue($io, $repo));
49
    }
50
}
51