Completed
Push — master ( 0ea243...da58d4 )
by Henry
10:25 queued 33s
created

tests/unit/Controller/InstallTest.php (1 issue)

Check for loose comparison of strings.

Best Practice Bug Major

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace Redaxscript\Tests\Controller;
3
4
use org\bovigo\vfs\vfsStream as Stream;
5
use org\bovigo\vfs\vfsStreamFile as StreamFile;
6
use org\bovigo\vfs\vfsStreamWrapper as StreamWrapper;
7
use Redaxscript\Controller;
8
use Redaxscript\Tests\TestCaseAbstract;
9
10
/**
11
 * InstallTest
12
 *
13
 * @since 3.0.0
14
 *
15
 * @package Redaxscript
16
 * @category Tests
17
 * @author Henry Ruhs
18
 * @author Balázs Szilágyi
19
 *
20
 * @covers Redaxscript\Controller\ControllerAbstract
21
 * @covers Redaxscript\Controller\Install
22
 */
23
24
class InstallTest extends TestCaseAbstract
25
{
26
	/**
27
	 * setUp
28
	 *
29
	 * @since 3.0.0
30
	 */
31
32
	public function setUp() : void
33
	{
34
		parent::setUp();
35
		Stream::setup('root');
36
		$file = new StreamFile('config.php');
37
		StreamWrapper::getRoot()->addChild($file);
38
	}
39
40
	/**
41
	 * tearDown
42
	 *
43
	 * @since 3.1.0
44
	 */
45
46
	public function tearDown() : void
47
	{
48
		$this->dropDatabase();
49
	}
50
51
	/**
52
	 * testProcess
53
	 *
54
	 * @since 3.0.0
55
	 *
56
	 * @param array $postArray
57
	 * @param string $method
58
	 * @param string $expect
59
	 *
60
	 * @dataProvider providerAutoloader
61
	 */
62
63
	public function testProcess(array $postArray = [], string $method = null, string $expect = null) : void
64
	{
65
		/* setup */
66
67
		$postArray['db-type'] = $postArray['db-type'] === '%CURRENT%' ? $this->_config->get('dbType') : $postArray['db-type'];
68
		$postArray['db-host'] = $postArray['db-host'] === '%CURRENT%' ? $this->_config->get('dbHost') : $postArray['db-host'];
69
		$postArray['db-name'] = $postArray['db-name'] === '%CURRENT%' ? $this->_config->get('dbName') : $postArray['db-name'];
70
		$postArray['db-user'] = $postArray['db-user'] === '%CURRENT%' ? $this->_config->get('dbUser') : $postArray['db-user'];
71
		$postArray['db-password'] = $postArray['db-password'] === '%CURRENT%' ? $this->_config->get('dbPassword') : $postArray['db-password'];
72
		$postArray['db-prefix'] = $postArray['db-prefix'] === '%CURRENT%' ? $this->_config->get('dbPrefix') : $postArray['db-prefix'];
73
		$this->_request->set('post', $postArray);
74
		$this->_config->init(Stream::url('root' . DIRECTORY_SEPARATOR . 'config.php'));
75
		if ($method)
0 ignored issues
show
Bug Best Practice introduced by
The expression $method of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
76
		{
77
			$installController = $this
78
				->getMockBuilder('Redaxscript\Controller\Install')
79
				->setConstructorArgs(
80
				[
81
					$this->_registry,
82
					$this->_request,
83
					$this->_language,
84
					$this->_config
85
				])
86
				->setMethods(
87
				[
88
					$method
89
				])
90
				->getMock();
91
92
			/* override */
93
94
			$installController
95
				->expects($this->any())
96
				->method($method)
97
				->will($this->returnValue(false));
98
		}
99
		else
100
		{
101
			$installController = new Controller\Install($this->_registry, $this->_request, $this->_language, $this->_config);
102
		}
103
104
		/* actual */
105
106
		$actual = $installController->process();
107
108
		/* compare */
109
110
		$this->assertEquals($expect, $actual);
111
	}
112
113
	/**
114
	 * testValidateDatabase
115
	 *
116
	 * @since 3.0.0
117
	 *
118
	 * @param array $postArray
119
	 * @param array $expectArray
120
	 *
121
	 * @dataProvider providerAutoloader
122
	 */
123
124
	public function testValidateDatabase(array $postArray = [], array $expectArray = []) : void
125
	{
126
		/* setup */
127
128
		$installController = new Controller\Install($this->_registry, $this->_request, $this->_language, $this->_config);
129
130
		/* actual */
131
132
		$actualArray = $this->callMethod($installController, '_validateDatabase',
133
		[
134
			$postArray
135
		]);
136
137
		/* compare */
138
139
		$this->assertEquals($expectArray, $actualArray);
140
	}
141
142
	/**
143
	 * testValidateAccount
144
	 *
145
	 * @since 3.0.0
146
	 *
147
	 * @param array $postArray
148
	 * @param array $expectArray
149
	 *
150
	 * @dataProvider providerAutoloader
151
	 */
152
153
	public function testValidateAccount(array $postArray = [], array $expectArray = []) : void
154
	{
155
		/* setup */
156
157
		$installController = new Controller\Install($this->_registry, $this->_request, $this->_language, $this->_config);
158
159
		/* actual */
160
161
		$actualArray = $this->callMethod($installController, '_validateAccount',
162
		[
163
			$postArray
164
		]);
165
166
		/* compare */
167
168
		$this->assertEquals($expectArray, $actualArray);
169
	}
170
171
	/**
172
	 * testInstall
173
	 *
174
	 * @since 3.0.0
175
	 *
176
	 * @param array $installArray
177
	 * @param bool $expect
178
	 *
179
	 * @dataProvider providerAutoloader
180
	 */
181
182
	public function testInstall(array $installArray = [], bool $expect = null) : void
183
	{
184
		/* setup */
185
186
		$installController = new Controller\Install($this->_registry, $this->_request, $this->_language, $this->_config);
187
188
		/* actual */
189
190
		$actual = $this->callMethod($installController, '_install',
191
		[
192
			$installArray
193
		]);
194
195
		/* compare */
196
197
		$this->assertEquals($expect, $actual);
198
	}
199
}
200