Skip to content

Commit 5163b48

Browse files
SvenRtbgcweiske
authored andcommitted
Use assertContainsOnly(InstanceOf) to check type of array elements
1 parent 7f011d3 commit 5163b48

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

tests/ArrayTest.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ public function testMapTypedArray()
3636
);
3737
$this->assertIsArray($sn->typedArray);
3838
$this->assertCount(2, $sn->typedArray);
39-
$this->assertInstanceOf('JsonMapperTest_Simple', $sn->typedArray[0]);
40-
$this->assertInstanceOf('JsonMapperTest_Simple', $sn->typedArray[1]);
39+
$this->assertContainsOnlyInstancesOf(JsonMapperTest_Simple::class, $sn->typedArray);
4140
$this->assertEquals('stringvalue', $sn->typedArray[0]->str);
4241
$this->assertEquals(1.2, $sn->typedArray[1]->fl);
4342
}
@@ -167,8 +166,7 @@ public function testMapArrayObject()
167166
);
168167
$this->assertInstanceOf('ArrayObject', $sn->pArrayObject);
169168
$this->assertCount(2, $sn->pArrayObject);
170-
$this->assertInstanceOf('\stdClass', $sn->pArrayObject[0]);
171-
$this->assertInstanceOf('\stdClass', $sn->pArrayObject[1]);
169+
$this->assertContainsOnlyInstancesOf(stdClass::class, $sn->pArrayObject);
172170
$this->assertEquals('stringvalue', $sn->pArrayObject[0]->str);
173171
$this->assertEquals('1.2', $sn->pArrayObject[1]->fl);
174172
}
@@ -187,8 +185,7 @@ public function testMapTypedArrayObject()
187185
);
188186
$this->assertInstanceOf('ArrayObject', $sn->pTypedArrayObject);
189187
$this->assertCount(2, $sn->pTypedArrayObject);
190-
$this->assertInstanceOf('JsonMapperTest_Simple', $sn->pTypedArrayObject[0]);
191-
$this->assertInstanceOf('JsonMapperTest_Simple', $sn->pTypedArrayObject[1]);
188+
$this->assertContainsOnlyInstancesOf(JsonMapperTest_Simple::class, $sn->pTypedArrayObject);
192189
$this->assertEquals('stringvalue', $sn->pTypedArrayObject[0]->str);
193190
$this->assertEquals('1.2', $sn->pTypedArrayObject[1]->fl);
194191
}
@@ -207,8 +204,7 @@ public function testMapSimpleArrayObject()
207204
);
208205
$this->assertInstanceOf('ArrayObject', $sn->pSimpleArrayObject);
209206
$this->assertCount(2, $sn->pSimpleArrayObject);
210-
$this->assertIsInt($sn->pSimpleArrayObject['eins']);
211-
$this->assertIsInt($sn->pSimpleArrayObject['zwei']);
207+
$this->assertContainsOnly('int', $sn->pSimpleArrayObject, true);
212208
$this->assertEquals(1, $sn->pSimpleArrayObject['eins']);
213209
$this->assertEquals(1, $sn->pSimpleArrayObject['zwei']);
214210
}
@@ -557,9 +553,7 @@ public function testMapArrayFromVariadicFunctionWithObjectType()
557553
$variadicArray = $sn->getVariadicDateTime();
558554

559555
$this->assertCount(2, $variadicArray);
560-
$this->assertIsArray($variadicArray);
561-
$this->assertInstanceOf('DateTime', $variadicArray[0]);
562-
$this->assertInstanceOf('DateTime', $variadicArray[1]);
556+
$this->assertContainsOnlyInstancesOf(DateTime::class, $variadicArray);
563557
$this->assertEquals(
564558
'2014-01-02', $variadicArray[0]->format('Y-m-d')
565559
);

0 commit comments

Comments
 (0)