2
2
3
3
namespace Sevavietl \Arrays \Tests \Unit ;
4
4
5
+ use PHPUnit \Framework \TestCase ;
5
6
use Sevavietl \Arrays \CompositeKeyArray ;
6
7
use Sevavietl \Arrays \UndefinedOffsetException ;
7
8
8
- class CompositeKeyArrayTest extends \ TestCase
9
+ class CompositeKeyArrayTest extends TestCase
9
10
{
10
11
/**
11
12
* @dataProvider arrayDataProviderForIssetTesting
12
13
*/
13
- public function testOffsetExists ($ array , $ offset , $ exists )
14
+ public function testOffsetExists ($ array , $ offset , bool $ exists ): void
14
15
{
15
16
$ array = new CompositeKeyArray ($ array );
16
17
17
- $ this ->assertEquals (
18
- $ exists ,
19
- isset ($ array [$ offset ])
20
- );
18
+ $ this ->assertEquals ($ exists , isset ($ array [$ offset ]));
21
19
}
22
20
23
- public function arrayDataProviderForIssetTesting ()
21
+ public function arrayDataProviderForIssetTesting (): array
24
22
{
25
23
return [
26
24
[[1 ], 0 , true ],
@@ -41,17 +39,14 @@ public function arrayDataProviderForIssetTesting()
41
39
/**
42
40
* @dataProvider arrayDataProviderForGetTesting
43
41
*/
44
- public function testOffsetGet ($ array , $ offset , $ value )
42
+ public function testOffsetGet ($ array , $ offset , $ value ): void
45
43
{
46
44
$ array = new CompositeKeyArray ($ array );
47
45
48
- $ this ->assertEquals (
49
- $ value ,
50
- $ array [$ offset ]
51
- );
46
+ $ this ->assertEquals ($ value , $ array [$ offset ]);
52
47
}
53
48
54
- public function arrayDataProviderForGetTesting ()
49
+ public function arrayDataProviderForGetTesting (): array
55
50
{
56
51
return [
57
52
[[1 ], 0 , 1 ],
@@ -63,11 +58,10 @@ public function arrayDataProviderForGetTesting()
63
58
];
64
59
}
65
60
66
- /**
67
- * @expectedException Sevavietl\Arrays\UndefinedOffsetException
68
- */
69
- public function testOffsetGetThrowsException ()
61
+ public function testOffsetGetThrowsException (): void
70
62
{
63
+ $ this ->expectException (UndefinedOffsetException::class);
64
+
71
65
$ array = new CompositeKeyArray ();
72
66
73
67
$ value = $ array [['foo ' , 'bar ' ]];
@@ -76,72 +70,52 @@ public function testOffsetGetThrowsException()
76
70
/**
77
71
* @dataProvider arrayDataProviderForSetTesting
78
72
*/
79
- public function testOffsetSet ($ array , $ offset , $ value )
73
+ public function testOffsetSet ($ array , $ offset , $ value ): void
80
74
{
81
75
$ array = new CompositeKeyArray ($ array );
82
-
83
76
$ array [$ offset ] = $ value ;
84
77
85
- $ this ->assertEquals (
86
- $ value ,
87
- $ array [$ offset ]
88
- );
78
+ $ this ->assertEquals ($ value , $ array [$ offset ]);
89
79
}
90
80
91
- public function arrayDataProviderForSetTesting ()
81
+ public function arrayDataProviderForSetTesting (): array
92
82
{
93
83
return [
94
84
[[], 0 , 1 ],
95
85
[[], [0 , 1 ], 2 ],
96
86
];
97
87
}
98
88
99
- public function testOffsetSetEdgeCases ()
89
+ public function testOffsetSetEdgeCases (): void
100
90
{
101
91
$ array = new CompositeKeyArray ();
102
-
103
92
$ array [[[]]] = 'foo ' ;
104
93
105
- $ this ->assertEquals (
106
- 'foo ' ,
107
- $ array [0 ]
108
- );
94
+ $ this ->assertEquals ('foo ' , $ array [0 ]);
109
95
110
96
$ array = new CompositeKeyArray ();
111
-
112
97
$ array [[1 , [], 2 ]] = 3 ;
113
98
114
- $ this ->assertEquals (
115
- 3 ,
116
- $ array [[1 , 0 , 2 ]]
117
- );
99
+ $ this ->assertEquals (3 , $ array [[1 , 0 , 2 ]]);
118
100
119
101
$ array = new CompositeKeyArray ();
120
-
121
102
$ array [[1 , [], [], [], 2 ]] = 3 ;
122
103
123
- $ this ->assertEquals (
124
- 3 ,
125
- $ array [[1 , 0 , 0 , 0 , 2 ]]
126
- );
104
+ $ this ->assertEquals (3 , $ array [[1 , 0 , 0 , 0 , 2 ]]);
127
105
}
128
106
129
107
/**
130
108
* @dataProvider arrayDataProviderForUnsetTesting
131
109
*/
132
- public function testOffsetUnset ($ array , $ offset , $ arrayAfterUnset )
110
+ public function testOffsetUnset ($ array , $ offset , $ arrayAfterUnset ): void
133
111
{
134
112
$ array = new CompositeKeyArray ($ array );
135
-
136
113
unset($ array [$ offset ]);
137
114
138
- $ this ->assertEquals (
139
- $ arrayAfterUnset ,
140
- $ array ->toArray ()
141
- );
115
+ $ this ->assertEquals ($ arrayAfterUnset , $ array ->toArray ());
142
116
}
143
117
144
- public function arrayDataProviderForUnsetTesting ()
118
+ public function arrayDataProviderForUnsetTesting (): array
145
119
{
146
120
return [
147
121
[[1 ], 0 , []],
@@ -157,7 +131,7 @@ public function arrayDataProviderForUnsetTesting()
157
131
];
158
132
}
159
133
160
- public function testItIsIterable ()
134
+ public function testItIsIterable (): void
161
135
{
162
136
$ arr = new CompositeKeyArray ($ initial = [
163
137
'foo ' => ['bar ' => ['baz ' ]],
0 commit comments