PHP Fatal error: Default value for parameters with a class type hint can only be NULL in /usr/share/php/PHPUnit/Framework/Test.php on line 66
PHP Stack trace:
PHP 1. {main}() /usr/bin/phpunit:0
PHP 2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:46
PHP 3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:130
PHP 4. PHPUnit_Runner_BaseTestRunner->getTest() /usr/share/php/PHPUnit/TextUI/Command.php:150
PHP 5. PHPUnit_Runner_BaseTestRunner->loadSuiteClass() /usr/share/php/PHPUnit/Runner/BaseTestRunner.php:104
PHP 6. PHPUnit_Runner_StandardTestSuiteLoader->load() /usr/share/php/PHPUnit/Runner/BaseTestRunner.php:168
PHP 7. PHPUnit_Util_Fileloader::checkAndLoad() /usr/share/php/PHPUnit/Runner/StandardTestSuiteLoader.php:78
PHP 8. PHPUnit_Util_Fileloader::load() /usr/share/php/PHPUnit/Util/Fileloader.php:79
PHP 9. include_once() /usr/share/php/PHPUnit/Util/Fileloader.php:95
PHP 10. phpunit_autoload() /usr/share/php/PHPUnit/Autoload.php:0
PHP 11. require() /usr/share/php/PHPUnit/Autoload.php:203
PHP 12. phpunit_autoload() /usr/share/php/PHPUnit/Autoload.php:0
The line in question has:
public function run(PHPUnit_Framework_TestResult $result = NULL)
When I remove the = NULL
it goes through but fails on another line that also has an = NULL
, the screwed up thing is that the error basically says it HAS to be NULL, which it IS.
I have not modified PhpUnit in any way, I installed it using the method described here:
http://www.giocc.com/installing-phpunit-on-ubuntu-11-04-natty-narwhal.html
I honestly don't understand why this is happening.. something tells me PHP is bugged in that it's giving me the wrong error.
Found the answer, quoting myself from the comments section:
Oh damn I found the problem, and it's a silly one on my side. I had a constant file that was defining NULL for use in an ORM library. It's defined in it's own namespace so it shouldn't have interfered with the global constant, but I guess constants are a bit tricky with namespaces..
So TIL, if you want to define constants in a namespace, simply adding namespace to the top of the file won't suffice, you have to define the constants like so
define('NAMESPACE\CONSTANT', 'value');
// or
define(__NAMESPACE__ . '\CONSTANT', 'value'); // to use the current namespace
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With