Skip to content
Steve Axtmann edited this page Apr 28, 2015 · 6 revisions

If you wish to test your APIs, Integrated can assist you!

Please note that, temporarily, the following method calls are exclusive to the Laravel extension. This will change soon.

get($uri) or hit($uri)

Make a GET request to the given URI.

$this->get('/some-endpoint')
     ->seeJson();

post($uri, array $data)

Make a POST request to the given URI, and pass through any optional parameters.

$this->post('/some-endpoint', ['name' => 'joe']);

put($uri, array $data)

Make a PUT request to the given URI, and pass through the applicable data.

$this->put('/some-endpoint', ['name' => 'joe']);

patch($uri, array $data)

Make a PATCH request to the given URI, and pass through the applicable data.

$this->patch('/some-endpoint', ['name' => 'joe']);

delete($uri)

Make a DELETE request to the given URI.

$this->delete('/posts/1');

seeJson() or seeIsJson()

Assert that the last response is JSON (and not HTML, a string, etc.).

$this->get('/api/posts')
     ->seeJson();

seeStatusCode($code) or seeStatusCodeIs($code)

$this->get('/api/posts')
     ->seeStatusCode(200);

Ensure that the status code from the previous request matches what you provide.

seeJsonEquals($expected)

Assert that the returned JSON from the last response is equal to the provided JSON or array. If an array is provided, Integrated will json_encode it for you automatically to perform the comparison.

$this->get('/api/posts')
     ->seeJsonEquals(['title' => 'Foo', 'body' => 'Bar']);

seeJsonContains($expected)

$this->get('/api/posts')
     ->seeJsonContains(['title' => 'Foo']);

Assert that the returned JSON from the last response matches the provided array.

withHeaders(array $headers)

$this->withHeaders(['Accept' => 'application/json'])
     ->get('/api/posts');

Adds the given headers to the request. It will merge with any headers that have already been set. This has to be called before you make the request.

Gotcha

Trying to make a POST request, but keep getting a VerifyCsrfToken error? While this may be resolved in a future release of Laravel 5, in the meantime, update app/Http/Middleware/VerifyCsrfToken.php, like so:

public function handle($request, Closure $next)
{
	if (app()->environment() == 'testing') {
		return $next($request);
	}

	return parent::handle($request, $next);
}

That should do it!