Passed
Push — master ( c7ecbb...dde30a )
by Jan
02:51
created

BasicTest::simpleTest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 3
1
<?php
2
3
namespace Tests\Functional;
4
5
class BasicTest extends AbstractTestCase
6
{
7
8
    public function testDeploy()
9
    {
10
		$this->simpleTest(__DIR__ . '/data/pipeline.json',
11
		[
12
			'HOOK_PROJECT_PATH' => 'gitlab-org/gitlab-test',
13
			'HOOK_BUILD_ID' => 379,
14
			'HOOK_BUILD_REF' => 'bcbb5ec396a2c0f828686f14fac9b80b780504f2',
15
			'HOOK_ENV_NAME' => 'staging'
16
		], [
17
			'bash /testing-dir/script.bash deploy',
18
			'bash do-something-else'
19
		]);
20
    }
21
22
23
    public function testPush()
24
    {
25
		$this->simpleTest(__DIR__ . '/data/push.json', [
26
			'HOOK_PROJECT_PATH' => 'gitlab-org/gitlab-test',
27
			'HOOK_REF' => 'refs/heads/master',
28
			'HOOK_BRANCH' => 'master',
29
			'HOOK_BUILD_REF' => 'da1560886d4f094c3e6c9ef40349f7d38b5d27d7'
30
		], [
31
			'cwd' => '/testing-dir',
32
			'command' => 'bash /testing-dir/script.bash push'
33
		]);
34
    }
35
36
37
	public function testPushTag()
38
	{
39
		$this->simpleTest(__DIR__ . '/data/tag.json',
40
			[
41
				'HOOK_PROJECT_PATH' => 'jsmith/example',
42
				'HOOK_REF' => 'refs/tags/v1.0.0',
43
				'HOOK_TAG' => 'v1.0.0',
44
				'HOOK_BUILD_REF' => '82b3d5ae55f7080f1e6022629cdb57bfae7cccc7'
45
			],
46
			'bash test.bash xcasdzcxzsdda'
47
		);
48
	}
49
50
51
	public function testExecutorPushTag()
52
	{
53
		$result = shell_exec("bash -c \"echo abc\"");
54
		if ($result === "abc\n") {
55
			if (file_exists(__DIR__ . '/log')) {
56
				unlink(__DIR__ . '/log');
57
			}
58
59
			$response = $this->runApp(file_get_contents(__DIR__ . '/data/tag.json') , [
60
				'scripts' => [
61
					'jsmith/example' => [
62
						'tag' => [
63
							'cwd' => __DIR__,
64
							'bash test.bash ABC',
65
							'bash test.bash CDE'
66
						]
67
					]
68
				]
69
			]);
70
			$logFile = file_get_contents(__DIR__ . '/log');
71
			$this->assertEquals(
72
				"jsmith/example refs/tags/v1.0.0 v1.0.0 82b3d5ae55f7080f1e6022629cdb57bfae7cccc7 ABC\n" .
73
				"jsmith/example refs/tags/v1.0.0 v1.0.0 82b3d5ae55f7080f1e6022629cdb57bfae7cccc7 CDE\n",
74
				$logFile
75
			);
76
77
			$this->assertEquals(200, $response->getStatusCode());
78
79
			unlink(__DIR__ . '/log');
80
		}
81
	}
82
83
84
	public function testExecutorSinglePushTag()
85
	{
86
		$result = shell_exec("bash -c \"echo abc\"");
87
		if ($result === "abc\n") {
88
			if (file_exists(__DIR__ . '/log')) {
89
				unlink(__DIR__ . '/log');
90
			}
91
92
			$oldDir = getcwd();
93
			chdir(__DIR__);
94
95
			$response = $this->runApp(file_get_contents(__DIR__ . '/data/tag.json') , [
96
				'scripts' => [
97
					'jsmith/example' => [
98
						'tag' => 'bash test.bash DEF'
99
					]
100
				]
101
			]);
102
			$logFile = file_get_contents(__DIR__ . '/log');
103
			$this->assertEquals(
104
				"jsmith/example refs/tags/v1.0.0 v1.0.0 82b3d5ae55f7080f1e6022629cdb57bfae7cccc7 DEF\n",
105
				$logFile
106
			);
107
108
			$this->assertEquals(200, $response->getStatusCode());
109
110
			chdir($oldDir);
111
			unlink(__DIR__ . '/log');
112
		}
113
	}
114
115
116
	public function testNo()
117
	{
118
		$response = $this->runInvalid();
119
120
		$this->assertEquals(500, $response->getStatusCode());
121
	}
122
123
124
	public function testUnsecured()
125
	{
126
		$response = $this->runUnsecured();
127
128
		$this->assertEquals(403, $response->getStatusCode());
129
	}
130
131
132
	public function testNotHandled()
133
	{
134
		$response = $this->runNotHandled();
135
136
		$this->assertEquals(404, $response->getStatusCode());
137
	}
138
139
140
	protected function simpleTest($file, array $env, $command)
141
	{
142
		$response = $this->runAppMocked(file_get_contents($file), $env, $command);
143
		$this->assertEquals(200, $response->getStatusCode());
144
	}
145
146
}
147