Passed
Pull Request — master (#69)
by Stephan
01:59
created

AnyTest::testWithWildcardIsTrue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 11
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 0
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\FileChanged;
13
14
use CaptainHook\App\Console\IO\Mockery as IOMockery;
15
use CaptainHook\App\Mockery as CHMockery;
16
use PHPUnit\Framework\TestCase;
17
18
/**
19
 * Class All
20
 *
21
 * The FileChange condition is applicable for `post-merge` and `post-checkout` hooks.
22
 * It makes sure all configured files are updated before executing the action.
23
 *
24
 * @package CaptainHook
25
 * @author  Sebastian Feldmann <[email protected]>
26
 * @link    https://github.com/captainhookphp/captainhook
27
 * @since   Class available since Release 4.2.0
28
 */
29
class AnyTest extends TestCase
30
{
31
    use IOMockery;
32
    use CHMockery;
33
34
    /**
35
     * Tests Any::isTrue
36
     */
37
    public function testIsTrue(): void
38
    {
39
        $io = $this->createIOMock();
40
        $io->expects($this->exactly(2))->method('getArgument')->willReturn('');
41
        $operator   = $this->createGitDiffOperator(['fiz.php', 'baz.php', 'foo.php']);
42
        $repository = $this->createRepositoryMock('');
43
        $repository->expects($this->once())->method('getDiffOperator')->willReturn($operator);
44
45
        $fileChange = new Any(['foo.php', 'bar.php']);
46
47
        $this->assertTrue($fileChange->isTrue($io, $repository));
48
    }
49
50
    /**
51
     * Tests Any::isTrue
52
     */
53
    public function testWithWildcardIsTrue(): void
54
    {
55
        $io = $this->createIOMock();
56
        $io->expects($this->exactly(2))->method('getArgument')->willReturn('');
57
        $operator   = $this->createGitDiffOperator(['fiz.php', 'baz.php', 'foo.php']);
58
        $repository = $this->createRepositoryMock('');
59
        $repository->expects($this->once())->method('getDiffOperator')->willReturn($operator);
60
61
        $fileChange = new Any(['foo.*', 'bar.php']);
62
63
        $this->assertTrue($fileChange->isTrue($io, $repository));
64
    }
65
66
    /**
67
     * Tests Any::isTrue
68
     */
69
    public function testIsFalse(): void
70
    {
71
        $io = $this->createIOMock();
72
        $io->expects($this->exactly(2))->method('getArgument')->willReturn('');
73
        $operator   = $this->createGitDiffOperator(['fiz.php', 'baz.php']);
74
        $repository = $this->createRepositoryMock('');
75
        $repository->expects($this->once())->method('getDiffOperator')->willReturn($operator);
76
77
        $fileChange = new Any(['foo.php', 'bar.php']);
78
79
        $this->assertFalse($fileChange->isTrue($io, $repository));
80
    }
81
82
    /**
83
     * Tests Any::isTrue
84
     */
85
    public function testWithWildcardIsFalse(): void
86
    {
87
        $io = $this->createIOMock();
88
        $io->expects($this->exactly(2))->method('getArgument')->willReturn('');
89
        $operator   = $this->createGitDiffOperator(['fiz.php', 'baz.php']);
90
        $repository = $this->createRepositoryMock('');
91
        $repository->expects($this->once())->method('getDiffOperator')->willReturn($operator);
92
93
        $fileChange = new Any(['fo?.php', 'bar.*']);
94
95
        $this->assertFalse($fileChange->isTrue($io, $repository));
96
    }
97
}
98