19
19
use Mockery as m ;
20
20
use phpDocumentor \Reflection \Php \StrategyContainer ;
21
21
use phpDocumentor \Reflection \Types \Context ;
22
+ use phpDocumentor \Reflection \Types \Integer ;
23
+ use phpDocumentor \Reflection \Types \Nullable ;
22
24
use PhpParser \Comment \Doc ;
25
+ use PhpParser \Node \NullableType ;
23
26
use PhpParser \Node \Stmt \ClassMethod ;
24
27
25
28
/**
@@ -53,6 +56,7 @@ public function testCreateWithoutParameters()
53
56
$ classMethodMock ->shouldReceive ('isPrivate ' )->once ()->andReturn (false );
54
57
$ classMethodMock ->shouldReceive ('isProtected ' )->once ()->andReturn (false );
55
58
$ classMethodMock ->shouldReceive ('getDocComment ' )->once ()->andReturnNull ();
59
+ $ classMethodMock ->shouldReceive ('getReturnType ' )->once ()->andReturn (null );
56
60
57
61
$ containerMock = m::mock (StrategyContainer::class);
58
62
$ containerMock ->shouldReceive ('findMatching ' )->never ();
@@ -71,6 +75,7 @@ public function testCreateProtectedMethod()
71
75
$ classMethodMock ->shouldReceive ('isPrivate ' )->once ()->andReturn (false );
72
76
$ classMethodMock ->shouldReceive ('isProtected ' )->once ()->andReturn (true );
73
77
$ classMethodMock ->shouldReceive ('getDocComment ' )->once ()->andReturnNull ();
78
+ $ classMethodMock ->shouldReceive ('getReturnType ' )->once ()->andReturn (null );
74
79
75
80
$ containerMock = m::mock (StrategyContainer::class);
76
81
$ containerMock ->shouldReceive ('findMatching ' )->never ();
@@ -91,6 +96,7 @@ public function testCreateWithParameters()
91
96
$ classMethodMock ->params = array ('param1 ' );
92
97
$ classMethodMock ->shouldReceive ('isPrivate ' )->once ()->andReturn (true );
93
98
$ classMethodMock ->shouldReceive ('getDocComment ' )->once ()->andReturnNull ();
99
+ $ classMethodMock ->shouldReceive ('getReturnType ' )->once ()->andReturn (null );
94
100
95
101
$ containerMock = m::mock (StrategyContainer::class);
96
102
$ containerMock ->shouldReceive ('findMatching->create ' )
@@ -108,6 +114,48 @@ public function testCreateWithParameters()
108
114
$ this ->assertEquals ('private ' , (string )$ method ->getVisibility ());
109
115
}
110
116
117
+ /**
118
+ * @covers ::create
119
+ */
120
+ public function testReturnTypeResolving ()
121
+ {
122
+ $ classMethodMock = $ this ->buildClassMethodMock ();
123
+ $ classMethodMock ->params = [];
124
+ $ classMethodMock ->shouldReceive ('isPrivate ' )->once ()->andReturn (true );
125
+ $ classMethodMock ->shouldReceive ('getDocComment ' )->once ()->andReturnNull ();
126
+ $ classMethodMock ->shouldReceive ('getReturnType ' )->times (3 )->andReturn ('int ' );
127
+
128
+ $ containerMock = m::mock (StrategyContainer::class);
129
+ $ containerMock ->shouldReceive ('findMatching ' )->never ();
130
+
131
+
132
+ /** @var MethodDescriptor $method */
133
+ $ method = $ this ->fixture ->create ($ classMethodMock , $ containerMock );
134
+
135
+ $ this ->assertEquals (new Integer (), $ method ->getReturnType ());
136
+ }
137
+
138
+ /**
139
+ * @covers ::create
140
+ */
141
+ public function testReturnTypeNullableResolving ()
142
+ {
143
+ $ classMethodMock = $ this ->buildClassMethodMock ();
144
+ $ classMethodMock ->params = [];
145
+ $ classMethodMock ->shouldReceive ('isPrivate ' )->once ()->andReturn (true );
146
+ $ classMethodMock ->shouldReceive ('getDocComment ' )->once ()->andReturnNull ();
147
+ $ classMethodMock ->shouldReceive ('getReturnType ' )->times (3 )->andReturn (new NullableType ('int ' ));
148
+
149
+ $ containerMock = m::mock (StrategyContainer::class);
150
+ $ containerMock ->shouldReceive ('findMatching ' )->never ();
151
+
152
+
153
+ /** @var MethodDescriptor $method */
154
+ $ method = $ this ->fixture ->create ($ classMethodMock , $ containerMock );
155
+
156
+ $ this ->assertEquals (new Nullable (new Integer ()), $ method ->getReturnType ());
157
+ }
158
+
111
159
/**
112
160
* @covers ::create
113
161
*/
@@ -118,6 +166,7 @@ public function testCreateWithDocBlock()
118
166
$ classMethodMock ->params = array ();
119
167
$ classMethodMock ->shouldReceive ('isPrivate ' )->once ()->andReturn (true );
120
168
$ classMethodMock ->shouldReceive ('getDocComment ' )->andReturn ($ doc );
169
+ $ classMethodMock ->shouldReceive ('getReturnType ' )->once ()->andReturn (null );
121
170
122
171
$ docBlock = new DocBlockDescriptor ('' );
123
172
0 commit comments