@@ -46,24 +46,6 @@ public function it_can_add_mapping_for_xml_namespace(): void
4646 $ this ->assertSame ($ customDestination , $ destination );
4747 }
4848
49- #[Test]
50- public function it_can_add_multiple_mappings (): void
51- {
52- $ fallback = new Destination ('/src/Type ' , 'App \\Type ' );
53- $ custom1 = new Destination ('/src/Custom1 ' , 'App \\Custom1 ' );
54- $ custom2 = new Destination ('/src/Custom2 ' , 'App \\Custom2 ' );
55-
56- $ map = TypeNamespaceMap::create ($ fallback )
57- ->withMapping ('http://custom1.example.com ' , $ custom1 )
58- ->withMapping ('http://custom2.example.com ' , $ custom2 );
59-
60- $ type1 = XsdType::create ('Type1 ' )->withXmlNamespace ('http://custom1.example.com ' );
61- $ type2 = XsdType::create ('Type2 ' )->withXmlNamespace ('http://custom2.example.com ' );
62-
63- $ this ->assertSame ($ custom1 , $ map ->detectDestinationForType ($ type1 ));
64- $ this ->assertSame ($ custom2 , $ map ->detectDestinationForType ($ type2 ));
65- }
66-
6749 #[Test]
6850 public function it_returns_fallback_when_type_has_no_xml_namespace (): void
6951 {
@@ -79,21 +61,6 @@ public function it_returns_fallback_when_type_has_no_xml_namespace(): void
7961 $ this ->assertSame ($ fallback , $ destination );
8062 }
8163
82- #[Test]
83- public function it_returns_fallback_when_xml_namespace_is_not_mapped (): void
84- {
85- $ fallback = new Destination ('/src/Type ' , 'App \\Type ' );
86- $ custom = new Destination ('/src/Custom ' , 'App \\Custom ' );
87-
88- $ map = TypeNamespaceMap::create ($ fallback )
89- ->withMapping ('http://custom.example.com ' , $ custom );
90-
91- $ type = XsdType::create ('OtherType ' )->withXmlNamespace ('http://other.example.com ' );
92- $ destination = $ map ->detectDestinationForType ($ type );
93-
94- $ this ->assertSame ($ fallback , $ destination );
95- }
96-
9764 #[Test]
9865 public function it_is_immutable_when_adding_mappings (): void
9966 {
@@ -151,21 +118,6 @@ public function it_can_override_existing_mapping(): void
151118 $ this ->assertSame ($ custom2 , $ destination );
152119 }
153120
154- #[Test]
155- public function it_can_add_a_strategy (): void
156- {
157- $ fallback = new Destination ('/src/Type ' , 'App \\Type ' );
158- $ strategyDestination = new Destination ('/src/Strategy ' , 'App \\Strategy ' );
159-
160- $ map = TypeNamespaceMap::create ($ fallback )
161- ->withStrategy (fn (string $ xmlns , Destination $ fallback ) => $ strategyDestination );
162-
163- $ type = XsdType::create ('SomeType ' )->withXmlNamespace ('http://example.com/schema ' );
164- $ destination = $ map ->detectDestinationForType ($ type );
165-
166- $ this ->assertSame ($ strategyDestination , $ destination );
167- }
168-
169121 #[Test]
170122 public function it_does_not_call_strategy_when_xmlns_is_in_map (): void
171123 {
@@ -175,7 +127,7 @@ public function it_does_not_call_strategy_when_xmlns_is_in_map(): void
175127
176128 $ map = TypeNamespaceMap::create ($ fallback )
177129 ->withMapping ('http://mapped.example.com ' , $ mapped )
178- ->withStrategy (function (string $ xmlns , Destination $ fallback ) use (&$ strategyCalled ) {
130+ ->withStrategy (function (string $ xmlns , string $ xmlNamespaceName , Destination $ fallback ) use (&$ strategyCalled ) {
179131 $ strategyCalled = true ;
180132 return new Destination ('/src/Strategy ' , 'App \\Strategy ' );
181133 });
@@ -197,7 +149,7 @@ public function it_calls_strategy_when_xmlns_is_not_in_map(): void
197149
198150 $ map = TypeNamespaceMap::create ($ fallback )
199151 ->withMapping ('http://mapped.example.com ' , $ mapped )
200- ->withStrategy (function (string $ xmlns , Destination $ fallback ) use (&$ strategyCalled , $ strategyDestination ) {
152+ ->withStrategy (function (string $ xmlns , string $ xmlNamespaceName , Destination $ fallback ) use (&$ strategyCalled , $ strategyDestination ) {
201153 $ strategyCalled = true ;
202154 return $ strategyDestination ;
203155 });
@@ -210,46 +162,38 @@ public function it_calls_strategy_when_xmlns_is_not_in_map(): void
210162 }
211163
212164 #[Test]
213- public function it_passes_xmlns_and_fallback_to_strategy (): void
165+ public function it_passes_all_arguments_to_strategy (): void
214166 {
215167 $ fallback = new Destination ('/src/Type ' , 'App \\Type ' );
216168 $ receivedXmlns = null ;
169+ $ receivedNamespaceName = null ;
217170 $ receivedFallback = null ;
218171
219172 $ map = TypeNamespaceMap::create ($ fallback )
220- ->withStrategy (function (string $ xmlns , Destination $ fb ) use (&$ receivedXmlns , &$ receivedFallback ) {
173+ ->withStrategy (function (string $ xmlns , string $ xmlNamespaceName , Destination $ fb ) use (&$ receivedXmlns, & $ receivedNamespaceName , &$ receivedFallback ) {
221174 $ receivedXmlns = $ xmlns ;
175+ $ receivedNamespaceName = $ xmlNamespaceName ;
222176 $ receivedFallback = $ fb ;
223177 return $ fb ;
224178 });
225179
226- $ type = XsdType::create ('SomeType ' )->withXmlNamespace ('http://example.com/schema ' );
180+ $ type = XsdType::create ('SomeType ' )
181+ ->withXmlNamespace ('http://example.com/schema ' )
182+ ->withXmlNamespaceName ('ex ' );
227183 $ map ->detectDestinationForType ($ type );
228184
229185 $ this ->assertSame ('http://example.com/schema ' , $ receivedXmlns );
186+ $ this ->assertSame ('ex ' , $ receivedNamespaceName );
230187 $ this ->assertSame ($ fallback , $ receivedFallback );
231188 }
232189
233- #[Test]
234- public function it_returns_fallback_when_no_strategy_and_xmlns_not_in_map (): void
235- {
236- $ fallback = new Destination ('/src/Type ' , 'App \\Type ' );
237-
238- $ map = TypeNamespaceMap::create ($ fallback );
239-
240- $ type = XsdType::create ('SomeType ' )->withXmlNamespace ('http://example.com/schema ' );
241- $ destination = $ map ->detectDestinationForType ($ type );
242-
243- $ this ->assertSame ($ fallback , $ destination );
244- }
245-
246190 #[Test]
247191 public function it_can_use_strategy_to_calculate_destination_based_on_xmlns (): void
248192 {
249193 $ fallback = new Destination ('/src/Type ' , 'App \\Type ' );
250194
251195 $ map = TypeNamespaceMap::create ($ fallback )
252- ->withStrategy (function (string $ xmlns , Destination $ fallback ): Destination {
196+ ->withStrategy (function (string $ xmlns , string $ xmlNamespaceName , Destination $ fallback ): Destination {
253197 if (str_contains ($ xmlns , 'xoev.de ' )) {
254198 return new Destination ('/src/Type/Xoev ' , 'App \\Type \\Xoev ' );
255199 }
@@ -273,7 +217,7 @@ public function it_can_remove_strategy_by_setting_null(): void
273217 $ strategyDestination = new Destination ('/src/Strategy ' , 'App \\Strategy ' );
274218
275219 $ mapWithStrategy = TypeNamespaceMap::create ($ fallback )
276- ->withStrategy (fn (string $ xmlns , Destination $ fallback ) => $ strategyDestination );
220+ ->withStrategy (fn (string $ xmlns , string $ xmlNamespaceName , Destination $ fallback ) => $ strategyDestination );
277221
278222 $ mapWithoutStrategy = $ mapWithStrategy ->withStrategy (null );
279223
@@ -290,7 +234,7 @@ public function it_is_immutable_when_adding_strategy(): void
290234 $ strategyDestination = new Destination ('/src/Strategy ' , 'App \\Strategy ' );
291235
292236 $ map1 = TypeNamespaceMap::create ($ fallback );
293- $ map2 = $ map1 ->withStrategy (fn (string $ xmlns , Destination $ fallback ) => $ strategyDestination );
237+ $ map2 = $ map1 ->withStrategy (fn (string $ xmlns , string $ xmlNamespaceName , Destination $ fallback ) => $ strategyDestination );
294238
295239 $ type = XsdType::create ('SomeType ' )->withXmlNamespace ('http://example.com/schema ' );
296240
0 commit comments