File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 12
12
use Illuminate \Support \Collection ;
13
13
use Neomerx \JsonApi \Contracts \Document \DocumentInterface as Keys ;
14
14
use Neomerx \JsonApi \Contracts \Http \Headers \MediaTypeInterface ;
15
+ use PHPUnit \Framework \Assert as PHPUnit ;
15
16
use RuntimeException ;
16
17
17
18
class TestResponse extends BaseTestResponse
@@ -56,6 +57,26 @@ public function assertJsonApiResponse(
56
57
return $ this ;
57
58
}
58
59
60
+ /**
61
+ * Assert that the response has the given status code.
62
+ *
63
+ * @param int $status
64
+ * @return $this
65
+ */
66
+ public function assertStatus ($ status )
67
+ {
68
+ $ actual = $ this ->getStatusCode ();
69
+ $ message = "Expected status code {$ status } but received {$ actual }" ;
70
+ $ content = (array ) json_decode ((string ) $ this ->getContent (), true );
71
+ if (isset ($ content [Keys::KEYWORD_ERRORS ])) {
72
+ $ message .= " with errors: \n" . json_encode ($ content , JSON_PRETTY_PRINT );
73
+ }
74
+
75
+ PHPUnit::assertSame ($ status , $ actual , $ message );
76
+
77
+ return $ this ;
78
+ }
79
+
59
80
/**
60
81
* Assert a response with a singular resource in the `data` member.
61
82
*
You can’t perform that action at this time.
0 commit comments