File tree 2 files changed +28
-8
lines changed
2 files changed +28
-8
lines changed Original file line number Diff line number Diff line change @@ -37,8 +37,6 @@ final class ContextFactory
37
37
* @see Context for more information on Contexts.
38
38
*
39
39
* @return Context
40
- *
41
- * @throws \InvalidArgumentException
42
40
*/
43
41
public function createFromReflector (\Reflector $ reflector )
44
42
{
@@ -47,11 +45,13 @@ public function createFromReflector(\Reflector $reflector)
47
45
}
48
46
49
47
$ fileName = $ reflector ->getFileName ();
50
- if (!$ fileName ) {
51
- throw new \InvalidArgumentException ('There is no file name associated with this reflector. ' );
48
+ $ namespace = $ reflector ->getNamespaceName ();
49
+
50
+ if (file_exists ($ fileName )) {
51
+ return $ this ->createForNamespace ($ namespace , file_get_contents ($ fileName ));
52
52
}
53
53
54
- return $ this -> createForNamespace ( $ reflector -> getNamespaceName (), file_get_contents ( $ fileName ) );
54
+ return new Context ( $ namespace , [] );
55
55
}
56
56
57
57
/**
Original file line number Diff line number Diff line change @@ -151,13 +151,33 @@ public function bar()
151
151
}
152
152
153
153
/**
154
- * @expectedException \InvalidArgumentException
155
154
* @covers ::createFromReflector
156
155
*/
157
- public function testThrowExceptionWhenEmptyFileName ()
156
+ public function testEmptyFileName ()
158
157
{
159
158
$ fixture = new ContextFactory ();
160
- $ fixture ->createFromReflector (new \ReflectionClass ('stdClass ' ));
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 ());
161
181
}
162
182
}
163
183
}
You can’t perform that action at this time.
0 commit comments