Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Codeception/Util/JsonType.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ protected function typeComparison(array $data, array $jsonType): string|bool
return $regexes[1][$pos];
}, $filter);

$matched = $matched && $this->matchFilter($filter, (string)$data[$key]);
$matched = $matched && $this->matchFilter($filter, $data[$key]);
}

if ($matched) {
Expand All @@ -186,7 +186,7 @@ protected function typeComparison(array $data, array $jsonType): string|bool
return true;
}

protected function matchFilter(string $filter, string $value)
protected function matchFilter(string $filter, mixed $value)
{
$filter = trim($filter);
if (str_starts_with($filter, '!')) {
Expand All @@ -206,7 +206,7 @@ protected function matchFilter(string $filter, string $value)
}

if (str_starts_with($filter, '=')) {
return $value === substr($filter, 1);
return (string) $value === substr($filter, 1);
}

if ($filter === 'url') {
Expand All @@ -232,7 +232,7 @@ protected function matchFilter(string $filter, string $value)
}

if (preg_match('#^regex\((.*?)\)$#', $filter, $matches)) {
return preg_match($matches[1], $value);
return preg_match($matches[1], (string) $value);
}

if (preg_match('#^>=(-?[\d\.]+)$#', $filter, $matches)) {
Expand Down
7 changes: 5 additions & 2 deletions tests/unit/Codeception/Util/JsonTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ final class JsonTypeTest extends Unit
'name' => 'string|null', // http://codeception.com/docs/modules/REST#seeResponseMatchesJsonType
'user' => [
'url' => 'String:url'
]
],
'empty_array' => 'array',
Comment thread
TavoNiievez marked this conversation as resolved.
];

protected array $data = [
'id' => 11,
'retweeted' => false,
'in_reply_to_screen_name' => null,
'name' => null,
'user' => ['url' => 'http://davert.com']
'user' => ['url' => 'http://davert.com'],
'empty_array' => [],
];

protected function _after()
Expand Down Expand Up @@ -167,6 +169,7 @@ public function testArray()
$this->types['user'] = 'array';
$jsonType = new JsonType($this->data);
$this->assertTrue($jsonType->matches($this->types));
$this->assertTrue($jsonType->matches(['empty_array' => 'array:empty']));
}

public function testNull()
Expand Down