module-rest icon indicating copy to clipboard operation
module-rest copied to clipboard

JsonType no longer supports "array:empty" constraints.

Open zheltikov opened this issue 3 months ago • 0 comments

When upgrading packages, I recently found out that JsonType no longer supports the "somekey" => "array:empty" constraint. The tests which use this constraint fail due to a warning emitted: "Array to string conversion".

After some investigation, I found that this conversion warning is emitted here: https://github.com/Codeception/module-rest/blob/master/src/Codeception/Util/JsonType.php#L173

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

This (string) cast is the cause of the warning. This typecast was introduced when migrating the codebase to PHP 7.4, here: https://github.com/Codeception/module-rest/commit/da2666b9#diff-5f18b614b32e2a743f0b10105d11c820ed509f8e52e68fd770666988143ae44dL172-R178

Because of this I was forced to downgrade this package to ^1.4.

I think that there should be no typecast at all, i.e. the $value argument to matchFilter(...) should have no type annotation (or mixed) and it should be checked to be a string in the filters that really need it.

Otherwise, we cannot test non-string values to match a type, which seems incorrect.

zheltikov avatar Mar 14 '24 19:03 zheltikov