2014-03-26 3 views
0

안녕하세요, 내 데이터베이스 호출을 테스트하는 테스트를 설정하려고합니다. url에서 변수를 전달하려고하지만 위선적으로 작동하지 않는 것 같습니다. Laravel - unit testing

나는이

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

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

을하고 싶어하지만 난 점점 계속 : 내가하려고 할 때 "정의되지 않은 변수 키워드를". 브라우저에서 phpunit을 실행하지 않을 때만 작동합니다. 누구나 왜 감사하지 않는지에 대한 아이디어가 있습니다.

답변

1

여기에서의 대답은 당신이 당신의 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(); 
} 
: 아래

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

Illuminate\Foundation\Testing\TestCase::call 방법의 구현