File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed
src/Core/Mapping/Parameter
tests/Cases/Core/Mapping/Parameter Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change 22
33namespace Apitte \Core \Mapping \Parameter ;
44
5+ use Apitte \Core \Exception \Runtime \InvalidArgumentTypeException ;
6+
57class StringTypeMapper implements ITypeMapper
68{
79
810 public function normalize (mixed $ value ): ?string
911 {
12+ if (!is_scalar ($ value )) {
13+ throw new InvalidArgumentTypeException ('string ' );
14+ }
15+
1016 return (string ) $ value ;
1117 }
1218
Original file line number Diff line number Diff line change 22
33require_once __DIR__ . '/../../../../bootstrap.php ' ;
44
5+ use Apitte \Core \Exception \Runtime \InvalidArgumentTypeException ;
56use Apitte \Core \Mapping \Parameter \StringTypeMapper ;
67use Apitte \Core \Schema \EndpointParameter ;
78use Tester \Assert ;
@@ -21,6 +22,15 @@ final class StringTypeMapperTest extends TestCase
2122 Assert::same ('-10 ' , $ mapper ->normalize (-10 , $ parameter ));
2223 }
2324
25+ public function testFail (): void
26+ {
27+ $ mapper = new StringTypeMapper ();
28+
29+ Assert::exception (function () use ($ mapper ): void {
30+ $ mapper ->normalize (['' ]);
31+ }, InvalidArgumentTypeException::class);
32+ }
33+
2434}
2535
2636(new StringTypeMapperTest ())->run ();
You can’t perform that action at this time.
0 commit comments