Skip to content

Commit 1cdcf47

Browse files
NaktibaldaDavertMik
authored andcommitted
[REST] Fixed JsonType crash when key 0 is not an array (#4532)
1 parent 7d89a11 commit 1cdcf47

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/Codeception/Util/JsonType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ public static function cleanCustomFilters()
9696
*/
9797
public function matches(array $jsonType)
9898
{
99-
if (array_key_exists(0, $this->jsonArray)) {
100-
// sequential array
99+
if (array_key_exists(0, $this->jsonArray) && is_array($this->jsonArray[0])) {
100+
// a list of items
101101
$msg = '';
102102
foreach ($this->jsonArray as $array) {
103103
$res = $this->typeComparison($array, $jsonType);

tests/unit/Codeception/Util/JsonTypeTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,22 @@ public function testCollection()
186186
$this->assertContains('3` is of type `integer:<3', $res);
187187
$this->assertContains('5` is of type `integer:<3', $res);
188188
}
189+
190+
/**
191+
* @issue https://github.com/Codeception/Codeception/issues/4517
192+
*/
193+
public function testMatchesArrayReturnedByFetchBoth()
194+
{
195+
$jsonType = new JsonType([
196+
'0' => 10,
197+
'a' => 10,
198+
'1' => 11,
199+
'b' => 11,
200+
]);
201+
202+
$this->assertTrue($jsonType->matches([
203+
'a' => 'integer',
204+
'b' => 'integer',
205+
]));
206+
}
189207
}

0 commit comments

Comments
 (0)