Passed
Push — master ( 0dd639...f7347f )
by Sebastian
07:18
created

Mockery::createResolverMock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 10
rs 10
cc 1
nc 1
nop 2
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;
13
14
use CaptainHook\App\Console\Runtime\Resolver;
15
use SebastianFeldmann\Git\Operator\Diff;
16
use SebastianFeldmann\Git\Operator\Index;
17
use SebastianFeldmann\Git\Operator\Info;
18
use SebastianFeldmann\Git\Repository;
19
20
trait Mockery
21
{
22
    /**
23
     * Create resolver mock
24
     *
25
     * @param  string $executable
26
     * @param  bool   $isPhar
27
     * @return \CaptainHook\App\Console\Runtime\Resolver&\PHPUnit\Framework\MockObject\MockObject
28
     */
29
    public function createResolverMock(string $executable = 'vendor/bin/captainhook', bool $isPhar = false): Resolver
30
    {
31
        $repo = $this->getMockBuilder(Resolver::class)
32
                     ->disableOriginalConstructor()
33
                     ->getMock();
34
35
        $repo->method('getExecutable')->willReturn($executable);
36
        $repo->method('isPharRelease')->willReturn($isPhar);
37
38
        return $repo;
39
    }
40
41
    /**
42
     * Create repository mock
43
     *
44
     * @param  string $root
45
     * @return \SebastianFeldmann\Git\Repository&\PHPUnit\Framework\MockObject\MockObject
46
     */
47
    public function createRepositoryMock(string $root = ''): Repository
48
    {
49
        $repo = $this->getMockBuilder(Repository::class)
50
                     ->disableOriginalConstructor()
51
                     ->getMock();
52
53
        $repo->method('getRoot')->willReturn($root);
54
        $repo->method('getHooksDir')->willReturn($root . '/.git/hooks');
55
56
        return $repo;
57
    }
58
59
    /**
60
     * Create info operator mock
61
     *
62
     * @param  string $tag
63
     * @return \SebastianFeldmann\Git\Operator\Info&\PHPUnit\Framework\MockObject\MockObject
64
     */
65
    public function createGitInfoOperator(string $tag = 'v1.0.0'): Info
66
    {
67
        $operator = $this->getMockBuilder(Info::class)
68
                         ->disableOriginalConstructor()
69
                         ->getMock();
70
71
        $operator->method('getCurrentTag')->willReturn($tag);
72
73
        return $operator;
74
    }
75
76
    /**
77
     * Create diff operator mock
78
     *
79
     * @param  array $changedFiles
80
     * @return \SebastianFeldmann\Git\Operator\Diff&\PHPUnit\Framework\MockObject\MockObject
81
     */
82
    public function createGitDiffOperator(array $changedFiles = []): Diff
83
    {
84
        $operator = $this->getMockBuilder(Diff::class)
85
                         ->disableOriginalConstructor()
86
                         ->getMock();
87
88
        $operator->method('getChangedFiles')->willReturn($changedFiles);
89
90
        return $operator;
91
    }
92
93
    /**
94
     * Create index operator mock
95
     *
96
     * @param  array $stagedFiles
97
     * @return \SebastianFeldmann\Git\Operator\Index&\PHPUnit\Framework\MockObject\MockObject
98
     */
99
    public function createGitIndexOperator(array $stagedFiles = []): Index
100
    {
101
        $operator = $this->getMockBuilder(Index::class)
102
                         ->disableOriginalConstructor()
103
                         ->getMock();
104
105
        $operator->method('getStagedFiles')->willReturn($stagedFiles);
106
107
        return $operator;
108
    }
109
110
    /**
111
     * @param  $type
112
     * @return \PHPUnit\Framework\MockObject\MockBuilder
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\MockObject\MockBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
113
     */
114
    abstract public function getMockBuilder($type);
115
}
116