Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonType no longer supports "array:empty" constraints. #100

Open
zheltikov opened this issue Mar 14, 2024 · 0 comments
Open

JsonType no longer supports "array:empty" constraints. #100

zheltikov opened this issue Mar 14, 2024 · 0 comments

Comments

@zheltikov
Copy link

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: 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant