我正在使用phpunit和Laravel 4框架。爲什麼當測試過程中出現PHP錯誤時,沒有顯示錯誤消息(例如:缺少方法)?爲什麼phpunit在控制檯中不顯示任何錯誤
我們如何讓phpunit顯示所有錯誤?
我正在使用phpunit和Laravel 4框架。爲什麼當測試過程中出現PHP錯誤時,沒有顯示錯誤消息(例如:缺少方法)?爲什麼phpunit在控制檯中不顯示任何錯誤
我們如何讓phpunit顯示所有錯誤?
我認爲這個問題可能是指一個PHP本身,而不是PHPUnit的。請按照下列步驟操作:
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.編輯錯誤輸出設置。在相應的php.ini
爲error_reporting設置適當的設置,display_errors,display_startup_errors:
error_reporting = E_ALL
display_errors = On
display_startup_errors = On
如果你不想改變CLI錯誤報告在全球範圍內的行爲,你可以使用定義這些settnigs PHPUnit的引導文件。
1.爲PHPUnit設置引導程序。打開/Applications/MAMP/htdocs/testtingDecoded/phpunit.xml
文件和引導屬性添加到PHPUnit的標籤:
<phpunit bootstrap="bootstrap.php">
2.在文件夾中創建phpunit.xml
bootstrap.php中:
<?php
ini_set('error_reporting', E_ALL); // or error_reporting(E_ALL);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
這是一個很常見的問題,尤其是當你正在運行在生產服務器上進行測試,或者測試人員不太瞭解PHP配置。
該問題與php.ini
設置有關,正如Alexander Yancharuk在他的回答中指出的那樣,以及他建議的所有解決方案都可以正常工作。
但還有另一種解決方案可能是有用的,因爲這是對我來說,這是設置PHPUnit的配置文件(XML)本身在適當的PHP設置,如下所示:
<phpunit>
<suites>
...
</suites>
<php>
<ini name="display_errors" value="On" />
<ini name="display_startup_errors" value="On" />
</php>
</phpunit>
使用此您不僅可以個性化錯誤顯示,還可以個性化PHP配置,特別是針對您的測試套件,使您的生產配置保持不變,而不必爲此只寫一個引導文件。
我試過了,但它不適合我。只是想知道我是否錯過了一些東西。我在運行High Sierra的Mac上使用Laravel 5.6。 PHP版本PHP 7.1.7和phpunit 7.0.0。我將'
你可以得到所有的PHPunit錯誤。 [This one] [1]或[This one] [2]將對你有用。 [1]:http://stackoverflow.com/questions/3569862/phpunit-errors [2]:http://stackoverflow.com/questions/5994729/phpunit-not-showing-a-stack-trace -for-a-php-fatal-error – 2013-10-23 09:19:31