Nygganh's avatar

Regular expression with seeJson

Hi,

I have this test unit case:

$this->get('/api/v1/books')
            ->seeJson([
                'meta' =>
                [
                    'num' => 1
                ]
             ]);

How can I change this to allow any number for 'num' value? Something like this to illustrate:

$this->get('/api/v1/books')
            ->seeJson([
                'meta' =>
                [
                    'num' => '\d+'
                ]
             ]);

Thanks!

EDIT: Figured it out, ended up doing something like this:

$response = $this->call('GET', '/api/v1/books');
$json = json_decode($response->getContent());

$this->assertTrue(isset($json->meta->num));
$this->assertTrue(is_numeric($json->meta->num));
0 likes
0 replies

Please or to participate in this conversation.