File tree 2 files changed +37
-1
lines changed
2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -43,9 +43,15 @@ public function createFromReflector(\Reflector $reflector)
43
43
if (method_exists ($ reflector , 'getDeclaringClass ' )) {
44
44
$ reflector = $ reflector ->getDeclaringClass ();
45
45
}
46
+
46
47
$ fileName = $ reflector ->getFileName ();
48
+ $ namespace = $ reflector ->getNamespaceName ();
49
+
50
+ if (file_exists ($ fileName )) {
51
+ return $ this ->createForNamespace ($ namespace , file_get_contents ($ fileName ));
52
+ }
47
53
48
- return $ this -> createForNamespace ( $ reflector -> getNamespaceName (), file_get_contents ( $ fileName ) );
54
+ return new Context ( $ namespace , [] );
49
55
}
50
56
51
57
/**
Original file line number Diff line number Diff line change @@ -149,6 +149,36 @@ public function bar()
149
149
150
150
$ this ->assertSame ([], $ context ->getNamespaceAliases ());
151
151
}
152
+
153
+ /**
154
+ * @covers ::createFromReflector
155
+ */
156
+ public function testEmptyFileName ()
157
+ {
158
+ $ fixture = new ContextFactory ();
159
+ $ context = $ fixture ->createFromReflector (new \ReflectionClass ('stdClass ' ));
160
+
161
+ $ this ->assertSame ([], $ context ->getNamespaceAliases ());
162
+ }
163
+
164
+ /**
165
+ * @covers ::createFromReflector
166
+ */
167
+ public function testEvalDClass ()
168
+ {
169
+ eval (<<<PHP
170
+ namespace Foo;
171
+
172
+ class Bar
173
+ {
174
+ }
175
+ PHP
176
+ );
177
+ $ fixture = new ContextFactory ();
178
+ $ context = $ fixture ->createFromReflector (new \ReflectionClass ('Foo\Bar ' ));
179
+
180
+ $ this ->assertSame ([], $ context ->getNamespaceAliases ());
181
+ }
152
182
}
153
183
}
154
184
You can’t perform that action at this time.
0 commit comments