Completed
Push — master ( f93ca8...fd9012 )
by Henry
11:16 queued 01:19
created

tests/phpunit/Console/Command/RestoreTest.php (2 issues)

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\Console\Command;
3
4
use Redaxscript\Console\Command;
5
use Redaxscript\Tests\TestCaseAbstract;
6
use org\bovigo\vfs\vfsStream as Stream;
7
8
/**
9
 * RestoreTest
10
 *
11
 * @since 3.0.0
12
 *
13
 * @package Redaxscript
14
 * @category Tests
15
 * @author Henry Ruhs
16
 *
17
 * @covers Redaxscript\Console\Command\CommandAbstract
18
 * @covers Redaxscript\Console\Command\Restore
19
 *
20
 * @requires OS Linux
21
 */
22
23
class RestoreTest extends TestCaseAbstract
24
{
25
	/**
26
	 * setUp
27
	 *
28
	 * @since 3.0.0
29
	 */
30
31
	public function setUp()
32
	{
33
		parent::setUp();
34
		Stream::setup('root', 0777, $this->getJSON('tests' . DIRECTORY_SEPARATOR . 'provider' . DIRECTORY_SEPARATOR . 'Console' . DIRECTORY_SEPARATOR . 'ConsoleTest_setUp.json'));
0 ignored issues
show
It seems like $this->getJSON('tests' ....onsoleTest_setUp.json') targeting Redaxscript\Tests\TestCaseAbstract::getJSON() can also be of type null; however, org\bovigo\vfs\vfsStream::setup() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
35
	}
36
37
	/**
38
	 * tearDown
39
	 *
40
	 * @since 3.0.0
41
	 */
42
43
	public function tearDown()
44
	{
45
		$this->_request->setServer('argv', null);
46
	}
47
48
	/**
49
	 * testNoArgument
50
	 *
51
	 * @since 3.0.0
52
	 */
53
54
	public function testNoArgument()
55
	{
56
		/* setup */
57
58
		$restoreCommand = new Command\Restore($this->_registry, $this->_request, $this->_language, $this->_config);
59
60
		/* expect and actual */
61
62
		$expect = $restoreCommand->getHelp();
63
		$actual = $restoreCommand->run('cli');
64
65
		/* compare */
66
67
		$this->assertEquals($expect, $actual);
68
	}
69
70
	/**
71
	 * testDatabase
72
	 *
73
	 * @since 3.0.0
74
	 */
75
76
	public function testDatabase()
77
	{
78
		/* setup */
79
80
		$this->_request->setServer('argv',
81
		[
0 ignored issues
show
array('console.php', 're..., '--file', 'test.sql') is of type array<integer,string,{"0..."string","6":"string"}>, but the function expects a string|boolean|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
82
			'console.php',
83
			'restore',
84
			'database',
85
			'--directory',
86
			Stream::url('root' . DIRECTORY_SEPARATOR . 'build'),
87
			'--file',
88
			'test.sql'
89
		]);
90
		$restoreCommand = new Command\Restore($this->_registry, $this->_request, $this->_language, $this->_config);
91
92
		/* actual */
93
94
		$actual = $restoreCommand->run('cli');
95
96
		/* compare */
97
98
		$this->assertTrue($actual);
99
	}
100
101
	/**
102
	 * testDatabaseInvalid
103
	 *
104
	 * @since 3.0.0
105
	 */
106
107
	public function testDatabaseInvalid()
108
	{
109
		/* setup */
110
111
		$this->_request->setServer('argv',
112
		[
113
			'console.php',
114
			'restore',
115
			'database',
116
			'--no-interaction'
117
		]);
118
		$restoreCommand = new Command\Restore($this->_registry, $this->_request, $this->_language, $this->_config);
119
120
		/* actual */
121
122
		$actual = $restoreCommand->run('cli');
123
124
		/* compare */
125
126
		$this->assertFalse($actual);
127
	}
128
}
129