Skip to content

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

@zheltikov

Description

@zheltikov

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions