Having some issues using PHPUnit to test my controllers.
Code I was working on so far was implementing $_POST
or other request variables:
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST = array(
'test' => true
);
Most of tests worked perfectly this way until I run into methods that take uses of filter_input_array
function:
$_SERVER['REQUEST_METHOD'] = 'POST';
$_REQUEST = $_POST = $GLOBALS['_POST'] = array(
'test' => true
);
// ....
var_dump(filter_input_array(INPUT_POST));
NULL
I'm not willing to remove filter_input
functions from not mine code, but I'm unable to make them working in tests.
Versionings:
PHP 5.5.9-1ubuntu4.9 (cli) (built: Apr 17 2015 11:44:57)
Apache/2.4.7 (Ubuntu)
PHPUnit 4.6.6 by Sebastian Bergmann and contributors.
Any help will be appreciated.
EDIT 2015.05.11
Setting $_SERVER
with CONTENT_LENGTH
and CONTENT_TYPE
does not fix the problem. My version of PHP does not allow me to write to php://stdin
in way its described in PHP 5.6.0 chagelog (or way I understand it), but file_put_contents(STDIN,..)
succeed but does not work anyway.
Because it is a phpunit test, maybe there is some kind of annotation or phpunit.xml
entry I don't know yet, that may fix this problem in php-cgi POST setting manner.