55namespace Tests \Unit \Lendable \Aggregate ;
66
77use Lendable \Aggregate \AggregateType ;
8+ use Lendable \Aggregate \CannotResolveAggregateType ;
89use Lendable \Aggregate \MapAggregateTypeResolver ;
910use PHPUnit \Framework \TestCase ;
1011
@@ -22,4 +23,46 @@ public function it_can_resolve_an_aggregate_type_for_a_mapped_aggregate_root():
2223
2324 $ this ->assertSame ('foo ' , $ fixture ->resolve (new \stdClass ())->toString ());
2425 }
26+
27+ /**
28+ * @test
29+ */
30+ public function it_throws_if_a_mapped_class_does_not_exist (): void
31+ {
32+ $ this ->expectException (\InvalidArgumentException::class);
33+ $ this ->expectExceptionMessage ('All map keys must be class names that exist, FooBarBaz does not exist. ' );
34+
35+ // @phpstan-ignore-next-line intentional undefined class.
36+ new MapAggregateTypeResolver ([\FooBarBaz::class => AggregateType::fromString ('FooBarBaz ' )]);
37+ }
38+
39+ /**
40+ * @test
41+ */
42+ public function it_throws_if_a_mapped_value_is_not_an_aggregate_type (): void
43+ {
44+ $ badValue = new class () {
45+ };
46+
47+ $ this ->expectException (\InvalidArgumentException::class);
48+ $ this ->expectExceptionMessage (\sprintf ('All map values must be instances of %s, %s is not ' , AggregateType::class, $ badValue ::class));
49+
50+ // @phpstan-ignore-next-line intentionally non-compliant value passed.
51+ new MapAggregateTypeResolver ([\stdClass::class => $ badValue ]);
52+ }
53+
54+ /**
55+ * @test
56+ */
57+ public function it_throws_if_cannot_resolve_an_aggregate_as_not_mapped (): void
58+ {
59+ $ this ->expectException (CannotResolveAggregateType::class);
60+
61+ $ fixture = new MapAggregateTypeResolver ([\stdClass::class => AggregateType::fromString ('foo ' )]);
62+ $ fixture ->resolve (
63+ // @phpstan-ignore-next-line intentional bad method call violating static analysis for runtime check.
64+ new class () {
65+ }
66+ );
67+ }
2568}
0 commit comments