First go at integration tests
This commit is contained in:
parent
89db9390df
commit
e2aa01c9cc
16 changed files with 610 additions and 28 deletions
50
tests/Traits/Http/IntegrationJsonRequestAssertions.php
Normal file
50
tests/Traits/Http/IntegrationJsonRequestAssertions.php
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Traits;
|
||||
|
||||
use Illuminate\Foundation\Testing\TestResponse;
|
||||
|
||||
trait IntegrationJsonRequestAssertions
|
||||
{
|
||||
/**
|
||||
* Make assertions about a 404 response on the API.
|
||||
*
|
||||
* @param \Illuminate\Foundation\Testing\TestResponse $response
|
||||
*/
|
||||
public function assertNotFoundJson(TestResponse $response)
|
||||
{
|
||||
$response->assertStatus(404);
|
||||
$response->assertJsonStructure(['errors' => [['code', 'status', 'detail']]]);
|
||||
$response->assertJsonCount(1, 'errors');
|
||||
$response->assertJson([
|
||||
'errors' => [
|
||||
[
|
||||
'code' => 'NotFoundHttpException',
|
||||
'status' => '404',
|
||||
'detail' => 'The requested resource does not exist on this server.',
|
||||
],
|
||||
],
|
||||
], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make assertions about a 403 error returned by the API.
|
||||
*
|
||||
* @param \Illuminate\Foundation\Testing\TestResponse $response
|
||||
*/
|
||||
public function assertAccessDeniedJson(TestResponse $response)
|
||||
{
|
||||
$response->assertStatus(403);
|
||||
$response->assertJsonStructure(['errors' => [['code', 'status', 'detail']]]);
|
||||
$response->assertJsonCount(1, 'errors');
|
||||
$response->assertJson([
|
||||
'errors' => [
|
||||
[
|
||||
'code' => 'AccessDeniedHttpException',
|
||||
'status' => '403',
|
||||
'detail' => 'This action is unauthorized.',
|
||||
],
|
||||
],
|
||||
], true);
|
||||
}
|
||||
}
|
Reference in a new issue