misc_pterodactyl-panel/tests/Traits/Http/IntegrationJsonRequestAssertions.php
2018-09-03 15:59:30 -07:00

51 lines
1.6 KiB
PHP

<?php
namespace Tests\Traits\Http;
use Illuminate\Http\Response;
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(Response::HTTP_NOT_FOUND);
$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(Response::HTTP_FORBIDDEN);
$response->assertJsonStructure(['errors' => [['code', 'status', 'detail']]]);
$response->assertJsonCount(1, 'errors');
$response->assertJson([
'errors' => [
[
'code' => 'AccessDeniedHttpException',
'status' => '403',
'detail' => 'This action is unauthorized.',
],
],
], true);
}
}