forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntegrationJsonRequestAssertions.php
More file actions
51 lines (47 loc) · 1.53 KB
/
IntegrationJsonRequestAssertions.php
File metadata and controls
51 lines (47 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace Tests\Traits\Http;
use Illuminate\Http\Response;
use Illuminate\Testing\TestResponse;
trait IntegrationJsonRequestAssertions
{
/**
* Make assertions about a 404 response on the API.
*
* @param \Illuminate\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\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);
}
}