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 \ClassTypedStub ;
1112use Emul \ArrayToClassMapper \Test \Unit \Stub \CustomDocBlockTypedArrayStub ;
1213use Emul \ArrayToClassMapper \Test \Unit \Stub \CustomDocBlockTypedStub ;
1314use Emul \ArrayToClassMapper \Test \Unit \Stub \CustomStub ;
@@ -29,6 +30,20 @@ protected function setUp(): void
2930 $ this ->docBlockParser = \Mockery::mock (DocBlockParser::class);
3031 }
3132
33+ public function testMapWhenNullGiven_shouldSet ()
34+ {
35+ $ mapper = $ this ->getMapper ();
36+
37+ $ this ->expectTypeRetrievedFromDocBlock ('' , null );
38+
39+ $ input = ['int ' => null ];
40+
41+ /** @var ScalarTypedStub $result */
42+ $ result = $ mapper ->map ($ input , ScalarTypedStub::class);
43+
44+ $ this ->assertNull ($ result ->getInt ());
45+ }
46+
3247 public function testMapWhenBuiltInTypedPropertyGiven_shouldCast ()
3348 {
3449 $ mapper = $ this ->getMapper ();
@@ -101,6 +116,34 @@ public function testMapWhenArrayTypedPropertyGivenWithCustomDockBlockType_should
101116 $ this ->assertSame (2 , $ mappedArray [1 ]->getInt ());
102117 }
103118
119+ public function testMapWhenClassTypedPropertyGivenWithNullValue_shouldSetToNull ()
120+ {
121+ $ mapper = $ this ->getMapper ();
122+
123+ $ this ->expectTypeRetrievedFromDocBlock ('' , null );
124+
125+ $ input = ['object ' => null ];
126+
127+ /** @var ClassTypedStub $result */
128+ $ result = $ mapper ->map ($ input , ClassTypedStub::class);
129+
130+ $ this ->assertNull ($ result ->getObject ());
131+ }
132+
133+ public function testMapWhenClassTypedPropertyGiven_shouldMap ()
134+ {
135+ $ mapper = $ this ->getMapper ();
136+
137+ $ this ->expectTypeRetrievedFromDocBlock ('' , null );
138+
139+ $ input = ['object ' => ['int ' => 1 ]];
140+
141+ /** @var ClassTypedStub $result */
142+ $ result = $ mapper ->map ($ input , ClassTypedStub::class);
143+
144+ $ this ->assertSame (1 , $ result ->getObject ()->getInt ());
145+ }
146+
104147 public function testMapWhenArrayTypedPropertyGivenWithCustomDockBlockTypeAndCustomMapperProvided_shouldMapElementsWithGivenMapper ()
105148 {
106149 $ currentTime = '2020-01-01 01:01:01 ' ;
0 commit comments