Php 单元测试
嗨,我正在尝试设置一个测试来测试我的数据库调用。我想在url中传递一个变量,但似乎无法让它工作 我想这么做Php 单元测试,php,unit-testing,laravel,phpunit,Php,Unit Testing,Laravel,Phpunit,嗨,我正在尝试设置一个测试来测试我的数据库调用。我想在url中传递一个变量,但似乎无法让它工作 我想这么做 public function testDb() { $response = $this->call('GET', '/searchAvailability?keyword=test product'); $content = $response->getContent(); $this-
public function testDb()
{
$response = $this->call('GET', '/searchAvailability?keyword=test product');
$content = $response->getContent();
$this->assertEquals('[{"name":"test product"}]',$content );
}
但当我尝试时,我总是得到“未定义变量:关键字”。它在浏览器中工作,但在运行phpunit时不起作用。任何人都知道为什么这不起作用了,谢谢。这里的答案是您需要在
调用中以不同的方式指定参数:
$this->call('GET', '/searchAvailability', array('keyword' => 'test product'));
/**
* Call the given URI and return the Response.
*
* @param string $method
* @param string $uri
* @param array $parameters
* @param array $files
* @param array $server
* @param string $content
* @param bool $changeHistory
* @return \Illuminate\Http\Response
*/
public function call()
{
call_user_func_array(array($this->client, 'request'), func_get_args());
return $this->client->getResponse();
}
下面是illumb\Foundation\Testing\TestCase::call
方法的实现:
$this->call('GET', '/searchAvailability', array('keyword' => 'test product'));
/**
* Call the given URI and return the Response.
*
* @param string $method
* @param string $uri
* @param array $parameters
* @param array $files
* @param array $server
* @param string $content
* @param bool $changeHistory
* @return \Illuminate\Http\Response
*/
public function call()
{
call_user_func_array(array($this->client, 'request'), func_get_args());
return $this->client->getResponse();
}