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\Config\Run; |
16
|
|
|
use CaptainHook\App\Hook\Template\PathInfo; |
17
|
|
|
use PHPUnit\Framework\TestCase; |
18
|
|
|
|
19
|
|
|
class WSLTest extends ShellTest |
20
|
|
|
{ |
21
|
|
|
use ConfigMockery; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Tests WSL::getCode |
25
|
|
|
*/ |
26
|
|
|
public function testTemplate(): void |
27
|
|
|
{ |
28
|
|
|
$pathInfo = $this->createMock(PathInfo::class); |
29
|
|
|
$pathInfo->method('getExecutablePath')->willReturn('vendor/bin/captainhook'); |
30
|
|
|
$pathInfo->method('getConfigPath')->willReturn('captainhook.json'); |
31
|
|
|
|
32
|
|
|
$config = $this->createConfigMock(false, 'captainhook.json'); |
33
|
|
|
$config->method('getBootstrap')->willReturn('vendor/autoload.php'); |
34
|
|
|
$config->method('getPhpPath')->willReturn(''); |
35
|
|
|
|
36
|
|
|
$template = new WSL($pathInfo, $config, false); |
37
|
|
|
$code = $template->getCode('commit-msg'); |
38
|
|
|
|
39
|
|
|
$this->assertStringContainsString('#!/bin/sh', $code); |
40
|
|
|
$this->assertStringContainsString('commit-msg', $code); |
41
|
|
|
$this->assertStringNotContainsString('php7.4', $code); |
42
|
|
|
$this->assertStringContainsString('wsl.exe vendor/bin/captainhook $INTERACTIVE', $code); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Tests WSL::getCode |
47
|
|
|
*/ |
48
|
|
|
public function testTemplateWithDefinedPHP(): void |
49
|
|
|
{ |
50
|
|
|
$pathInfo = $this->createMock(PathInfo::class); |
51
|
|
|
$pathInfo->method('getExecutablePath')->willReturn('vendor/bin/captainhook'); |
52
|
|
|
$pathInfo->method('getConfigPath')->willReturn('captainhook.json'); |
53
|
|
|
|
54
|
|
|
$config = $this->createConfigMock(false, 'captainhook.json'); |
55
|
|
|
$config->method('getBootstrap')->willReturn('vendor/autoload.php'); |
56
|
|
|
$config->method('getPhpPath')->willReturn('/usr/bin/php7.4'); |
57
|
|
|
|
58
|
|
|
$template = new WSL($pathInfo, $config, false); |
59
|
|
|
$code = $template->getCode('commit-msg'); |
60
|
|
|
|
61
|
|
|
$this->assertStringContainsString('#!/bin/sh', $code); |
62
|
|
|
$this->assertStringContainsString('commit-msg', $code); |
63
|
|
|
$this->assertStringContainsString('/usr/bin/php7.4', $code); |
64
|
|
|
$this->assertStringContainsString('wsl.exe /usr/bin/php7.4 vendor/bin/captainhook $INTERACTIVE', $code); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Tests WSL::getCode |
69
|
|
|
*/ |
70
|
|
|
public function testTemplateWithDefinedPHPAndRunPath(): void |
71
|
|
|
{ |
72
|
|
|
$pathInfo = $this->createMock(PathInfo::class); |
73
|
|
|
$pathInfo->method('getExecutablePath')->willReturn('vendor/bin/captainhook'); |
74
|
|
|
$pathInfo->method('getConfigPath')->willReturn('captainhook.json'); |
75
|
|
|
|
76
|
|
|
$config = $this->createConfigMock(false, 'captainhook.json'); |
77
|
|
|
$runConfig = new Run(['path' => 'tools/captainhook.phar']); |
78
|
|
|
$config->method('getRunConfig')->willReturn($runConfig); |
79
|
|
|
$config->method('getBootstrap')->willReturn('vendor/autoload.php'); |
80
|
|
|
$config->method('getPhpPath')->willReturn('/usr/bin/php7.4'); |
81
|
|
|
|
82
|
|
|
$template = new WSL($pathInfo, $config, false); |
83
|
|
|
$code = $template->getCode('commit-msg'); |
84
|
|
|
|
85
|
|
|
$this->assertStringContainsString('#!/bin/sh', $code); |
86
|
|
|
$this->assertStringContainsString('commit-msg', $code); |
87
|
|
|
$this->assertStringContainsString('/usr/bin/php7.4', $code); |
88
|
|
|
$this->assertStringContainsString('wsl.exe /usr/bin/php7.4 tools/captainhook.phar $INTERACTIVE', $code); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Tests WSL::getCode |
93
|
|
|
*/ |
94
|
|
|
public function testTemplateExtExecutable(): void |
95
|
|
|
{ |
96
|
|
|
$pathInfo = $this->createMock(PathInfo::class); |
97
|
|
|
$pathInfo->method('getExecutablePath')->willReturn('/usr/local/bin/captainhook'); |
98
|
|
|
$pathInfo->method('getConfigPath')->willReturn('captainhook.json'); |
99
|
|
|
|
100
|
|
|
$config = $this->createConfigMock(false, 'captainhook.json'); |
101
|
|
|
$config->method('getBootstrap')->willReturn('vendor/autoload.php'); |
102
|
|
|
$config->method('getPhpPath')->willReturn(''); |
103
|
|
|
|
104
|
|
|
$template = new WSL($pathInfo, $config, false); |
105
|
|
|
$code = $template->getCode('commit-msg'); |
106
|
|
|
|
107
|
|
|
$this->assertStringContainsString('#!/bin/sh', $code); |
108
|
|
|
$this->assertStringContainsString('commit-msg', $code); |
109
|
|
|
$this->assertStringNotContainsString('php7.4', $code); |
110
|
|
|
$this->assertStringContainsString('wsl.exe /usr/local/bin/captainhook $INTERACTIVE', $code); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Tests WSL::getCode |
115
|
|
|
*/ |
116
|
|
|
public function testTemplateExtExecutableWithDefinedPHP(): void |
117
|
|
|
{ |
118
|
|
|
$pathInfo = $this->createMock(PathInfo::class); |
119
|
|
|
$pathInfo->method('getExecutablePath')->willReturn('/usr/local/bin/captainhook'); |
120
|
|
|
$pathInfo->method('getConfigPath')->willReturn('captainhook.json'); |
121
|
|
|
|
122
|
|
|
$config = $this->createConfigMock(false, 'captainhook.json'); |
123
|
|
|
$config->method('getBootstrap')->willReturn('vendor/autoload.php'); |
124
|
|
|
$config->method('getPhpPath')->willReturn('/usr/bin/php7.4'); |
125
|
|
|
|
126
|
|
|
$template = new WSL($pathInfo, $config, false); |
127
|
|
|
$code = $template->getCode('commit-msg'); |
128
|
|
|
|
129
|
|
|
$this->assertStringContainsString('#!/bin/sh', $code); |
130
|
|
|
$this->assertStringContainsString('commit-msg', $code); |
131
|
|
|
|
132
|
|
|
$this->assertStringContainsString('/usr/bin/php7.4', $code); |
133
|
|
|
$this->assertStringContainsString('wsl.exe /usr/bin/php7.4 /usr/local/bin/captainhook $INTERACTIVE', $code); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Tests WSL::getCode |
138
|
|
|
*/ |
139
|
|
|
public function testTemplateExtExecutableWithUserInput(): void |
140
|
|
|
{ |
141
|
|
|
$pathInfo = $this->createMock(PathInfo::class); |
142
|
|
|
$pathInfo->method('getExecutablePath')->willReturn('/usr/local/bin/captainhook'); |
143
|
|
|
$pathInfo->method('getConfigPath')->willReturn('captainhook.json'); |
144
|
|
|
|
145
|
|
|
$config = $this->createConfigMock(false, 'captainhook.json'); |
146
|
|
|
$config->method('getBootstrap')->willReturn('vendor/autoload.php'); |
147
|
|
|
$config->method('getPhpPath')->willReturn(''); |
148
|
|
|
|
149
|
|
|
$template = new WSL($pathInfo, $config, false); |
150
|
|
|
$code = $template->getCode('prepare-commit-msg'); |
151
|
|
|
|
152
|
|
|
$this->assertStringContainsString('#!/bin/sh', $code); |
153
|
|
|
$this->assertStringContainsString('commit-msg', $code); |
154
|
|
|
$this->assertStringContainsString('wsl.exe /usr/local/bin/captainhook $INTERACTIVE', $code); |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|