问题描述
我在Laravel 4框架中使用phpunit.为什么在测试过程中出现PHP错误时,没有显示错误消息(例如:缺少方法)?
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)?
我们如何让phpunit显示所有错误?
How can we get phpunit to show all errors?
推荐答案
我认为问题可能出在PHP本身,而不是PHPUnit.请按照以下步骤操作:
I think the problem is probably refers to a PHP itself, not PHPUnit. Follow this steps:
1.检查正确的php.ini
.请注意,某些系统可以对不同的PHP SAPI使用不同的php.ini
:
php -i | grep php.ini
Configuration File (php.ini) Path => /etc/php5/cli
Loaded Configuration File => /etc/php5/cli/php.ini
2.编辑错误输出设置.为 error_reporting , display_errors , display_startup_errors 在相应的php.ini
:
error_reporting = E_ALL
display_errors = On
display_startup_errors = On
如果您不想在全局范围内更改CLI错误报告行为,则可以使用PHPUnit引导程序文件来定义这些设置.
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.为PHPUnit设置引导程序.打开/Applications/MAMP/htdocs/testtingDecoded/phpunit.xml
文件,并将bootstrap属性添加到phpunit标签:
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.在phpunit.xml
文件夹中创建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');
这篇关于为什么phpunit在控制台中不显示任何错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!