Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

JsonContains mismatches nested sequential array #61

Open
@jumale

Description

@jumale

Hi,
I'm not sure if it's a bug or expected behaviour.

This example matches correctly:

<?php
$actualJson = [
    'foo' => [
        'bar' => ['cat', 'dog']
    ]
];

$expectedJson = ['cat', 'dog'];

(new JsonContains($expectedJson))->evaluate(json_encode($actualJson));
// success

While this example fails - it can not match a sequential array when it's inside of another sequential array:

<?php
$actualJson = [
    'foo' => [
        ['cat', 'dog']
    ]
];

$expectedJson = ['cat', 'dog'];

(new JsonContains($expectedJson))->evaluate(json_encode($actualJson));
// failed

There is a workaround to wrap the expected value in an array one more time, but still looks weird that it does not work in the example above.

<?php
$actualJson = [
    'foo' => [
        ['some noise'],
        ['cat', 'dog'],
        ['some noise'],
    ]
];

$expectedJson = [['cat', 'dog']];

(new JsonContains($expectedJson))->evaluate(json_encode($actualJson));
// success

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions