2015-05-15 145 views
2

据:单元测试 - 错误

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

为了通过头,我在$server参数,我做的,像这样将它们设置:

public function testCreateLocation(){ 
    $response = $this->call('POST', '/api/v1/token', $this->test_token_request); 
    $tokenObject = json_decode($response->getContent()); 

    /** Run the test */ 
    $response = $this->call('POST', '/api/v1/location', $this->test_1_create_tag, 
    [], ['Authorization' => 'Bearer '.$tokenObject->token]); 

    /** Read the response */ 
    $this->assertResponseOk(); 
} 

然而,当我运行单元测试时,出现以下错误:

[email protected]:~/Code$ php phpunit.phar tests/LocationModelTest.php 
PHPUnit 4.6.2 by Sebastian Bergmann and contributors. 

Configuration read from /home/vagrant/Code/phpunit.xml.dist 

EFF 

Time: 3.75 seconds, Memory: 35.75Mb 

There was 1 error: 

1) LocationModelTest::testCreateLocation 
InvalidArgumentException: An uploaded file must be an array or an instance of UploadedFile. 

我试过在null和一个空数组,因为它声明,但错误永远不会解决。有人有主意吗?

+0

你在你的控制器/请求/其他方法使用的文件在启动?如果是的话,你应该显示他们的声明 –

+0

@MarcinNabiałek没有,没有文件正在上传。此测试用于检索新的api JWT令牌,然后将其应用于任何后续api调用以测试身份验证。 – LokiSinclair

回答

1

我在Laravel 5.1上遇到了这个问题。有一次,我检查了最新的documentation on the call() method我看到,虽然这个问题:

call(string $method, string $uri, array $parameters = array(), **array $cookies = array(),** array $files = array(), array $server = array(), string $content = null) 

某处一路上一个额外的参数(饼干)了加入方法。

因此增加额外的空数组,你应该是好的:

$response = $this->call('POST', '/api/v1/location', $this->test_1_create_tag, [], [], ['Authorization' => 'Bearer '.$tokenObject->token]);