ParserTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 175
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 0
loc 175
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 4 1
A testInit() 0 11 1
A testGetAndSetArgument() 0 15 1
A testGetArgument() 0 16 1
A testGetArgumentInvalid() 0 15 1
A testGetAndSetOption() 0 15 1
A testGetOption() 0 16 1
A testGetOptionInvalid() 0 15 1
1
<?php
2
namespace Redaxscript\Tests\Console;
3
4
use Redaxscript\Console;
5
use Redaxscript\Tests\TestCaseAbstract;
6
7
/**
8
 * ParserTest
9
 *
10
 * @since 3.0.0
11
 *
12
 * @package Redaxscript
13
 * @category Tests
14
 * @author Henry Ruhs
15
 *
16
 * @covers Redaxscript\Console\Parser
17
 */
18
19
class ParserTest extends TestCaseAbstract
20
{
21
	/**
22
	 * tearDown
23
	 *
24
	 * @since 3.0.0
25
	 */
26
27
	public function tearDown() : void
28
	{
29
		$this->_request->setServer('argv', null);
30
	}
31
32
	/**
33
	 * testInit
34
	 *
35
	 * @since 3.0.0
36
	 */
37
38
	public function testInit() : void
39
	{
40
		/* setup */
41
42
		$parser = new Console\Parser($this->_request);
43
		$parser->init('cli');
44
45
		/* compare */
46
47
		$this->assertEmpty($parser->getArgumentArray());
48
	}
49
50
	/**
51
	 * testGetAndSetArgument
52
	 *
53
	 * @since 3.0.0
54
	 */
55
56
	public function testGetAndSetArgument() : void
57
	{
58
		/* setup */
59
60
		$parser = new Console\Parser($this->_request);
61
		$parser->setArgument('test', 'test');
62
63
		/* actual */
64
65
		$actual = $parser->getArgument('test');
66
67
		/* compare */
68
69
		$this->assertEquals('test', $actual);
70
	}
71
72
	/**
73
	 * testGetArgument
74
	 *
75
	 * @since 3.0.0
76
	 *
77
	 * @param array $argumentArray
78
	 * @param array $expectArray
79
	 *
80
	 * @dataProvider providerAutoloader
81
	 */
82
83
	public function testGetArgument(array $argumentArray = [], array $expectArray = []) : void
84
	{
85
		/* setup */
86
87
		$this->_request->setServer('argv', $argumentArray);
88
		$parser = new Console\Parser($this->_request);
89
		$parser->init('cli');
90
91
		/* actual */
92
93
		$actualArray = $parser->getArgumentArray();
94
95
		/* compare */
96
97
		$this->assertEquals($expectArray, $actualArray);
98
	}
99
100
	/**
101
	 * testGetArgumentInvalid
102
	 *
103
	 * @since 3.0.0
104
	 */
105
106
	public function testGetArgumentInvalid() : void
107
	{
108
		/* setup */
109
110
		$parser = new Console\Parser($this->_request);
111
		$parser->init('cli');
112
113
		/* actual */
114
115
		$actual = $parser->getArgument('invalidArgument');
116
117
		/* compare */
118
119
		$this->assertNull($actual);
120
	}
121
122
	/**
123
	 * testGetAndSetOption
124
	 *
125
	 * @since 3.0.0
126
	 */
127
128
	public function testGetAndSetOption() : void
129
	{
130
		/* setup */
131
132
		$parser = new Console\Parser($this->_request);
133
		$parser->setOption('test', 'test');
134
135
		/* actual */
136
137
		$actual = $parser->getOption('test');
138
139
		/* compare */
140
141
		$this->assertEquals('test', $actual);
142
	}
143
144
	/**
145
	 * testGetOption
146
	 *
147
	 * @since 3.0.0
148
	 *
149
	 * @param array $argumentArray
150
	 * @param array $expectArray
151
	 *
152
	 * @dataProvider providerAutoloader
153
	 */
154
155
	public function testGetOption(array $argumentArray = [], array $expectArray = []) : void
156
	{
157
		/* setup */
158
159
		$this->_request->setServer('argv', $argumentArray);
160
		$parser = new Console\Parser($this->_request);
161
		$parser->init('cli');
162
163
		/* actual */
164
165
		$actualArray = $parser->getOptionArray();
166
167
		/* compare */
168
169
		$this->assertEquals($expectArray, $actualArray);
170
	}
171
172
	/**
173
	 * testGetOptionInvalid
174
	 *
175
	 * @since 3.0.0
176
	 */
177
178
	public function testGetOptionInvalid() : void
179
	{
180
		/* setup */
181
182
		$parser = new Console\Parser($this->_request);
183
		$parser->init('cli');
184
185
		/* actual */
186
187
		$actual = $parser->getOption('invalidOption');
188
189
		/* compare */
190
191
		$this->assertNull($actual);
192
	}
193
}
194