2
我試圖測試一個「名稱」是否實際插入到我的控制器中。在phpunit中使用json POST測試特定元素laravel-4
我創造了這個測試來檢查的「姓名」:
public function testStoreName()
{
$json = '{"name":"FOO", "address":"fubar City", "nickname":"fubar"}';
$post = $this->action('POST', '[email protected]', null, array(), array(), array(), $json);
$output= json_decode($this->client->getResponse()->getContent());
$output->name;
if($output->name != "")
{
echo "Test Passed\n\n";
}
elseif($output->name == "")
{
echo "Name cannot be null";
}
// $this->assertTrue($this->client->getResponse()->isOk());
}
但是,當我改變$ JSON和設置「名稱」:「」;我收到錯誤。我想不必多說,「名字不能爲空