Passed
Push — master ( dde30a...f17d1c )
by Jan
02:49
created

BashRestTest::testAction2Env()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 29
rs 8.8571
cc 1
eloc 21
nc 1
nop 0
1
<?php
2
3
namespace Tests\Functional;
4
5
class BashRestTest extends AbstractTestCase
6
{
7
8
	public static function setUpBeforeClass()
9
	{
10
		self::setSecurityHeader('X-Secret');
11
	}
12
13
14
	public function testAction1()
15
	{
16
		self::setPath('/bash-rest/test-app/action1');
17
		$this->simpleTest('[]', [] , 'test');
18
	}
19
20
21
	public function testAction2()
22
	{
23
		self::setPath('/bash-rest/test-app/action2');
24
		$this->simpleTest('[]', [] , [
25
			'cwd' => 'dir',
26
			'test1',
27
			'test2'
28
		]);
29
	}
30
31
32
	public function testAction2Env()
33
	{
34
		self::setPath('/bash-rest/test-app/action2');
35
		$input = [
36
			'test' => 'a',
37
			'down' => [
38
				'test' => 'b',
39
				'more' => [
40
					'test' => 3
41
				]
42
			],
43
			'array' => ['a', 'b', 'c'],
44
			'last' => 'zxc'
45
		];
46
47
		$this->simpleTest(json_encode($input), [
48
			'HOOK_test' => 'a',
49
			'HOOK_down_test' => 'b',
50
			'HOOK_down_more_test' => 3,
51
			'HOOK_array_0' => 'a',
52
			'HOOK_array_1' => 'b',
53
			'HOOK_array_2' => 'c',
54
			'HOOK_last' => 'zxc'
55
		] , [
56
			'cwd' => 'dir',
57
			'test1',
58
			'test2'
59
		]);
60
	}
61
62
63
	public function testUnsecured()
64
	{
65
		self::setPath('/bash-rest/test-app/noAction');
66
		$response = $this->runUnsecured();
67
68
		$this->assertEquals(403, $response->getStatusCode());
69
	}
70
71
72
	public function testNotHandled()
73
	{
74
		self::setPath('/bash-rest/test-app/noAction');
75
		$response = $this->runAppMocked('[]', [], NULL);
76
77
		$this->assertEquals(404, $response->getStatusCode());
78
	}
79
80
81
	protected function simpleTest($data, array $env, $command)
82
	{
83
		$response = $this->runAppMocked($data, $env, $command);
84
		$this->assertEquals(200, $response->getStatusCode());
85
		$responseBody = (string)$response->getBody();
86
		$this->assertEquals(
87
			[
88
				'result' => $env
89
			],
90
			json_decode($responseBody, TRUE)
91
		);
92
	}
93
94
}
95