为什么error_log只使用phpunit's——process-isolation生成RuntimeExce


why error_log generate a RuntimeException only with phpunit's --process-isolation

我进行了一些测试,测试的代码输出了一些error_log信息(因为我也在测试失败,这是预期的)

<?php
Class X {
    function dosomething(){
            error_log('did it');
            return true;
    }
}

和测试:

<?php
require_once 'X.php';
class xTest extends PHPUnit_Framework_TestCase {
    public function testDo(){
            $x = new X();
            $this->assertTrue( $x->dosomething(), 'dosomething returns true');
    }
}

当在php_unit 没有 --process-isolation上运行时,给我一个很好的.,无论我测试通过。

然而,当 --process-isolation运行时,得到:
1) test::a with data set #1 'a'
RuntimeException: did it

为什么会这样?我被卡在3.4.12版本上(对此无能为力),但在更新日志中没有找到任何有趣的内容。

下面是一个示例会话:

xxx$ phpunit xTest.php
PHPUnit 3.4.12 by Sebastian Bergmann.
did it
.
Time: 0 seconds, Memory: 4.50Mb
OK (1 test, 1 assertion)
shell return code: 0
xxx$ phpunit --process-isolation xTest.php
PHPUnit 3.4.12 by Sebastian Bergmann.
E
Time: 0 seconds, Memory: 4.50Mb
There was 1 error:
1) xTest::testDo
RuntimeException: did it

FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
shell return code: 2

编辑:我正在搜索"phpunit rununtimeexception error_log",提交这个5秒后,它已经是最热门的搜索结果:(没有关于它的任何信息。

但是我来这里编辑并说:添加$this->setExpectedException('RuntimeException');绝对不能捕获此问题。

我的猜测是外部和内部进程中的error_log配置之间存在差异。默认情况下,当从CLI运行error_log()时,它将被写入stderr并导致测试失败。你需要做的是找出为什么会有不同。我猜你有一些代码在外部进程中运行,改变了这个配置,而不是在内部进程中运行。