This repository was archived by the owner on Aug 26, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +32
-3
lines changed
Expand file tree Collapse file tree 4 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -149,7 +149,14 @@ Functions
149149- ` assertResourceIsForbidden() `
150150- ` assertMatchesResourceItemJsonSchema(Your::class) `
151151- ` assertMatchesResourceCollectionJsonSchema(Your::class) `
152- - ` assertResourceIsBadRequest(Response::HTTP_BAD_REQUEST) `
152+ - ` assertResourceIsBadRequest() `
153+ - ` assertResourceIsUnprocessableEntity() `
154+ - ` expectResponseContent() `
155+
156+ > if you want to test ` expectResponseContent ` and not return an exception pass ` false ` as parameter, example: ` expectResponseContent(false) `
157+
158+
159+
153160
154161## Testing
155162
Original file line number Diff line number Diff line change @@ -95,6 +95,11 @@ function assertResourceIsBadRequest(): void
9595 test ()->assertResourceIsBadRequest ();
9696}
9797
98+ function assertResourceIsUnprocessableEntity (): void
99+ {
100+ test ()->assertResourceIsUnprocessableEntity ();
101+ }
102+
98103function assertResponseStatusCodeSame (int $ statusCode ): void
99104{
100105 test ()->assertResponseStatusCodeSame ($ statusCode );
Original file line number Diff line number Diff line change @@ -38,6 +38,13 @@ public function assertResourceIsUnauthorized(): TestCase
3838 return $ this ;
3939 }
4040
41+ public function assertResourceIsUnprocessableEntity (): TestCase
42+ {
43+ test ()->assertResponseStatusCodeSame (422 );
44+
45+ return $ this ;
46+ }
47+
4148 public function assertResourceIsForbidden (): TestCase
4249 {
4350 test ()->assertResponseStatusCodeSame (403 );
@@ -55,8 +62,8 @@ public function assertResourceIsNotFound(): TestCase
5562 /**
5663 * @return Expectation|Extendable
5764 */
58- public function expectResponseContent ()
65+ public function expectResponseContent (bool $ throw = true )
5966 {
60- return expect ($ this ->response ()->getContent ());
67+ return expect ($ this ->response ()->getContent ($ throw ));
6168 }
6269}
Original file line number Diff line number Diff line change 44use function Eerison \PestPluginApiPlatform \assertResourceIsForbidden ;
55use function Eerison \PestPluginApiPlatform \assertResourceIsNotFound ;
66use function Eerison \PestPluginApiPlatform \assertResourceIsUnauthorized ;
7+ use function Eerison \PestPluginApiPlatform \assertResourceIsUnprocessableEntity ;
78use function Eerison \PestPluginApiPlatform \assertResponseIsSuccessful ;
89use function Eerison \PestPluginApiPlatform \assertResponseStatusCodeSame ;
910use function Eerison \PestPluginApiPlatform \get ;
4546 ->get ('/foo/response/400 ' )
4647 ->assertResourceIsBadRequest ();
4748
49+ test ('assertResourceIsUnprocessableEntity method ' )
50+ ->get ('/foo/response/422 ' )
51+ ->assertResourceIsUnprocessableEntity ();
52+
4853it ('can use assertResponseIsSuccessful as function ' , function () {
4954 get ('/foo/response/204 ' );
5055 assertResponseIsSuccessful ();
9297 get ('/foo/response/400 ' );
9398 assertResourceIsBadRequest ();
9499});
100+
101+ test ('Unprocessable entity function. ' , function () {
102+ get ('/foo/response/422 ' );
103+ assertResourceIsUnprocessableEntity ();
104+ });
You can’t perform that action at this time.
0 commit comments