N
N
nepster-web2015-08-31 14:47:05
PHP
nepster-web, 2015-08-31 14:47:05

Codeception how to check for existence of keys in JSON response?

Here is a test response:

{"code":1,"status":200,"message":"Шаблон ответа","data":{"test-1":1,"test-2":2,"test-3":3}}

I want to test it:
$I = new ApiTester($scenario);
$I->sendGET('test-response');
$I->seeResponseCodeIs(200);
$I->haveHttpHeader('Content-Type','application/json');
$I->seeResponseIsJson();
$I->seeResponseContainsJson([
    'code' => 1,
    'status' => 200,
    'message' => 'Шаблон ответа',
]);

Everything is working well.
And at the same time, how can you check the key and no matter what the content is?
That is:
- That is, I want to make sure that there is a message in the response and it doesn’t matter to me what it is, the main thing is that it be.
- I want to make sure that there is data and this parameter is not empty.
Can I somehow check the response from the server in Codeception for such requests?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Skobkin, 2015-09-07
@skobkin

And is n't that it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question