SettingTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 140
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 140
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 9 1
A tearDown() 0 5 1
A testNoArgument() 0 15 1
A testList() 0 20 1
A testSet() 0 25 1
A testSetInvalid() 0 22 1
1
<?php
2
namespace Redaxscript\Tests\Console\Command;
3
4
use Redaxscript\Console\Command;
5
use Redaxscript\Tests\TestCaseAbstract;
6
7
/**
8
 * SettingTest
9
 *
10
 * @since 3.0.0
11
 *
12
 * @package Redaxscript
13
 * @category Tests
14
 * @author Henry Ruhs
15
 *
16
 * @covers Redaxscript\Console\Command\CommandAbstract
17
 * @covers Redaxscript\Console\Command\Setting
18
 */
19
20
class SettingTest extends TestCaseAbstract
21
{
22
	/**
23
	 * setUp
24
	 *
25
	 * @since 3.1.0
26
	 */
27
28
	public function setUp() : void
29
	{
30
		parent::setUp();
31
		$optionArray = $this->getOptionArray();
32
		$installer = $this->installerFactory();
33
		$installer->init();
34
		$installer->rawCreate();
35
		$installer->insertSettings($optionArray);
36
	}
37
38
	/**
39
	 * tearDown
40
	 *
41
	 * @since 3.1.0
42
	 */
43
44
	public function tearDown() : void
45
	{
46
		$this->dropDatabase();
47
		$this->_request->setServer('argv', null);
48
	}
49
50
	/**
51
	 * testNoArgument
52
	 *
53
	 * @since 3.0.0
54
	 */
55
56
	public function testNoArgument() : void
57
	{
58
		/* setup */
59
60
		$settingCommand = new Command\Setting($this->_registry, $this->_request, $this->_language, $this->_config);
61
62
		/* expect and actual */
63
64
		$expect = $settingCommand->getHelp();
65
		$actual = $settingCommand->run('cli');
66
67
		/* compare */
68
69
		$this->assertEquals($expect, $actual);
70
	}
71
72
	/**
73
	 * testList
74
	 *
75
	 * @since 3.0.0
76
	 */
77
78
	public function testList() : void
79
	{
80
		/* setup */
81
82
		$this->_request->setServer('argv',
83
		[
84
			'console.php',
85
			'setting',
86
			'list'
87
		]);
88
		$settingCommand = new Command\Setting($this->_registry, $this->_request, $this->_language, $this->_config);
89
90
		/* actual */
91
92
		$actual = $settingCommand->run('cli');
93
94
		/* compare */
95
96
		$this->assertIsString($actual);
97
	}
98
99
	/**
100
	 * testSet
101
	 *
102
	 * @since 3.0.0
103
	 */
104
105
	public function testSet() : void
106
	{
107
		/* setup */
108
109
		$this->_request->setServer('argv',
110
		[
111
			'console.php',
112
			'setting',
113
			'set',
114
			'--key',
115
			'copyright',
116
			'--value',
117
			'Redaxscript'
118
		]);
119
		$settingCommand = new Command\Setting($this->_registry, $this->_request, $this->_language, $this->_config);
120
121
		/* expect and actual */
122
123
		$expect = $settingCommand->success();
124
		$actual = $settingCommand->run('cli');
125
126
		/* compare */
127
128
		$this->assertEquals($expect, $actual);
129
	}
130
131
	/**
132
	 * testSetInvalid
133
	 *
134
	 * @since 3.0.0
135
	 */
136
137
	public function testSetInvalid() : void
138
	{
139
		/* setup */
140
141
		$this->_request->setServer('argv',
142
		[
143
			'console.php',
144
			'setting',
145
			'set',
146
			'--no-interaction'
147
		]);
148
		$settingCommand = new Command\Setting($this->_registry, $this->_request, $this->_language, $this->_config);
149
150
		/* expect and actual */
151
152
		$expect = $settingCommand->error();
153
		$actual = $settingCommand->run('cli');
154
155
		/* compare */
156
157
		$this->assertEquals($expect, $actual);
158
	}
159
}
160