During tests, I make use of a StreamWrapper backed virtual file system. The class being tested makes use of \ReflectionClass::getFileName() to locate the source file within which the class is defined.
The problem, at least with PHP 7.1, is that \ReflectionClass::getFileName() strips the leading scheme from the path. So doing something like:
require 'vfs://foo/bar.php';
$inst = new Bar();
$path = (new \ReflectionClass($inst))->getFileName();
Actually returns '/foo/bar.php' as opposed to 'vfs://foo/bar.php'.
Is there another way to determine the source code path for a class or a way to extend/mock \ReflectionClass during testing?
Aucun commentaire:
Enregistrer un commentaire