66
77use ApiSkeletons \Laravel \ApiProblem \ApiProblem ;
88use ApiSkeletons \Laravel \ApiProblem \Exception ;
9+ use ApiSkeletons \Laravel \ApiProblem \Facades \ApiProblem as ApiProblemFacade ;
10+ use http \Exception \InvalidArgumentException ;
11+ use Illuminate \Http \JsonResponse ;
912use ReflectionObject ;
1013use TypeError ;
1114
@@ -27,6 +30,18 @@ public function statusCodes(): array
2730 ];
2831 }
2932
33+ public function testResponseWithObject (): void
34+ {
35+ $ apiProblem = new ApiProblem (500 , 'Testing ' );
36+
37+ $ this ->assertInstanceOf (JsonResponse::class, $ apiProblem ->response ());
38+ }
39+
40+ public function testResponseWithFacade (): void
41+ {
42+ $ this ->assertInstanceOf (JsonResponse::class, ApiProblemFacade::response ('Testing ' , 500 ));
43+ }
44+
3045 /**
3146 * @dataProvider statusCodes
3247 */
@@ -255,4 +270,52 @@ public function testInvalidHttpStatusCodesAreCastTo500(int $code): void
255270 $ problem = new ApiProblem ($ code , $ e );
256271 $ this ->assertEquals (500 , $ problem ->status );
257272 }
273+
274+ /**
275+ * @dataProvider statusCodes
276+ * @group api-tools-118
277+ */
278+ public function testMagicGetInvalidArgument (int $ code ): void
279+ {
280+ $ this ->expectException (Exception \InvalidArgumentException::class);
281+ $ apiProblem = new ApiProblem ($ code , 'Testing ' , null , null , ['more ' => 'testing ' ]);
282+
283+ $ this ->assertEquals ('testing ' , $ apiProblem ->code );
284+ }
285+
286+ /**
287+ * @dataProvider statusCodes
288+ * @group api-tools-118
289+ */
290+ public function testMagicGetNormalizedProperties (int $ code ): void
291+ {
292+ $ apiProblem = new ApiProblem ($ code , 'Testing ' , 'test ' , 'title test ' , ['more ' => 'testing ' ]);
293+
294+ $ this ->assertEquals ('test ' , $ apiProblem ->__get ('type ' ));
295+ $ this ->assertEquals ($ code , $ apiProblem ->__get ('status ' ));
296+ $ this ->assertEquals ('title test ' , $ apiProblem ->__get ('title ' ));
297+ $ this ->assertEquals ('Testing ' , $ apiProblem ->__get ('detail ' ));
298+ }
299+
300+ /**
301+ * @dataProvider statusCodes
302+ * @group api-tools-118
303+ */
304+ public function testMagicGetAdditionalDetails (int $ code ): void
305+ {
306+ $ apiProblem = new ApiProblem ($ code , 'Testing ' , 'test ' , 'title test ' , ['xxmore ' => 'testing ' ]);
307+
308+ $ this ->assertEquals ('testing ' , $ apiProblem ->__get ('xxmore ' ));
309+ }
310+
311+ /**
312+ * @dataProvider statusCodes
313+ * @group api-tools-118
314+ */
315+ public function testMagicGetAdditionalDetailsNormalized (int $ code ): void
316+ {
317+ $ apiProblem = new ApiProblem ($ code , 'Testing ' , 'test ' , 'title test ' , ['code ' => 'testing ' ]);
318+
319+ $ this ->assertEquals ('testing ' , $ apiProblem ->__get ('code ' ));
320+ }
258321}
0 commit comments