1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wikibase\Lib\Tests; |
4
|
|
|
|
5
|
|
|
use OutOfBoundsException; |
6
|
|
|
use Wikibase\Lib\SettingsArray; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @covers \Wikibase\Lib\SettingsArray |
10
|
|
|
* |
11
|
|
|
* @group Wikibase |
12
|
|
|
* |
13
|
|
|
* @license GPL-2.0-or-later |
14
|
|
|
* @author Jeroen De Dauw < [email protected] > |
15
|
|
|
*/ |
16
|
|
|
class SettingsArrayTest extends \PHPUnit\Framework\TestCase { |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @dataProvider settingProvider |
20
|
|
|
*/ |
21
|
|
|
public function testGetKnownSetting( array $settings ) { |
22
|
|
|
$settingsArray = new SettingsArray( $settings ); |
23
|
|
|
|
24
|
|
|
foreach ( $settingsArray as $settingName => $settingValue ) { |
25
|
|
|
$this->assertEquals( $settingValue, $settingsArray->getSetting( $settingName ) ); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
$this->assertSameSize( $settings, $settingsArray ); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function settingProvider() { |
32
|
|
|
$argLists = []; |
33
|
|
|
|
34
|
|
|
$argLists[] = [ [] ]; |
35
|
|
|
|
36
|
|
|
$argLists[] = [ [ |
37
|
|
|
'foo' => 'bar' |
38
|
|
|
] ]; |
39
|
|
|
|
40
|
|
|
$argLists[] = [ [ |
41
|
|
|
'foo' => 'bar', |
42
|
|
|
'baz' => 'bah', |
43
|
|
|
] ]; |
44
|
|
|
|
45
|
|
|
$argLists[] = [ [ |
46
|
|
|
'foo' => 'bar', |
47
|
|
|
'baz' => 'bah', |
48
|
|
|
'blah' => 'bah', |
49
|
|
|
'nyan' => 1337, |
50
|
|
|
'onoez' => [ 1, 2, 3 ], |
51
|
|
|
'spam' => false, |
52
|
|
|
'hax' => null, |
53
|
|
|
] ]; |
54
|
|
|
|
55
|
|
|
return $argLists; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @dataProvider settingProvider |
60
|
|
|
*/ |
61
|
|
|
public function testGetUnknownSetting( array $settings ) { |
62
|
|
|
$settingsArray = new SettingsArray( $settings ); |
63
|
|
|
|
64
|
|
|
$this->expectException( OutOfBoundsException::class ); |
65
|
|
|
|
66
|
|
|
$settingsArray->getSetting( 'NyanData ALL the way across the sky' ); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @dataProvider settingProvider |
71
|
|
|
*/ |
72
|
|
|
public function testHasSetting( array $settings ) { |
73
|
|
|
$settings = new SettingsArray( $settings ); |
74
|
|
|
|
75
|
|
|
foreach ( array_keys( iterator_to_array( $settings ) ) as $settingName ) { |
76
|
|
|
$this->assertTrue( $settings->hasSetting( $settingName ) ); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$this->assertFalse( $settings->hasSetting( 'I dont think therefore I dont exist' ) ); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @dataProvider settingProvider |
84
|
|
|
*/ |
85
|
|
|
public function testSetSetting( array $settings ) { |
86
|
|
|
$settings = new SettingsArray( $settings ); |
87
|
|
|
|
88
|
|
|
foreach ( $settings as $settingName => $settingValue ) { |
89
|
|
|
$settings->setSetting( $settingName, $settingValue ); |
|
|
|
|
90
|
|
|
$this->assertEquals( $settingValue, $settings->getSetting( $settingName ) ); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
foreach ( $settings as $settingName => $settingValue ) { |
94
|
|
|
$settings->setSetting( $settingName, $settingValue ); |
|
|
|
|
95
|
|
|
$this->assertEquals( $settingValue, $settings->getSetting( $settingName ) ); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
if ( $settings->count() === 0 ) { |
99
|
|
|
$this->assertTrue( true ); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
} |
104
|
|
|
|
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()
method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail()
, this method _has_ side-effects. In the following case, we could not remove the method call: