Bug #70034 [Csd]: ReflectionClass->getFileName in PHPT returns "-" as filename
| From: | james at asgrim dot com | Date: | Thu, 09 Jul 2015 18:22:54 +0000 |
| Subject: | Bug #70034 [Csd]: ReflectionClass->getFileName in PHPT returns "-" as filename | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-194265@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70034&edit=1
ID: 70034
User updated by: james at asgrim dot com
Reported by: james at asgrim dot com
Summary: ReflectionClass->getFileName in PHPT returns "-" as
filename
Status: Closed
Type: Bug
Package: Reflection related
Operating System: Ubuntu 15.04
PHP Version: 5.6.10
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Yes indeed - further information if anyone comes across this:
https://github.com/sebastianbergmann/phpunit/issues/1783
It's actually because phpunit pipes the code into php on Linux (although, from your example
there, it looks like it works by creating a tmp file and running that)
Incidentally, do you know of a way of "faking" the filename in this case?
e.g.
this fails:
echo "<?php class Foo {} \$c = new ReflectionClass('Foo');
var_dump(\$c->getFileName());" | php
is it possible to "fake" the filename, something like:
echo "<?php class Foo {} \$c = new ReflectionClass('Foo');
var_dump(\$c->getFileName());" | php --pretend-the-filename-is="foo.php"
or something?
Previous Comments:
------------------------------------------------------------------------
[2015-07-09 18:12:51] cmb@php.net
Ah, interesting! I didn't know that PHPUnit is able to run phpt
tests.
Anyway, I gave it a try on Windows, and got the following:
--- Expected
+++ Actual
@@ @@
-string(%d) "%sReflectionClass_FileInfo_basic.php"
+string(43) "C:\Users\cmb\AppData\Local\Temp\PHP2C57.tmp"
So indeed, this seems to be a current limitation of PHPUnit.
------------------------------------------------------------------------
[2015-07-09 17:27:59] james at asgrim dot com
Hmm - I'm running the test using PHP Unit, so this may be a bug there instead. I'll close
this, investigate some more and re-open if it needs a closer look at here :)
Thank you!
------------------------------------------------------------------------
[2015-07-09 14:42:28] cmb@php.net
The test passes for me, and apparently for others as well[1]. How
did you run the test (make test or directly via run-tests.php)?
[1] <https://qa.php.net/reports/run_tests.php?version=5.6.10>
------------------------------------------------------------------------
[2015-07-09 12:53:28] james at asgrim dot com
Description:
------------
The ReflectionClass_FileInfo_basic.phpt test is failing.
When creating a reflection of a class in a .phpt test, the getFileName() method returns simply a
string with a hypen ("-") instead of the actual filename.
--- Expected
+++ Actual
@@ @@
-string(%d) "%sReflectionClass_FileInfo_basic.php"
+string(1) "-"
https://github.com/php/php-src/blob/master/ext/reflection/tests/ReflectionClass_FileInfo_basic.phpt
Expected result:
----------------
Expect the filename returned by getFileName() to be "%sReflectionClass_FileInfo_basic.php"
Actual result:
--------------
The filename returned by getFileName() is actually "-"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70034&edit=1