1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Functional; |
4
|
|
|
|
5
|
|
|
class HookTest extends AbstractTestCase |
6
|
|
|
{ |
7
|
|
|
|
8
|
|
|
public static function setUpBeforeClass() |
9
|
|
|
{ |
10
|
|
|
self::setPath('/'); |
11
|
|
|
self::setSecurityHeader('X-Gitlab-Token'); |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
public function testDeploy() |
16
|
|
|
{ |
17
|
|
|
$this->simpleTest(__DIR__ . '/data/pipeline.json', |
18
|
|
|
[ |
19
|
|
|
'HOOK_PROJECT_PATH' => 'gitlab-org/gitlab-test', |
20
|
|
|
'HOOK_BUILD_ID' => 379, |
21
|
|
|
'HOOK_BUILD_REF' => 'bcbb5ec396a2c0f828686f14fac9b80b780504f2', |
22
|
|
|
'HOOK_ENV_NAME' => 'staging' |
23
|
|
|
], [ |
|
|
|
|
24
|
|
|
'bash /testing-dir/script.bash deploy', |
25
|
|
|
'bash do-something-else' |
26
|
|
|
]); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
public function testPush() |
31
|
|
|
{ |
32
|
|
|
$this->simpleTest(__DIR__ . '/data/push.json', [ |
33
|
|
|
'HOOK_PROJECT_PATH' => 'gitlab-org/gitlab-test', |
34
|
|
|
'HOOK_REF' => 'refs/heads/master', |
35
|
|
|
'HOOK_BRANCH' => 'master', |
36
|
|
|
'HOOK_BUILD_REF' => 'da1560886d4f094c3e6c9ef40349f7d38b5d27d7' |
37
|
|
|
], [ |
|
|
|
|
38
|
|
|
'cwd' => '/testing-dir', |
39
|
|
|
'command' => 'bash /testing-dir/script.bash push' |
40
|
|
|
]); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
public function testPushTag() |
45
|
|
|
{ |
46
|
|
|
$this->simpleTest(__DIR__ . '/data/tag.json', |
47
|
|
|
[ |
48
|
|
|
'HOOK_PROJECT_PATH' => 'jsmith/example', |
49
|
|
|
'HOOK_REF' => 'refs/tags/v1.0.0', |
50
|
|
|
'HOOK_TAG' => 'v1.0.0', |
51
|
|
|
'HOOK_BUILD_REF' => '82b3d5ae55f7080f1e6022629cdb57bfae7cccc7' |
52
|
|
|
], |
53
|
|
|
'bash test.bash xcasdzcxzsdda' |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
public function testExecutorPushTag() |
59
|
|
|
{ |
60
|
|
|
$result = shell_exec("bash -c \"echo abc\""); |
61
|
|
|
if ($result === "abc\n") { |
62
|
|
|
if (file_exists(__DIR__ . '/log')) { |
63
|
|
|
unlink(__DIR__ . '/log'); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$response = $this->runApp(file_get_contents(__DIR__ . '/data/tag.json') , [ |
67
|
|
|
'scripts' => [ |
68
|
|
|
'jsmith/example' => [ |
69
|
|
|
'tag' => [ |
70
|
|
|
'cwd' => __DIR__, |
71
|
|
|
'bash test.bash ABC', |
72
|
|
|
'bash test.bash CDE' |
73
|
|
|
] |
74
|
|
|
] |
75
|
|
|
] |
76
|
|
|
]); |
77
|
|
|
$logFile = file_get_contents(__DIR__ . '/log'); |
78
|
|
|
$this->assertEquals( |
79
|
|
|
"jsmith/example refs/tags/v1.0.0 v1.0.0 82b3d5ae55f7080f1e6022629cdb57bfae7cccc7 ABC\n" . |
80
|
|
|
"jsmith/example refs/tags/v1.0.0 v1.0.0 82b3d5ae55f7080f1e6022629cdb57bfae7cccc7 CDE\n", |
81
|
|
|
$logFile |
82
|
|
|
); |
83
|
|
|
|
84
|
|
|
$this->assertEquals(200, $response->getStatusCode()); |
85
|
|
|
|
86
|
|
|
unlink(__DIR__ . '/log'); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
public function testExecutorSinglePushTag() |
92
|
|
|
{ |
93
|
|
|
$result = shell_exec("bash -c \"echo abc\""); |
94
|
|
|
if ($result === "abc\n") { |
95
|
|
|
if (file_exists(__DIR__ . '/log')) { |
96
|
|
|
unlink(__DIR__ . '/log'); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
$oldDir = getcwd(); |
100
|
|
|
chdir(__DIR__); |
101
|
|
|
|
102
|
|
|
$response = $this->runApp(file_get_contents(__DIR__ . '/data/tag.json') , [ |
103
|
|
|
'scripts' => [ |
104
|
|
|
'jsmith/example' => [ |
105
|
|
|
'tag' => 'bash test.bash DEF' |
106
|
|
|
] |
107
|
|
|
] |
108
|
|
|
]); |
109
|
|
|
$logFile = file_get_contents(__DIR__ . '/log'); |
110
|
|
|
$this->assertEquals( |
111
|
|
|
"jsmith/example refs/tags/v1.0.0 v1.0.0 82b3d5ae55f7080f1e6022629cdb57bfae7cccc7 DEF\n", |
112
|
|
|
$logFile |
113
|
|
|
); |
114
|
|
|
|
115
|
|
|
$this->assertEquals(200, $response->getStatusCode()); |
116
|
|
|
|
117
|
|
|
chdir($oldDir); |
118
|
|
|
unlink(__DIR__ . '/log'); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
|
123
|
|
|
public function testNo() |
124
|
|
|
{ |
125
|
|
|
$response = $this->runInvalid(); |
126
|
|
|
|
127
|
|
|
$this->assertEquals(500, $response->getStatusCode()); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
|
131
|
|
|
public function testUnsecured() |
132
|
|
|
{ |
133
|
|
|
$response = $this->runUnsecured(); |
134
|
|
|
|
135
|
|
|
$this->assertEquals(403, $response->getStatusCode()); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
public function testNotHandled() |
140
|
|
|
{ |
141
|
|
|
$response = $this->runNotHandled(); |
142
|
|
|
|
143
|
|
|
$this->assertEquals(404, $response->getStatusCode()); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @param string $file |
149
|
|
|
* @param array $env |
150
|
|
|
* @param string $command |
151
|
|
|
*/ |
152
|
|
|
protected function simpleTest($file, array $env, $command) |
153
|
|
|
{ |
154
|
|
|
$response = $this->runAppMocked(file_get_contents($file), $env, $command); |
155
|
|
|
$this->assertEquals(200, $response->getStatusCode()); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
} |
159
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: