File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -37,13 +37,19 @@ final class ContextFactory
3737 * @see Context for more information on Contexts.
3838 *
3939 * @return Context
40+ *
41+ * @throws \InvalidArgumentException
4042 */
4143 public function createFromReflector (\Reflector $ reflector )
4244 {
4345 if (method_exists ($ reflector , 'getDeclaringClass ' )) {
4446 $ reflector = $ reflector ->getDeclaringClass ();
4547 }
48+
4649 $ fileName = $ reflector ->getFileName ();
50+ if (!$ fileName ) {
51+ throw new \InvalidArgumentException ('There is no file name associated with the reflector "%s". ' );
52+ }
4753
4854 return $ this ->createForNamespace ($ reflector ->getNamespaceName (), file_get_contents ($ fileName ));
4955 }
Original file line number Diff line number Diff line change @@ -149,6 +149,16 @@ public function bar()
149149
150150 $ this ->assertSame ([], $ context ->getNamespaceAliases ());
151151 }
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+ }
152162 }
153163}
154164
You can’t perform that action at this time.
0 commit comments