|
2 | 2 |
|
3 | 3 | namespace Nuxtifyts\PhpDto\Tests\Unit\Contexts; |
4 | 4 |
|
| 5 | +use Nuxtifyts\PhpDto\Tests\Dummies\Serializers\HasSerializersDummyClass; |
5 | 6 | use Nuxtifyts\PhpDto\Attributes\Property\Computed; |
6 | 7 | use Nuxtifyts\PhpDto\Attributes\Property\WithRefiner; |
7 | 8 | use Nuxtifyts\PhpDto\Contexts\PropertyContext; |
8 | 9 | use Nuxtifyts\PhpDto\Contexts\TypeContext; |
9 | 10 | use Nuxtifyts\PhpDto\Data; |
10 | 11 | use Nuxtifyts\PhpDto\DataRefiners\DateTimeRefiner; |
11 | 12 | use Nuxtifyts\PhpDto\Enums\Property\Type; |
| 13 | +use Nuxtifyts\PhpDto\Exceptions\UnknownTypeException; |
12 | 14 | use Nuxtifyts\PhpDto\Exceptions\UnsupportedTypeException; |
13 | 15 | use Nuxtifyts\PhpDto\Serializers\ScalarTypeSerializer; |
14 | 16 | use Nuxtifyts\PhpDto\Tests\Dummies\ComputedPropertiesData; |
|
32 | 34 | #[CoversClass(Computed::class)] |
33 | 35 | #[CoversClass(WithRefiner::class)] |
34 | 36 | #[CoversClass(UnsupportedTypeException::class)] |
| 37 | +#[CoversClass(UnknownTypeException::class)] |
35 | 38 | #[UsesClass(ComputedPropertiesData::class)] |
36 | 39 | #[UsesClass(ScalarTypeSerializer::class)] |
37 | 40 | #[UsesClass(PersonData::class)] |
38 | 41 | #[UsesClass(Data::class)] |
39 | 42 | #[UsesClass(CoordinatesData::class)] |
40 | 43 | #[UsesClass(UnionMultipleTypeData::class)] |
41 | 44 | #[UsesClass(PersonData::class)] |
| 45 | +#[UsesClass(HasSerializersDummyClass::class)] |
42 | 46 | final class PropertyContextTest extends UnitCase |
43 | 47 | { |
44 | 48 | /** |
@@ -99,6 +103,26 @@ public function __construct( |
99 | 103 | PropertyContext::getInstance($reflectionProperty); |
100 | 104 | } |
101 | 105 |
|
| 106 | + /** |
| 107 | + * @throws Throwable |
| 108 | + */ |
| 109 | + #[Test] |
| 110 | + public function will_throw_and_exception_if_it_fails_to_resolve_a_serializer(): void |
| 111 | + { |
| 112 | + $object = new readonly class (1) extends Data { |
| 113 | + public function __construct( |
| 114 | + public int $value |
| 115 | + ) { |
| 116 | + } |
| 117 | + }; |
| 118 | + |
| 119 | + $reflectionProperty = new ReflectionProperty($object::class, 'value'); |
| 120 | + $propertyContext = PropertyContext::getInstance($reflectionProperty); |
| 121 | + |
| 122 | + self::expectException(UnknownTypeException::class); |
| 123 | + HasSerializersDummyClass::testGetSerializersFromPropertyContext($propertyContext); |
| 124 | + } |
| 125 | + |
102 | 126 | /** |
103 | 127 | * @throws Throwable |
104 | 128 | */ |
|
0 commit comments