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

[REST] seeResponseContainsJson should not take order into account #1268

Closed
DavertMik opened this issue Aug 4, 2014 · 3 comments
Closed

[REST] seeResponseContainsJson should not take order into account #1268

DavertMik opened this issue Aug 4, 2014 · 3 comments
Milestone

Comments

@DavertMik
Copy link
Member

If I have array response like this

[
{
"id": "33",
"title": "Google",
"created_at": "2014-02-08 03:09:31",
"updated_at": "2014-02-08 03:09:31"
},
{
"id": "34",
"title": "Twitter",
"created_at": "-0001-11-30 00:00:00",
"updated_at": "2014-08-03 14:21:33"
}
]

I should be able to check array values without knowing its keys, so I could check that item I'm looking for is inside of array:

<?php
$I->seeResponseContainsJson([['title' => 'Twitter']]); // should pass
?>

Especially useful if there is root element:

{"companies": [
{
"id": "33",
"title": "Google",
"created_at": "2014-02-08 03:09:31",
"updated_at": "2014-02-08 03:09:31"
},
{
"id": "34",
"title": "Twitter",
"created_at": "-0001-11-30 00:00:00",
"updated_at": "2014-08-03 14:21:33"
}
]
}
<?php
$I->seeResponseContainsJson([['title' => 'Twitter']]); // should pass
$I->seeResponseContainsJson([['title' => 'Twitter'], ['title' => 'Google']]); // should pass
$I->seeResponseContainsJson(['companies' => [['title' => 'Twitter'], ['title' => 'Google']]]); // should pass
?>
@DavertMik DavertMik added this to the 2.0.4 milestone Aug 4, 2014
@Lambik
Copy link

Lambik commented Mar 15, 2016

Actually, in some cases, I would like to have the correct order... for instance when testing that my "order by" query returns the right order

@Naktibalda
Copy link
Member

It would be a backwards compatibility break now.

To achieve your goal, you could use seeXmlResponseMatchesXpath for each item of array.

@uaoleg
Copy link

uaoleg commented Jan 11, 2023

@Lambik you can test sorting in the following way:

$res = $I->sendGet('/api/endpoint');
$json = Json::decode($res);
$I->assertEquals(123, $json[0]['id']);
$I->assertEquals(456, $json[1]['id']);

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

No branches or pull requests

4 participants