2

According to:

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

In order to pass headers, I set them in the $server parameter, which I'm doing like so:

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

However, when I run the unit test, I get the following error:

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.

I've tried passing in null and an empty array as it states, but the error is never resolved. Anyone have any ideas?

2
  • Do you use files in your controller/request/other methods you launch? If yes, you should show their declaration Commented May 15, 2015 at 20:21
  • @MarcinNabiałek Nope, no files are being uploaded. This test was to retrieve a new api JWT token, and then apply that to any subsequent api calls for testing authentication. Commented May 16, 2015 at 21:06

1 Answer 1

2

I ran into this problem on Laravel 5.1 as well. Once I checked the up to date documentation on the call() method I saw the issue though:

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

Somewhere along the way an extra parameter (cookies) got added to the method.

So add an extra empty array and you should be good:

$response = $this->call('POST', '/api/v1/location', $this->test_1_create_tag, [], [], ['Authorization' => 'Bearer '.$tokenObject->token]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.