Completed
Push — master ( d0c173...e44a53 )
by Henry
09:36
created

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

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
		}
98
		else
99
		{
100
			$installController = new Controller\Install($this->_registry, $this->_request, $this->_language, $this->_config);
101
		}
102
103
		/* actual */
104
105
		$actual = $installController->process();
106
107
		/* compare */
108
109
		$this->assertEquals($expect, $actual);
110
	}
111
112
	/**
113
	 * testValidateDatabase
114
	 *
115
	 * @since 3.0.0
116
	 *
117
	 * @param array $postArray
118
	 * @param array $expectArray
119
	 *
120
	 * @dataProvider providerAutoloader
121
	 */
122
123
	public function testValidateDatabase(array $postArray = [], array $expectArray = []) : void
124
	{
125
		/* setup */
126
127
		$installController = new Controller\Install($this->_registry, $this->_request, $this->_language, $this->_config);
128
129
		/* actual */
130
131
		$actualArray = $this->callMethod($installController, '_validateDatabase',
132
		[
133
			$postArray
134
		]);
135
136
		/* compare */
137
138
		$this->assertEquals($expectArray, $actualArray);
139
	}
140
141
	/**
142
	 * testValidateAccount
143
	 *
144
	 * @since 3.0.0
145
	 *
146
	 * @param array $postArray
147
	 * @param array $expectArray
148
	 *
149
	 * @dataProvider providerAutoloader
150
	 */
151
152
	public function testValidateAccount(array $postArray = [], array $expectArray = []) : void
153
	{
154
		/* setup */
155
156
		$installController = new Controller\Install($this->_registry, $this->_request, $this->_language, $this->_config);
157
158
		/* actual */
159
160
		$actualArray = $this->callMethod($installController, '_validateAccount',
161
		[
162
			$postArray
163
		]);
164
165
		/* compare */
166
167
		$this->assertEquals($expectArray, $actualArray);
168
	}
169
170
	/**
171
	 * testInstall
172
	 *
173
	 * @since 3.0.0
174
	 *
175
	 * @param array $installArray
176
	 * @param bool $expect
177
	 *
178
	 * @dataProvider providerAutoloader
179
	 */
180
181
	public function testInstall(array $installArray = [], bool $expect = null) : void
182
	{
183
		/* setup */
184
185
		$installController = new Controller\Install($this->_registry, $this->_request, $this->_language, $this->_config);
186
187
		/* actual */
188
189
		$actual = $this->callMethod($installController, '_install',
190
		[
191
			$installArray
192
		]);
193
194
		/* compare */
195
196
		$this->assertEquals($expect, $actual);
197
	}
198
}
199