AllTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 29
c 0
b 0
f 0
dl 0
loc 72
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testIsFalse() 0 10 1
A testWithWildcardIsFalse() 0 10 1
A testPreCommitRestriction() 0 4 1
A testWithWildcardIsTrue() 0 10 1
A testIsTrue() 0 10 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 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
    /**
24
     * Tests OfType::getRestriction
25
     */
26
    public function testPreCommitRestriction(): void
27
    {
28
        $this->assertTrue(All::getRestriction()->isApplicableFor('pre-commit'));
29
        $this->assertFalse(All::getRestriction()->isApplicableFor('pre-push'));
30
    }
31
32
    /**
33
     * Tests All::isTrue
34
     */
35
    public function testIsFalse(): void
36
    {
37
        $io         = $this->createIOMock();
38
        $operator   = $this->createGitIndexOperator(['fiz.php', 'baz.php', 'foo.php']);
39
        $repository = $this->createRepositoryMock('');
40
        $repository->expects($this->once())->method('getIndexOperator')->willReturn($operator);
41
42
        $fileStaged = new All(['foo.php', 'bar.php']);
43
44
        $this->assertFalse($fileStaged->isTrue($io, $repository));
45
    }
46
47
    /**
48
     * Tests All::isTrue
49
     */
50
    public function testWithWildcardIsFalse(): void
51
    {
52
        $io         = $this->createIOMock();
53
        $operator   = $this->createGitIndexOperator(['fiz.php', 'baz.php', 'foo.php']);
54
        $repository = $this->createRepositoryMock('');
55
        $repository->expects($this->once())->method('getIndexOperator')->willReturn($operator);
56
57
        $fileStaged = new All(['foo.*', 'bar.php']);
58
59
        $this->assertFalse($fileStaged->isTrue($io, $repository));
60
    }
61
62
    /**
63
     * Tests All::isTrue
64
     */
65
    public function testIsTrue(): 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.php', 'bar.php'], ['A', 'C']);
73
74
        $this->assertTrue($fileStaged->isTrue($io, $repository));
75
    }
76
77
    /**
78
     * Tests All::isTrue
79
     */
80
    public function testWithWildcardIsTrue(): void
81
    {
82
        $io = $this->createIOMock();
83
        $operator   = $this->createGitIndexOperator(['foo.php', 'bar.php', 'baz.php']);
84
        $repository = $this->createRepositoryMock('');
85
        $repository->expects($this->once())->method('getIndexOperator')->willReturn($operator);
86
87
        $fileStaged = new All(['foo.*', 'ba?.php']);
88
89
        $this->assertTrue($fileStaged->isTrue($io, $repository));
90
    }
91
}
92