Passed
Push — master ( 7bee4d...457c92 )
by Sebastian
01:54
created

ConditionTest::testClassNotFound()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of CaptainHook.
4
 *
5
 * (c) Sebastian Feldmann <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace CaptainHook\App\Runner;
11
12
use CaptainHook\App\Hook\Condition\FileChanged\Any;
13
use PHPUnit\Framework\TestCase;
14
use CaptainHook\App\Config;
15
use CaptainHook\App\Console\IO\Mockery as IOMockery;
16
use CaptainHook\App\Mockery as CHMockery;
17
18
class ConditionTest extends TestCase
19
{
20
    use IOMockery;
21
    use CHMockery;
22
23
    /**
24
     * Tests Condition::doesConditionApply
25
     */
26
    public function testDoesConditionApply(): void
27
    {
28
        $io = $this->createIOMock();
29
        $io->expects($this->exactly(2))->method('getArgument')->willReturn('');
1 ignored issue
show
Bug introduced by
The method expects() does not exist on CaptainHook\App\Console\IO. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
        $io->/** @scrutinizer ignore-call */ 
30
             expects($this->exactly(2))->method('getArgument')->willReturn('');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
30
31
        $operator   = $this->createGitDiffOperator(['fiz.php', 'baz.php', 'foo.php']);
32
        $repository = $this->createRepositoryMock('');
33
        $repository->expects($this->once())->method('getDiffOperator')->willReturn($operator);
1 ignored issue
show
Bug introduced by
The method expects() does not exist on SebastianFeldmann\Git\Repository. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
        $repository->/** @scrutinizer ignore-call */ 
34
                     expects($this->once())->method('getDiffOperator')->willReturn($operator);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
34
35
        $conditionConfig = new Config\Condition(
36
            '\\' . Any::class,
37
            [
38
                ['foo.php', 'bar.php']
39
            ]
40
        );
41
42
        $runner = new Condition($io, $repository);
43
        $this->assertTrue($runner->doesConditionApply($conditionConfig));
44
    }
45
46
    /**
47
     * Test Condition::doesConditionApply
48
     */
49
    public function testClassNotFound(): void
50
    {
51
        $this->expectException(\Exception::class);
52
53
        $conditionConfig = new Config\Condition('\\NotFoundForSure', []);
54
55
        $runner = new Condition($this->createIOMock(), $this->createRepositoryMock());
56
        $runner->doesConditionApply($conditionConfig);
57
    }
58
59
    /**
60
     * Test Condition::doesConditionApply
61
     */
62
    public function testDoesConditionApplyCli(): void
63
    {
64
        if (\defined('PHP_WINDOWS_VERSION_MAJOR')) {
65
            $this->markTestSkipped('not tested on windows');
66
        }
67
68
        $io         = $this->createIOMock();
69
        $repository = $this->createRepositoryMock('');
70
71
        $conditionConfig = new Config\Condition(CH_PATH_FILES . '/bin/phpunit');
72
73
        $runner = new Condition($io, $repository);
74
        $this->assertTrue($runner->doesConditionApply($conditionConfig));
75
    }
76
}
77