I'm using phpunit with Laravel 4 framework. Why is it that when there's a PHP error during the tests, no error messages are shown (eg: missing method)?
How can we get phpunit to show all errors?
I'm using phpunit with Laravel 4 framework. Why is it that when there's a PHP error during the tests, no error messages are shown (eg: missing method)?
How can we get phpunit to show all errors?
I think the problem is probably refers to a PHP itself, not PHPUnit. Follow this steps:
1. Check proper php.ini
. Note that some systems can use different php.ini
for different PHP SAPI:
php -i | grep php.ini
Configuration File (php.ini) Path => /etc/php5/cli
Loaded Configuration File => /etc/php5/cli/php.ini
2. Edit error output settings. Set appropriate settings for error_reporting, display_errors, display_startup_errors in corresponding php.ini
:
error_reporting = E_ALL
display_errors = On
display_startup_errors = On
If you don't want to change CLI error reporting behavior in global scope, you can use PHPUnit bootstrap file for define those settnigs.
1. Setup bootstrap for PHPUnit. Open /Applications/MAMP/htdocs/testtingDecoded/phpunit.xml
file and add bootstrap attribute to phpunit tag:
<phpunit bootstrap="bootstrap.php">
2. Create bootstrap.php in folder with phpunit.xml
:
<?php
ini_set('error_reporting', E_ALL); // or error_reporting(E_ALL);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
This is a very common issue, especially when you are running tests on a host configured like a production server (usually less verbose) or when the tester isn't very aware of the PHP configuration.
The issue is related to php.ini
settings, as pointed by Alexander Yancharuk in his answer and all the solutions he suggests work fine.
But there is another solution that may be useful, as it was for me, which is to set the appropriate PHP settings in the PHPUnit configuration file (XML) itself, as follows:
<phpunit>
<suites>
...
</suites>
<php>
<ini name="display_errors" value="On" />
<ini name="display_startup_errors" value="On" />
</php>
</phpunit>
Using this you can personalize not only error display, but a lot of PHP configuration, specifically for your test suite, leaving your production configuration untouched and without having to write a bootstrap file only for this.
<php></php>
element to the phpunit.xml
file that comes with Laravel, but no luck. Errors are still not displayed. Any idea why not? –
Devotee I think the problem is probably refers to a PHP itself, not PHPUnit. Follow this steps:
1. Check proper php.ini
. Note that some systems can use different php.ini
for different PHP SAPI:
php -i | grep php.ini
Configuration File (php.ini) Path => /etc/php5/cli
Loaded Configuration File => /etc/php5/cli/php.ini
2. Edit error output settings. Set appropriate settings for error_reporting, display_errors, display_startup_errors in corresponding php.ini
:
error_reporting = E_ALL
display_errors = On
display_startup_errors = On
If you don't want to change CLI error reporting behavior in global scope, you can use PHPUnit bootstrap file for define those settnigs.
1. Setup bootstrap for PHPUnit. Open /Applications/MAMP/htdocs/testtingDecoded/phpunit.xml
file and add bootstrap attribute to phpunit tag:
<phpunit bootstrap="bootstrap.php">
2. Create bootstrap.php in folder with phpunit.xml
:
<?php
ini_set('error_reporting', E_ALL); // or error_reporting(E_ALL);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
In my case I had all the options set, and yet all the console showed was error 255. It turned out that in one of the test files I had syntax not allowed for this version of php. After adjusting this part, in my case, the nullsafe operator available from 8, the tests started working (I was checking compatibility for lower version of app which runs on 7.4)
You should make sure that you have enabled this parameter in your phpunit.xml
config:
displayDetailsOnTestsThatTriggerWarnings="true"
Alternatively, you can enabled just for one run by passing along this flag to phpunit CLI: --display-warnings
© 2022 - 2024 — McMap. All rights reserved.