Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.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

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 Laravel5中的单元测试-错误_Php_Unit Testing_Phpunit_Laravel 5 - Fatal编程技术网

Php Laravel5中的单元测试-错误

Php Laravel5中的单元测试-错误,php,unit-testing,phpunit,laravel-5,Php,Unit Testing,Phpunit,Laravel 5,根据: /** * 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 $changeHis

根据:

/**
 * 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();
}
但是,当我运行单元测试时,会出现以下错误:

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上也遇到了这个问题。检查最新版本后,我发现了问题:

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]);

您是否在控制器/请求/其他启动方法中使用文件?如果是,你应该展示他们的declaration@MarcinNabiałek没有,没有上传任何文件。这个测试是为了检索一个新的api JWT令牌,然后将其应用于任何后续的api调用以测试身份验证。