【问题标题】:PhpUnit test passes with Missing argument 1PhpUnit 测试通过缺少参数 1
【发布时间】:2016-10-26 17:16:38
【问题描述】:

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

unittest通过了,能不能让test失败?

这是我的 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 警告)

【问题讨论】:

    标签: php phpunit


    【解决方案1】:

    我找到了一个有点骇人听闻的解决方案 :)

    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();
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 2013-01-09
      • 2017-10-05
      • 1970-01-01
      • 2014-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多