88use  Emul \ArrayToClassMapper \DocBlock \DocBlockParser ;
99use  Emul \ArrayToClassMapper \DocBlock \Entity \DocBlockType ;
1010use  Emul \ArrayToClassMapper \Test \Unit \Stub \ClassDocBlockTypedArrayStub ;
11+ use  Emul \ArrayToClassMapper \Test \Unit \Stub \ClassDocBlockTypedStub ;
12+ use  Emul \ArrayToClassMapper \Test \Unit \Stub \ClassTypedStub ;
1113use  Emul \ArrayToClassMapper \Test \Unit \Stub \CustomDocBlockTypedArrayStub ;
1214use  Emul \ArrayToClassMapper \Test \Unit \Stub \CustomDocBlockTypedStub ;
1315use  Emul \ArrayToClassMapper \Test \Unit \Stub \CustomStub ;
@@ -29,6 +31,20 @@ protected function setUp(): void
2931        $ this  ->docBlockParser  = \Mockery::mock (DocBlockParser::class);
3032    }
3133
34+     public  function  testMapWhenNullGiven_shouldSet ()
35+     {
36+         $ mapper  = $ this  ->getMapper ();
37+ 
38+         $ this  ->expectTypeRetrievedFromDocBlock ('' , null );
39+ 
40+         $ input  = ['int '  => null ];
41+ 
42+         /** @var ScalarTypedStub $result */ 
43+         $ result  = $ mapper ->map ($ input , ScalarTypedStub::class);
44+ 
45+         $ this  ->assertNull ($ result ->getInt ());
46+     }
47+ 
3248    public  function  testMapWhenBuiltInTypedPropertyGiven_shouldCast ()
3349    {
3450        $ mapper  = $ this  ->getMapper ();
@@ -101,6 +117,48 @@ public function testMapWhenArrayTypedPropertyGivenWithCustomDockBlockType_should
101117        $ this  ->assertSame (2 , $ mappedArray [1 ]->getInt ());
102118    }
103119
120+     public  function  testMapWhenClassTypedPropertyGivenWithNullValue_shouldSetToNull ()
121+     {
122+         $ mapper  = $ this  ->getMapper ();
123+ 
124+         $ this  ->expectTypeRetrievedFromDocBlock ('' , null );
125+ 
126+         $ input  = ['object '  => null ];
127+ 
128+         /** @var ClassTypedStub $result */ 
129+         $ result  = $ mapper ->map ($ input , ClassTypedStub::class);
130+ 
131+         $ this  ->assertNull ($ result ->getObject ());
132+     }
133+ 
134+     public  function  testMapWhenClassDocBlockTypedPropertyGivenWithNullValue_shouldSetToNull ()
135+     {
136+         $ mapper  = $ this  ->getMapper ();
137+ 
138+         $ this  ->expectTypeRetrievedFromDocBlock ('/** @var ScalarTypedStub|null */ ' , new  DocBlockType ('ScalarTypedStub ' , true , false , true ));
139+ 
140+         $ input  = ['object '  => null ];
141+ 
142+         /** @var ClassDocBlockTypedStub $result */ 
143+         $ result  = $ mapper ->map ($ input , ClassDocBlockTypedStub::class);
144+ 
145+         $ this  ->assertNull ($ result ->getObject ());
146+     }
147+ 
148+     public  function  testMapWhenClassTypedPropertyGiven_shouldMap ()
149+     {
150+         $ mapper  = $ this  ->getMapper ();
151+ 
152+         $ this  ->expectTypeRetrievedFromDocBlock ('' , null );
153+ 
154+         $ input  = ['object '  => ['int '  => 1 ]];
155+ 
156+         /** @var ClassTypedStub $result */ 
157+         $ result  = $ mapper ->map ($ input , ClassTypedStub::class);
158+ 
159+         $ this  ->assertSame (1 , $ result ->getObject ()->getInt ());
160+     }
161+ 
104162    public  function  testMapWhenArrayTypedPropertyGivenWithCustomDockBlockTypeAndCustomMapperProvided_shouldMapElementsWithGivenMapper ()
105163    {
106164        $ currentTime  = '2020-01-01 01:01:01 ' ;
0 commit comments