Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 单元测试_Php_Unit Testing_Laravel_Phpunit - Fatal编程技术网

Php 单元测试

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-

嗨,我正在尝试设置一个测试来测试我的数据库调用。我想在url中传递一个变量,但似乎无法让它工作

我想这么做

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();
}