-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PHPUnit problems with getallheaders() #72
Comments
It appears as if the method I made the following test: <?php
namespace ns;
function test() {
return '1';
}
if ( function_exists('test') ) {
echo test();
} else {
echo '0';
}
if ( function_exists('ns\test') ) {
echo test();
} else {
echo '0';
} The result was |
So we should probably append a backslash to the function name like so: In Headers::createFromGlobals() public static function createFromGlobals()
{
$headers = null;
if (function_exists('\getallheaders')) {
$headers = \getallheaders();
}
if (!is_array($headers)) {
$headers = [];
}
return new static($headers);
} |
But then we cannot override this method for unit testing. I think we should make sure, that the function does exist in the root namespace. And then use the |
I think we can just do |
If we check for |
could do |
Then we insert a condition into the library source code that is actually only used by unit testing. I think there is no other way: we need a polyfill to make sure that the function exists on the root namespace. Either we write our own, or define one in composer require-dev. |
We can use https://github.com/ralouphie/getallheaders |
That's a good idea. |
In #70 the file
tests/Assets/PhpGetAllHeaders.php
had been removed. This breaks PHPUnit on my system (Win10, PHP 7.1), because the following conditionSlim-Psr7/src/Headers.php
Line 266 in 3f9b6ae
always returns false (even if the function is defined in the
Slim\Psr7
namespace via the filetests/Assets/PhpFunctionOverrides.php
).Test Output
It seems that only failures 1 and 4 are directly connected, as the other failures remain even if I add the function
getallheaders()
to the root namespace.The text was updated successfully, but these errors were encountered: