2

I'm trying to write a PHPUnit test which asserts that the array I am testing has the correct keys.

$structure = ['title', 'message', 'action'];
$structure = array_flip($structure);
$result = array_diff_key($structure, $response);

$this->assertEquals($result, []);

This test works, but there must be a cleaner way to do this with PHPUnit 4.8?

1 Answer 1

1

You should write an asserting for each key:

$this->assertArrayHasKey('key', $response);  
$this->assertArrayHasKey('message', $response); 
$this->assertArrayHasKey('action', $response);

Hope this help

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.