简体   繁体   English

由于语法错误或致命错误,如何在PHPunit中导出失败的测试?

[英]How do I export failed tests in PHPunit due to syntax errors or Fatal errors?

Below is my phpunit.xml file. 以下是我的phpunit.xml文件。 All methods of logging stop as soon as a PHP fatal error is achieved. 一旦发生PHP致命错误,所有日志记录方法都会停止。 I want to be able to have a log of this error. 我希望能够有此错误的日志。

<phpunit verbose="true" colors="true" stopOnFailure="false" syntaxCheck="true">
    <logging>
    <log type="tap" target="results/results.tap"/>
    <log type="testdox-text" target="results/results.txt" />
        <log type="junit" target="results/results.junit" logIncompleteSkipped="true"/>
        <log type="json" target="results/results.js"/>
        <log type="coverage-html" target="results/report" charset="UTF-8"
           yui="false" highlight="false"
           lowUpperBound="35" highLowerBound="70"/>
    </logging>
</phpunit>

Since phpunit (or rather your tests) run in a fatal error the php interpreter isn't able to do much more than die so logging via phpunit seems rather hard. 由于phpunit(或更确切地说是您的测试)在致命错误中运行,因此php解释器无法执行的工作远不止于此,因此通过phpunit进行日志记录似乎相当困难。

Maybe running each test as seperate process ( Using the --process-isolation switch or setting processIsolation="true" ) might help you a little bit. 也许将每个测试作为单独的进程运行(使用--process-isolation开关或设置processIsolation =“ true”)可能会对您有所帮助。 But that slows down your Testsuite and so on. 但这会使您的Testsuite变慢,等等。

So as a quick solution you could put the error output of php into a logfile (in case display_errors is on). 因此,作为一种快速的解决方案,您可以将php的错误输出放入日志文件中(以防display_errors打开)。

phpunit yourTests 2> errors.log

Maybe use a different php.ini for your testruns and provide a logfile there or just pass it to php via 也许为您的测试运行使用不同的php.ini并在那里提供日志文件,或者通过以下方式将其传递给php

echo "" > error.log && phpunit -d error_log=error.log yourTests

so you at least have a file with the errors to check against. 因此,您至少要有一个要检查错误的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM