在laravel phpunit中测试一个数组

时间:2016-09-04 01:43:30

标签: laravel testing phpunit

我在laravel中有一个数组输出,结构如下:

array:1 [
  0 => {#35
    +"id": 152
    +"user_id": 123
    +"post_id": 456
    +"content": "impedit"
    +"created_at": "04-09-2016 01:24"
    +"updated_at": "2016-09-04 01:24:51"
  }
]

如何测试数组结构包含键iduser_id ...?

我尝试了assertArrayHasKey('user_id',$ array),但显示失败。 感谢。

1 个答案:

答案 0 :(得分:1)

感谢@linuxartisan。最后,我将value对象转换为数组进行测试。

$this->assertArrayHasKey('user_id', (array)$comment[0]);