根据:
/**
* 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()
为了传递 header ,我将它们设置在 $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();
}
但是,当我运行单元测试时,出现以下错误:
vagrant@homestead:~/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
和一个空数组,但错误从未解决。大家有什么想法吗?
最佳答案
我在 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)
在此过程中,一个额外的参数(cookies)被添加到该方法中。
所以添加一个额外的空数组,你应该会很好:
$response = $this->call('POST', '/api/v1/location', $this->test_1_create_tag, [], [], ['Authorization' => 'Bearer '.$tokenObject->token]);
关于php - Laravel5 中的单元测试 - 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30262240/