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\Template\Local; |
13
|
|
|
|
14
|
|
|
use CaptainHook\App\Config\Mockery as ConfigMockery; |
15
|
|
|
use CaptainHook\App\Hook\Template\PathInfo; |
16
|
|
|
use PHPUnit\Framework\TestCase; |
17
|
|
|
|
18
|
|
|
class PHPTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
use ConfigMockery; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Tests PHP::getCode |
24
|
|
|
*/ |
25
|
|
|
public function testSrcTemplate(): void |
26
|
|
|
{ |
27
|
|
|
$pathInfo = $this->createMock(PathInfo::class); |
28
|
|
|
$pathInfo->method('getExecutablePath')->willReturn('./vendor/bin/captainhook'); |
29
|
|
|
$pathInfo->method('getConfigPath')->willReturn('captainhook.json'); |
30
|
|
|
|
31
|
|
|
$config = $this->createConfigMock(false, 'captainhook.json'); |
32
|
|
|
$config->method('getBootstrap')->willReturn('vendor/autoload.php'); |
33
|
|
|
|
34
|
|
|
$template = new PHP($pathInfo, $config, false); |
35
|
|
|
$code = $template->getCode('commit-msg'); |
36
|
|
|
|
37
|
|
|
$this->assertStringContainsString('#!/usr/bin/env php', $code); |
38
|
|
|
$this->assertStringContainsString('commit-msg', $code); |
39
|
|
|
$this->assertStringContainsString('$captainHook->run(', $code); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Tests PHP::getCode |
44
|
|
|
*/ |
45
|
|
|
public function testSrcStdInHook(): void |
46
|
|
|
{ |
47
|
|
|
$pathInfo = $this->createMock(PathInfo::class); |
48
|
|
|
$pathInfo->method('getExecutablePath')->willReturn('./vendor/bin/captainhook'); |
49
|
|
|
$pathInfo->method('getConfigPath')->willReturn('captainhook.json'); |
50
|
|
|
|
51
|
|
|
$config = $this->createConfigMock(false, 'captainhook.json'); |
52
|
|
|
$config->method('getBootstrap')->willReturn('vendor/autoload.php'); |
53
|
|
|
|
54
|
|
|
$template = new PHP($pathInfo, $config, false); |
55
|
|
|
$code = $template->getCode('pre-push'); |
56
|
|
|
|
57
|
|
|
$this->assertStringContainsString('#!/usr/bin/env php', $code); |
58
|
|
|
$this->assertStringContainsString('STDIN', $code); |
59
|
|
|
$this->assertStringContainsString('$captainHook->run(', $code); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Tests PHP::getCode |
64
|
|
|
*/ |
65
|
|
|
public function testSrcTemplateExtExecutable(): void |
66
|
|
|
{ |
67
|
|
|
$pathInfo = $this->createMock(PathInfo::class); |
68
|
|
|
$pathInfo->method('getExecutablePath')->willReturn('./vendor/bin/captainhook'); |
69
|
|
|
$pathInfo->method('getConfigPath')->willReturn('captainhook.json'); |
70
|
|
|
|
71
|
|
|
$config = $this->createConfigMock(false, 'captainhook.json'); |
72
|
|
|
$config->method('getBootstrap')->willReturn('vendor/autoload.php'); |
73
|
|
|
|
74
|
|
|
$template = new PHP($pathInfo, $config, false); |
75
|
|
|
$code = $template->getCode('commit-msg'); |
76
|
|
|
|
77
|
|
|
$this->assertStringContainsString('#!/usr/bin/env php', $code); |
78
|
|
|
$this->assertStringContainsString('commit-msg', $code); |
79
|
|
|
$this->assertStringContainsString('$captainHook->run(', $code); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Tests PHP::getCode |
84
|
|
|
*/ |
85
|
|
|
public function testPharAbsoluteExecutablePath(): void |
86
|
|
|
{ |
87
|
|
|
$pathInfo = $this->createMock(PathInfo::class); |
88
|
|
|
$pathInfo->method('getExecutablePath')->willReturn('/usr/local/bin/captainhook'); |
89
|
|
|
$pathInfo->method('getConfigPath')->willReturn('captainhook.json'); |
90
|
|
|
|
91
|
|
|
$config = $this->createConfigMock(false, 'captainhook.json'); |
92
|
|
|
$config->method('getBootstrap')->willReturn('vendor/autoload.php'); |
93
|
|
|
|
94
|
|
|
$template = new PHP($pathInfo, $config, true); |
95
|
|
|
$code = $template->getCode('commit-msg'); |
96
|
|
|
|
97
|
|
|
$this->assertStringContainsString('#!/usr/bin/env php', $code); |
98
|
|
|
$this->assertStringContainsString('commit-msg', $code); |
99
|
|
|
$this->assertStringContainsString('/usr/local/bin/captainhook', $code); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Tests PHP::getCode |
104
|
|
|
*/ |
105
|
|
|
public function testPharTemplate(): void |
106
|
|
|
{ |
107
|
|
|
$pathInfo = $this->createMock(PathInfo::class); |
108
|
|
|
$pathInfo->method('getExecutablePath')->willReturn('tools/captainhook.phar'); |
109
|
|
|
$pathInfo->method('getConfigPath')->willReturn('captainhook.json'); |
110
|
|
|
|
111
|
|
|
$config = $this->createConfigMock(false, 'captainhook.json'); |
112
|
|
|
$config->method('getBootstrap')->willReturn('vendor/autoload.php'); |
113
|
|
|
|
114
|
|
|
$template = new PHP($pathInfo, $config, true); |
115
|
|
|
$code = $template->getCode('commit-msg'); |
116
|
|
|
|
117
|
|
|
$this->assertStringContainsString('#!/usr/bin/env php', $code); |
118
|
|
|
$this->assertStringContainsString('hook:commit-msg', $code); |
119
|
|
|
$this->assertStringContainsString('tools/captainhook.phar', $code); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Tests PHP::getCode |
124
|
|
|
*/ |
125
|
|
|
public function testPharStdIn(): void |
126
|
|
|
{ |
127
|
|
|
$pathInfo = $this->createMock(PathInfo::class); |
128
|
|
|
$pathInfo->method('getExecutablePath')->willReturn('tools/captainhook.phar'); |
129
|
|
|
$pathInfo->method('getConfigPath')->willReturn('captainhook.json'); |
130
|
|
|
|
131
|
|
|
$config = $this->createConfigMock(false, 'captainhook.json'); |
132
|
|
|
$config->method('getBootstrap')->willReturn('vendor/autoload.php'); |
133
|
|
|
|
134
|
|
|
$template = new PHP($pathInfo, $config, true); |
135
|
|
|
$code = $template->getCode('post-rewrite'); |
136
|
|
|
|
137
|
|
|
$this->assertStringContainsString('#!/usr/bin/env php', $code); |
138
|
|
|
$this->assertStringContainsString('hook:post-rewrite', $code); |
139
|
|
|
$this->assertStringContainsString('STDIN', $code); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|