larsemil
larsemil

Reputation: 876

Unit Testing JSON responses in Laravel

I do:

$this->post('/v1/customer', ['area' => 'kil'])
        ->seeJson(['created' => true]);

But instead of created => true, I would like to do "NOT STATEMENTS". Ex: parent!=null or created_at > '0000-00-00'

How can this be achieved?

Upvotes: 0

Views: 808

Answers (1)

J.T. Grimes
J.T. Grimes

Reputation: 4272

Laravel does have a dontSeeJson function which would solve both of the examples you've listed (though possibly not a more general case) --

$this->dontSeeJson(['parent' => null]);

$this->dontSeeJson(['created_at' => '0000-00-00']);

If you need something more specific, I agree with @gontrollez - decode the json (json_decode($this->response->getContent(), true)) and test that.

Upvotes: 1

Related Questions