AllTest::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 CaptainHook\App\Console\IO\Mockery as IOMockery;
15
use CaptainHook\App\Mockery as CHMockery;
16
use PHPUnit\Framework\TestCase;
17
18
class AllTest extends TestCase
19
{
20
    use IOMockery;
21
    use CHMockery;
22
23
    public function testPreCommitRestriction(): void
24
    {
25
        $this->assertTrue(All::getRestriction()->isApplicableFor('pre-commit'));
26
        $this->assertFalse(All::getRestriction()->isApplicableFor('pre-push'));
27
    }
28
29
    public function testIsFalse(): void
30
    {
31
        $io         = $this->createIOMock();
32
        $operator   = $this->createGitIndexOperator(['fiz.php', 'baz.php', 'foo.php']);
33
        $repository = $this->createRepositoryMock('');
34
        $repository->expects($this->once())->method('getIndexOperator')->willReturn($operator);
35
36
        $fileStaged = new All(['foo.php', 'bar.php']);
37
38
        $this->assertFalse($fileStaged->isTrue($io, $repository));
39
    }
40
41
    public function testWithWildcardIsFalse(): void
42
    {
43
        $io         = $this->createIOMock();
44
        $operator   = $this->createGitIndexOperator(['fiz.php', 'baz.php', 'foo.php']);
45
        $repository = $this->createRepositoryMock('');
46
        $repository->expects($this->once())->method('getIndexOperator')->willReturn($operator);
47
48
        $fileStaged = new All(['foo.*', 'bar.php']);
49
50
        $this->assertFalse($fileStaged->isTrue($io, $repository));
51
    }
52
53
    public function testIsTrue(): void
54
    {
55
        $io         = $this->createIOMock();
56
        $operator   = $this->createGitIndexOperator(['foo.php', 'bar.php', 'baz.php']);
57
        $repository = $this->createRepositoryMock('');
58
        $repository->expects($this->once())->method('getIndexOperator')->willReturn($operator);
59
60
        $fileStaged = new All(['foo.php', 'bar.php'], ['A', 'C']);
61
62
        $this->assertTrue($fileStaged->isTrue($io, $repository));
63
    }
64
65
    public function testWithWildcardIsTrue(): void
66
    {
67
        $io = $this->createIOMock();
68
        $operator   = $this->createGitIndexOperator(['foo.php', 'bar.php', 'baz.php']);
69
        $repository = $this->createRepositoryMock('');
70
        $repository->expects($this->once())->method('getIndexOperator')->willReturn($operator);
71
72
        $fileStaged = new All(['foo.*', 'ba?.php']);
73
74
        $this->assertTrue($fileStaged->isTrue($io, $repository));
75
    }
76
}
77