Completed
Push — master ( 03d7de...dc9399 )
by Henry
06:00
created

tests/phpunit/Console/Command/SettingTest.php (3 issues)

Labels
Severity

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
7
/**
8
 * SettingTest
9
 *
10
 * @since 3.0.0
11
 *
12
 * @package Redaxscript
13
 * @category Tests
14
 * @author Henry Ruhs
15
 */
16
17
class SettingTest extends TestCaseAbstract
18
{
19
	/**
20
	 * setUp
21
	 *
22
	 * @since 3.1.0
23
	 */
24
25
	public function setUp()
26
	{
27
		parent::setUp();
28
		$installer = $this->installerFactory();
29
		$installer->init();
30
		$installer->rawCreate();
31
		$installer->insertSettings(
32
		[
33
			'adminName' => 'Test',
34
			'adminUser' => 'test',
35
			'adminPassword' => 'test',
36
			'adminEmail' => '[email protected]'
37
		]);
38
	}
39
40
	/**
41
	 * tearDown
42
	 *
43
	 * @since 3.1.0
44
	 */
45
46
	public function tearDown()
47
	{
48
		$installer = $this->installerFactory();
49
		$installer->init();
50
		$installer->rawDrop();
51
		$this->_request->setServer('argv', null);
52
	}
53
54
	/**
55
	 * testNoArgument
56
	 *
57
	 * @since 3.0.0
58
	 */
59
60
	public function testNoArgument()
61
	{
62
		/* setup */
63
64
		$settingCommand = new Command\Setting($this->_registry, $this->_request, $this->_language, $this->_config);
65
66
		/* expect and actual */
67
68
		$expect = $settingCommand->getHelp();
69
		$actual = $settingCommand->run('cli');
70
71
		/* compare */
72
73
		$this->assertEquals($expect, $actual);
74
	}
75
76
	/**
77
	 * testList
78
	 *
79
	 * @since 3.0.0
80
	 */
81
82
	public function testList()
83
	{
84
		/* setup */
85
86
		$this->_request->setServer('argv',
87
		[
88
			'console.php',
89
			'setting',
90
			'list'
91
		]);
92
		$settingCommand = new Command\Setting($this->_registry, $this->_request, $this->_language, $this->_config);
93
94
		/* actual */
95
96
		$actual = $settingCommand->run('cli');
97
98
		/* compare */
99
100
		$this->assertString($actual);
0 ignored issues
show
It seems like $actual defined by $settingCommand->run('cli') on line 96 can also be of type boolean; however, Redaxscript\Tests\TestCaseAbstract::assertString() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
101
	}
102
103
	/**
104
	 * testSet
105
	 *
106
	 * @since 3.0.0
107
	 */
108
109
	public function testSet()
110
	{
111
		/* setup */
112
113
		$this->_request->setServer('argv',
114
		[
115
			'console.php',
116
			'setting',
117
			'set',
118
			'--key',
119
			'copyright',
120
			'--value',
121
			'Redaxscript'
122
		]);
123
		$settingCommand = new Command\Setting($this->_registry, $this->_request, $this->_language, $this->_config);
124
125
		/* actual */
126
127
		$actual = $settingCommand->run('cli');
128
129
		/* compare */
130
131
		$this->assertTrue($actual);
0 ignored issues
show
It seems like $actual defined by $settingCommand->run('cli') on line 127 can also be of type null or string; however, PHPUnit\Framework\Assert::assertTrue() does only seem to accept boolean, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
132
	}
133
134
	/**
135
	 * testSetInvalid
136
	 *
137
	 * @since 3.0.0
138
	 */
139
140
	public function testSetInvalid()
141
	{
142
		/* setup */
143
144
		$this->_request->setServer('argv',
145
		[
146
			'console.php',
147
			'setting',
148
			'set',
149
			'--no-interaction'
150
		]);
151
		$settingCommand = new Command\Setting($this->_registry, $this->_request, $this->_language, $this->_config);
152
153
		/* actual */
154
155
		$actual = $settingCommand->run('cli');
156
157
		/* compare */
158
159
		$this->assertFalse($actual);
0 ignored issues
show
It seems like $actual defined by $settingCommand->run('cli') on line 155 can also be of type null or string; however, PHPUnit\Framework\Assert::assertFalse() does only seem to accept boolean, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
160
	}
161
}
162