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