PhpUnit测试通过Missing参数1传递

时间:2016-10-26 08:13:59

标签: php phpunit

当我运行测试时,会发出以下警告: 缺少参数1 ...

单元测试通过,是否可以让测试失败?

这是我的PhpUnit.xml

<phpunit bootstrap="bootstrap.php"
         colors="false"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         strict="true">
    <selenium>
        <browser name="Internet Explorer" browser="*iexplore" />
        <browser name="Firefox" browser="*firefox" />
    </selenium>
    <filter>
        <whitelist>
            <directory>../src</directory>
        </whitelist>
    </filter>
    <testsuites>
        <testsuite name="unitTests">
            <directory suffix="Test.php">*</directory>
        </testsuite>
    </testsuites>
    <logging>
        <log type="coverage-html" target="../build/coverage" />
        <log type="coverage-clover" target="../build/logs/clover.xml" />
        <log type="coverage-crap4j" target="../build/logs/crap4j.xml" />
    </logging>
</phpunit>

这是php日志:  缺少xx function()的参数1,在第37行的xx中调用并定义(错误类型:第78行的xx中的警告)

1 个答案:

答案 0 :(得分:1)

我找到了一点hackish解决方案:)

class THE_GREATEST_EVER_PHPUnit_Framework_TestCase extends \PHPUnit_Framework_TestCase
{
    public static function setUpBeforeClass() {
        set_error_handler(function($errno, $errstr, $errfile, $errline) {
            throw new \RuntimeException($errstr . " on line " . $errline . " in file " . $errfile);
        });
    }

    public function tearDown() {
        restore_error_handler();
    }

}