These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare( strict_types = 1 ); |
||
4 | |||
5 | namespace Diff\Tests\ArrayComparer; |
||
6 | |||
7 | use Diff\ArrayComparer\ArrayComparer; |
||
8 | use Diff\ArrayComparer\OrderedArrayComparer; |
||
9 | use Diff\Tests\DiffTestCase; |
||
10 | |||
11 | /** |
||
12 | * @covers Diff\ArrayComparer\OrderedArrayComparer |
||
13 | * |
||
14 | * @since 0.9 |
||
15 | * |
||
16 | * @group Diff |
||
17 | * |
||
18 | * @license GPL-2.0+ |
||
19 | * @author Jeroen De Dauw < [email protected] > |
||
20 | * @author Tobias Gritschacher < [email protected] > |
||
21 | */ |
||
22 | class OrderedArrayComparerTest extends DiffTestCase { |
||
23 | |||
24 | public function testCanConstruct() { |
||
25 | new OrderedArrayComparer( $this->createMock( 'Diff\Comparer\ValueComparer' ) ); |
||
0 ignored issues
–
show
|
|||
26 | $this->assertTrue( true ); |
||
27 | } |
||
28 | |||
29 | public function testDiffArraysWithComparerThatAlwaysReturnsTrue() { |
||
30 | $valueComparer = $this->createMock( 'Diff\Comparer\ValueComparer' ); |
||
31 | |||
32 | $valueComparer->expects( $this->any() ) |
||
33 | ->method( 'valuesAreEqual' ) |
||
34 | ->will( $this->returnValue( true ) ); |
||
35 | |||
36 | $arrayComparer = new OrderedArrayComparer( $valueComparer ); |
||
0 ignored issues
–
show
$valueComparer is of type object<PHPUnit\Framework\MockObject\MockObject> , but the function expects a object<Diff\Comparer\ValueComparer> .
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...
|
|||
37 | |||
38 | $this->assertNoDifference( |
||
39 | $arrayComparer, |
||
40 | array( 0, 2, 4 ), |
||
41 | array( 1, 2, 9 ) |
||
42 | ); |
||
43 | |||
44 | $this->assertNoDifference( |
||
45 | $arrayComparer, |
||
46 | array( 1, 2, 3 ), |
||
47 | array( 1, 2, 3 ) |
||
48 | ); |
||
49 | |||
50 | $this->assertNoDifference( |
||
51 | $arrayComparer, |
||
52 | array( 'bah' ), |
||
53 | array( 'foo', 'bar', 'baz' ) |
||
54 | ); |
||
55 | |||
56 | $this->assertNoDifference( |
||
57 | $arrayComparer, |
||
58 | array(), |
||
59 | array( 'foo', 'bar', 'baz' ) |
||
60 | ); |
||
61 | |||
62 | $this->assertNoDifference( |
||
63 | $arrayComparer, |
||
64 | array(), |
||
65 | array() |
||
66 | ); |
||
67 | } |
||
68 | |||
69 | private function assertNoDifference( ArrayComparer $arrayComparer, array $arrayOne, array $arrayTwo ) { |
||
70 | $this->assertEquals( |
||
71 | array(), |
||
72 | $arrayComparer->diffArrays( |
||
73 | $arrayOne, |
||
74 | $arrayTwo |
||
75 | ) |
||
76 | ); |
||
77 | } |
||
78 | |||
79 | public function testDiffArraysWithComparerThatAlwaysReturnsFalse() { |
||
80 | $valueComparer = $this->createMock( 'Diff\Comparer\ValueComparer' ); |
||
81 | |||
82 | $valueComparer->expects( $this->any() ) |
||
83 | ->method( 'valuesAreEqual' ) |
||
84 | ->will( $this->returnValue( false ) ); |
||
85 | |||
86 | $arrayComparer = new OrderedArrayComparer( $valueComparer ); |
||
0 ignored issues
–
show
$valueComparer is of type object<PHPUnit\Framework\MockObject\MockObject> , but the function expects a object<Diff\Comparer\ValueComparer> .
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...
|
|||
87 | |||
88 | $this->assertAllDifferent( |
||
89 | $arrayComparer, |
||
90 | array(), |
||
91 | array() |
||
92 | ); |
||
93 | |||
94 | $this->assertAllDifferent( |
||
95 | $arrayComparer, |
||
96 | array( 1, 2, 3 ), |
||
97 | array() |
||
98 | ); |
||
99 | |||
100 | $this->assertAllDifferent( |
||
101 | $arrayComparer, |
||
102 | array( 1, 2, 3 ), |
||
103 | array( 1, 2, 3 ) |
||
104 | ); |
||
105 | |||
106 | $this->assertAllDifferent( |
||
107 | $arrayComparer, |
||
108 | array(), |
||
109 | array( 1, 2, 3 ) |
||
110 | ); |
||
111 | } |
||
112 | |||
113 | private function assertAllDifferent( ArrayComparer $arrayComparer, array $arrayOne, array $arrayTwo ) { |
||
114 | $this->assertEquals( |
||
115 | $arrayOne, |
||
116 | $arrayComparer->diffArrays( |
||
117 | $arrayOne, |
||
118 | $arrayTwo |
||
119 | ) |
||
120 | ); |
||
121 | } |
||
122 | |||
123 | public function testQuantityMattersWithReturnTrue() { |
||
124 | $valueComparer = $this->createMock( 'Diff\Comparer\ValueComparer' ); |
||
125 | |||
126 | $valueComparer->expects( $this->any() ) |
||
127 | ->method( 'valuesAreEqual' ) |
||
128 | ->will( $this->returnValue( true ) ); |
||
129 | |||
130 | $arrayComparer = new OrderedArrayComparer( $valueComparer ); |
||
0 ignored issues
–
show
$valueComparer is of type object<PHPUnit\Framework\MockObject\MockObject> , but the function expects a object<Diff\Comparer\ValueComparer> .
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...
|
|||
131 | |||
132 | $this->assertEquals( |
||
133 | array( 1, 1, 1 ), |
||
134 | $arrayComparer->diffArrays( |
||
135 | array( 1, 1, 1, 1 ), |
||
136 | array( 1 ) |
||
137 | ) |
||
138 | ); |
||
139 | |||
140 | $this->assertEquals( |
||
141 | array( 1 ), |
||
142 | $arrayComparer->diffArrays( |
||
143 | array( 1, 1, 1, 1 ), |
||
144 | array( 1, 1, 1 ) |
||
145 | ) |
||
146 | ); |
||
147 | } |
||
148 | |||
149 | public function testQuantityMattersWithSimpleComparison() { |
||
150 | $valueComparer = $this->createMock( 'Diff\Comparer\ValueComparer' ); |
||
151 | |||
152 | $valueComparer->expects( $this->any() ) |
||
153 | ->method( 'valuesAreEqual' ) |
||
154 | ->will( $this->returnCallback( function( $firstValue, $secondValue ) { |
||
155 | return $firstValue == $secondValue; |
||
156 | } ) ); |
||
157 | |||
158 | $arrayComparer = new OrderedArrayComparer( $valueComparer ); |
||
0 ignored issues
–
show
$valueComparer is of type object<PHPUnit\Framework\MockObject\MockObject> , but the function expects a object<Diff\Comparer\ValueComparer> .
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...
|
|||
159 | |||
160 | $this->assertEquals( |
||
161 | array( 1, 2, 3, 2, 5 ), |
||
162 | $arrayComparer->diffArrays( |
||
163 | array( 1, 1, 2, 3, 2, 5 ), |
||
164 | array( 1, 2, 3, 4 ) |
||
165 | ) |
||
166 | ); |
||
167 | |||
168 | $this->assertEquals( |
||
169 | array( 1, 2 ), |
||
170 | $arrayComparer->diffArrays( |
||
171 | array( 1, 1, 1, 2, 2, 3 ), |
||
172 | array( 1, 1, 2, 2, 3, 3, 3 ) |
||
173 | ) |
||
174 | ); |
||
175 | |||
176 | $this->assertEquals( |
||
177 | array( 3, 1, 2, 1, 1, 2 ), |
||
178 | $arrayComparer->diffArrays( |
||
179 | array( 3, 1, 2, 1, 1, 2 ), |
||
180 | array( 1, 3, 3, 2, 2, 3, 1 ) |
||
181 | ) |
||
182 | ); |
||
183 | } |
||
184 | |||
185 | public function testOrderMattersWithSimpleComparison() { |
||
186 | $valueComparer = $this->createMock( 'Diff\Comparer\ValueComparer' ); |
||
187 | |||
188 | $valueComparer->expects( $this->any() ) |
||
189 | ->method( 'valuesAreEqual' ) |
||
190 | ->will( $this->returnCallback( function( $firstValue, $secondValue ) { |
||
191 | return $firstValue == $secondValue; |
||
192 | } ) ); |
||
193 | |||
194 | $arrayComparer = new OrderedArrayComparer( $valueComparer ); |
||
0 ignored issues
–
show
$valueComparer is of type object<PHPUnit\Framework\MockObject\MockObject> , but the function expects a object<Diff\Comparer\ValueComparer> .
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...
|
|||
195 | |||
196 | $this->assertEquals( |
||
197 | array(), |
||
198 | $arrayComparer->diffArrays( |
||
199 | array( 1, 2, 3, 4, 5 ), |
||
200 | array( 1, 2, 3, 4, 5 ) |
||
201 | ) |
||
202 | ); |
||
203 | |||
204 | $this->assertEquals( |
||
205 | array( 1, 2, 3, 4 ), |
||
206 | $arrayComparer->diffArrays( |
||
207 | array( 1, 2, 3, 4, 5 ), |
||
208 | array( 2, 1, 4, 3, 5 ) |
||
209 | ) |
||
210 | ); |
||
211 | |||
212 | $this->assertEquals( |
||
213 | array( 1, 5 ), |
||
214 | $arrayComparer->diffArrays( |
||
215 | array( 1, 2, 3, 4, 5 ), |
||
216 | array( 5, 2, 3, 4, 1 ) |
||
217 | ) |
||
218 | ); |
||
219 | |||
220 | $this->assertEquals( |
||
221 | array( 1, 2, 3, 4, 5 ), |
||
222 | $arrayComparer->diffArrays( |
||
223 | array( 1, 2, 3, 4, 5 ), |
||
224 | array( 2, 3, 4, 5 ) |
||
225 | ) |
||
226 | ); |
||
227 | |||
228 | $this->assertEquals( |
||
229 | array( 1, 2, 3, 4 ), |
||
230 | $arrayComparer->diffArrays( |
||
231 | array( 1, 2, 3, 4 ), |
||
232 | array( 5, 1, 2, 3, 4 ) |
||
233 | ) |
||
234 | ); |
||
235 | } |
||
236 | |||
237 | public function testValueComparerGetsCalledWithCorrectValues() { |
||
238 | $valueComparer = $this->createMock( 'Diff\Comparer\ValueComparer' ); |
||
239 | |||
240 | $valueComparer->expects( $this->once() ) |
||
241 | ->method( 'valuesAreEqual' ) |
||
242 | ->with( |
||
243 | $this->equalTo( 1 ), |
||
244 | $this->equalTo( 2 ) |
||
245 | ) |
||
246 | ->will( $this->returnValue( true ) ); |
||
247 | |||
248 | $arrayComparer = new OrderedArrayComparer( $valueComparer ); |
||
0 ignored issues
–
show
$valueComparer is of type object<PHPUnit\Framework\MockObject\MockObject> , but the function expects a object<Diff\Comparer\ValueComparer> .
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...
|
|||
249 | |||
250 | $arrayComparer->diffArrays( |
||
251 | array( 1 ), |
||
252 | array( 2 ) |
||
253 | ); |
||
254 | } |
||
255 | |||
256 | } |
||
257 |
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: