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\StrategicArrayComparer; |
||
9 | use Diff\Tests\DiffTestCase; |
||
10 | |||
11 | /** |
||
12 | * @covers Diff\ArrayComparer\StrategicArrayComparer |
||
13 | * |
||
14 | * @group Diff |
||
15 | * |
||
16 | * @license GPL-2.0+ |
||
17 | * @author Jeroen De Dauw < [email protected] > |
||
18 | */ |
||
19 | class StrategicArrayComparerTest extends DiffTestCase { |
||
20 | |||
21 | public function testCanConstruct() { |
||
22 | new StrategicArrayComparer( $this->createMock( 'Diff\Comparer\ValueComparer' ) ); |
||
0 ignored issues
–
show
|
|||
23 | $this->assertTrue( true ); |
||
24 | } |
||
25 | |||
26 | public function testDiffArraysWithComparerThatAlwaysReturnsTrue() { |
||
27 | $valueComparer = $this->createMock( 'Diff\Comparer\ValueComparer' ); |
||
28 | |||
29 | $valueComparer->expects( $this->any() ) |
||
30 | ->method( 'valuesAreEqual' ) |
||
31 | ->will( $this->returnValue( true ) ); |
||
32 | |||
33 | $arrayComparer = new StrategicArrayComparer( $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...
|
|||
34 | |||
35 | $this->assertNoDifference( |
||
36 | $arrayComparer, |
||
37 | array( 0, 2, 4 ), |
||
38 | array( 1, 2, 9 ) |
||
39 | ); |
||
40 | |||
41 | $this->assertNoDifference( |
||
42 | $arrayComparer, |
||
43 | array( 1, 2, 3 ), |
||
44 | array( 1, 2, 3 ) |
||
45 | ); |
||
46 | |||
47 | $this->assertNoDifference( |
||
48 | $arrayComparer, |
||
49 | array( 'bah' ), |
||
50 | array( 'foo', 'bar', 'baz' ) |
||
51 | ); |
||
52 | |||
53 | $this->assertNoDifference( |
||
54 | $arrayComparer, |
||
55 | array(), |
||
56 | array( 'foo', 'bar', 'baz' ) |
||
57 | ); |
||
58 | |||
59 | $this->assertNoDifference( |
||
60 | $arrayComparer, |
||
61 | array(), |
||
62 | array() |
||
63 | ); |
||
64 | } |
||
65 | |||
66 | private function assertNoDifference( ArrayComparer $arrayComparer, array $arrayOne, array $arrayTwo ) { |
||
67 | $this->assertEquals( |
||
68 | array(), |
||
69 | $arrayComparer->diffArrays( |
||
70 | $arrayOne, |
||
71 | $arrayTwo |
||
72 | ) |
||
73 | ); |
||
74 | } |
||
75 | |||
76 | public function testDiffArraysWithComparerThatAlwaysReturnsFalse() { |
||
77 | $valueComparer = $this->createMock( 'Diff\Comparer\ValueComparer' ); |
||
78 | |||
79 | $valueComparer->expects( $this->any() ) |
||
80 | ->method( 'valuesAreEqual' ) |
||
81 | ->will( $this->returnValue( false ) ); |
||
82 | |||
83 | $arrayComparer = new StrategicArrayComparer( $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...
|
|||
84 | |||
85 | $this->assertAllDifferent( |
||
86 | $arrayComparer, |
||
87 | array(), |
||
88 | array() |
||
89 | ); |
||
90 | |||
91 | $this->assertAllDifferent( |
||
92 | $arrayComparer, |
||
93 | array( 1, 2, 3 ), |
||
94 | array() |
||
95 | ); |
||
96 | |||
97 | $this->assertAllDifferent( |
||
98 | $arrayComparer, |
||
99 | array( 1, 2, 3 ), |
||
100 | array( 1, 2, 3 ) |
||
101 | ); |
||
102 | |||
103 | $this->assertAllDifferent( |
||
104 | $arrayComparer, |
||
105 | array(), |
||
106 | array( 1, 2, 3 ) |
||
107 | ); |
||
108 | } |
||
109 | |||
110 | private function assertAllDifferent( ArrayComparer $arrayComparer, array $arrayOne, array $arrayTwo ) { |
||
111 | $this->assertEquals( |
||
112 | $arrayOne, |
||
113 | $arrayComparer->diffArrays( |
||
114 | $arrayOne, |
||
115 | $arrayTwo |
||
116 | ) |
||
117 | ); |
||
118 | } |
||
119 | |||
120 | public function testQuantityMattersWithReturnTrue() { |
||
121 | $valueComparer = $this->createMock( 'Diff\Comparer\ValueComparer' ); |
||
122 | |||
123 | $valueComparer->expects( $this->any() ) |
||
124 | ->method( 'valuesAreEqual' ) |
||
125 | ->will( $this->returnValue( true ) ); |
||
126 | |||
127 | $arrayComparer = new StrategicArrayComparer( $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...
|
|||
128 | |||
129 | $this->assertEquals( |
||
130 | array( 1, 1, 1 ), |
||
131 | $arrayComparer->diffArrays( |
||
132 | array( 1, 1, 1, 1 ), |
||
133 | array( 1 ) |
||
134 | ) |
||
135 | ); |
||
136 | |||
137 | $this->assertEquals( |
||
138 | array( 1 ), |
||
139 | $arrayComparer->diffArrays( |
||
140 | array( 1, 1, 1, 1 ), |
||
141 | array( 1, 1, 1 ) |
||
142 | ) |
||
143 | ); |
||
144 | } |
||
145 | |||
146 | public function testQuantityMattersWithSimpleComparison() { |
||
147 | $valueComparer = $this->createMock( 'Diff\Comparer\ValueComparer' ); |
||
148 | |||
149 | $valueComparer->expects( $this->any() ) |
||
150 | ->method( 'valuesAreEqual' ) |
||
151 | ->will( $this->returnCallback( function( $firstValue, $secondValue ) { |
||
152 | return $firstValue == $secondValue; |
||
153 | } ) ); |
||
154 | |||
155 | $arrayComparer = new StrategicArrayComparer( $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...
|
|||
156 | |||
157 | $this->assertEquals( |
||
158 | array( 1, 2, 5 ), |
||
159 | $arrayComparer->diffArrays( |
||
160 | array( 1, 1, 2, 3, 2, 5 ), |
||
161 | array( 1, 2, 3, 4 ) |
||
162 | ) |
||
163 | ); |
||
164 | |||
165 | $this->assertEquals( |
||
166 | array( 1 ), |
||
167 | $arrayComparer->diffArrays( |
||
168 | array( 1, 1, 1, 2, 2, 3 ), |
||
169 | array( 1, 1, 2, 2, 3, 3, 3 ) |
||
170 | ) |
||
171 | ); |
||
172 | |||
173 | $this->assertEquals( |
||
174 | array( 1 ), |
||
175 | $arrayComparer->diffArrays( |
||
176 | array( 3, 1, 2, 1, 1, 2 ), |
||
177 | array( 1, 3, 3, 2, 2, 3, 1 ) |
||
178 | ) |
||
179 | ); |
||
180 | } |
||
181 | |||
182 | public function testValueComparerGetsCalledWithCorrectValues() { |
||
183 | $valueComparer = $this->createMock( 'Diff\Comparer\ValueComparer' ); |
||
184 | |||
185 | $valueComparer->expects( $this->once() ) |
||
186 | ->method( 'valuesAreEqual' ) |
||
187 | ->with( |
||
188 | $this->equalTo( 1 ), |
||
189 | $this->equalTo( 2 ) |
||
190 | ) |
||
191 | ->will( $this->returnValue( true ) ); |
||
192 | |||
193 | $arrayComparer = new StrategicArrayComparer( $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...
|
|||
194 | |||
195 | $arrayComparer->diffArrays( |
||
196 | array( 1 ), |
||
197 | array( 2 ) |
||
198 | ); |
||
199 | } |
||
200 | |||
201 | } |
||
202 |
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: