2014-03-26 82 views
0

嗨,我想设置一个测试来测试我的数据库调用。我想通过在URL中的变量,但似乎无法让它的工作。Laravel - 单元测试

我想做到这一点

public function testDb() 
{ 
       $response = $this->call('GET', '/searchAvailability?keyword=test product'); 
       $content = $response->getContent(); 

      $this->assertEquals('[{"name":"test product"}]',$content); 
} 

但一直收到“未定义的变量:关键字”当我尝试。它运行在浏览器中,而不是当我运行phpunit时。任何人都有任何想法,为什么这不工作谢谢。

回答

1

这里的答案是,你需要在你的call方法不同指定参数:

$this->call('GET', '/searchAvailability', array('keyword' => 'test product')); 

下面是Illuminate\Foundation\Testing\TestCase::call方法的实现:

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