Completed
Push — master ( 6ae0fa...363b1d )
by Sebastian
16s queued 13s
created

IsEmptyTest::testExecuteInvalidOption()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 12
rs 10
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\File\Action;
13
14
use CaptainHook\App\Config;
15
use CaptainHook\App\Console\IO\NullIO;
16
use CaptainHook\App\Hook\Message\Action\Regex;
17
use CaptainHook\App\Mockery;
18
use Exception;
19
use PHPUnit\Framework\TestCase;
20
21
class IsEmptyTest extends TestCase
22
{
23
    use Mockery;
24
25
    /**
26
     * Tests IsEmpty::execute
27
     *
28
     * @throws \Exception
29
     */
30
    public function testInvalidConfiguration(): void
31
    {
32
        $this->expectException(Exception::class);
33
        $this->expectExceptionMessage('Missing option "files" for IsEmpty action');
34
35
        $io     = new NullIO();
36
        $config = new Config(CH_PATH_FILES . '/captainhook.json');
37
        $action = new Config\Action(Regex::class);
38
39
        $repo = $this->createRepositoryMock();
40
        $repo->method('getIndexOperator')->willReturn($this->createGitIndexOperator(['foo.txt']));
1 ignored issue
show
Bug introduced by
The method method() 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

40
        $repo->/** @scrutinizer ignore-call */ 
41
               method('getIndexOperator')->willReturn($this->createGitIndexOperator(['foo.txt']));

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...
41
42
        $standard = new IsEmpty();
43
        $standard->execute($config, $io, $repo, $action);
44
    }
45
46
    /**
47
     * Tests RegexCheck::execute
48
     *
49
     * @throws \Exception
50
     */
51
    public function testCommitEmptyFile(): void
52
    {
53
        $io     = new NullIO();
54
        $config = new Config(CH_PATH_FILES . '/captainhook.json');
55
        $action = new Config\Action(IsEmpty::class, ['files' => [
56
            CH_PATH_FILES . '/doesNotExist.txt',
57
            CH_PATH_FILES . '/storage/empty.log',
58
        ]]);
59
60
        $stagedFiles = [CH_PATH_FILES . '/storage/empty.log'];
61
        $repo        = $this->createRepositoryMock();
62
        $repo->method('getIndexOperator')->willReturn($this->createGitIndexOperator($stagedFiles));
63
64
        $standard = new IsEmpty();
65
        $standard->execute($config, $io, $repo, $action);
66
67
        $this->assertTrue(true);
68
    }
69
70
    /**
71
     * Tests RegexCheck::execute
72
     *
73
     * @throws \Exception
74
     */
75
    public function testCommitUnwatchedEmptyFile(): void
76
    {
77
        $io     = new NullIO();
78
        $config = new Config(CH_PATH_FILES . '/captainhook.json');
79
        $action = new Config\Action(IsEmpty::class, ['files' => [
80
            CH_PATH_FILES . '/doesNotExist.txt',
81
        ]]);
82
83
        $stagedFiles = [CH_PATH_FILES . '/empty.log'];
84
        $repo        = $this->createRepositoryMock();
85
        $repo->method('getIndexOperator')->willReturn($this->createGitIndexOperator($stagedFiles));
86
87
        $standard = new IsEmpty();
88
        $standard->execute($config, $io, $repo, $action);
89
90
        $this->assertTrue(true);
91
    }
92
93
    /**
94
     * Tests RegexCheck::execute
95
     *
96
     * @throws \Exception
97
     */
98
    public function testFailCommitFileWithContents(): void
99
    {
100
        $this->expectException(Exception::class);
101
        $this->expectExceptionMessage('<error>Error: 1 non-empty file(s)</error>');
102
103
        $io     = new NullIO();
104
        $config = new Config(CH_PATH_FILES . '/captainhook.json');
105
        $action = new Config\Action(IsEmpty::class, ['files' => [
106
            CH_PATH_FILES . '/doesNotExist.txt',  // pass
107
            CH_PATH_FILES . '/storage/empty.log', // pass
108
            CH_PATH_FILES . '/storage/test.json', // fail
109
        ]]);
110
111
        $stagedFiles = [CH_PATH_FILES . '/storage/empty.log', CH_PATH_FILES . '/storage/test.json'];
112
        $repo        = $this->createRepositoryMock();
113
        $repo->method('getIndexOperator')->willReturn($this->createGitIndexOperator($stagedFiles));
114
115
        $standard = new IsEmpty();
116
        $standard->execute($config, $io, $repo, $action);
117
    }
118
}
119