【发布时间】:2016-04-15 10:17:30
【问题描述】:
我目前正在为我的 API 编写一些测试,我很想知道是否有更好的方法来处理这个问题,因为我觉得这是“hacky”的做事方式。
下面的代码示例:
public function testListingOfAllUsers()
{
$users = $this->createUsers();
$client = $this->createClient();
$client->request("GET", "/users/");
$response = $client->getResponse();
$content = $response->getContent();
$decodedContent = json_decode($content);
$this->assertTrue($response->isOk());
$this->assertInternalType("array", $decodedContent->data);
$this->assertCount(count($users), $decodedContent->data);
foreach ($decodedContent->data as $data) {
$this->assertObjectHasAttribute("attributes", $data);
$this->assertEquals("users", $data->type);
}
}
我想知道是否有更好的方法来测试我的 API 是否符合 JSON API 规范。开导我!我很确定 PHPUnit 不是我的答案。
【问题讨论】:
标签: php json phpunit integration-testing silex