And*_*s B 7 php phpunit unit-testing
问题:为什么PHPUnit似乎在严格模式下运行?
问题:
Sebastian Bergmann的PHPUnit 4.3.1.
配置从/full/path/to/configuration.xml读取
[R
时间:2.65秒,内存:11.50Mb
好的,但不完整,跳过或有风险的测试!测试:1,断言:1,风险:1.完成.
也:
危险测试:测试代码或测试代码没有(仅)关闭自己的输出缓冲区
我的PHP版本是5.4.
如文档(https://phpunit.de/manual/current/en/strict-mode.html)中所述,这似乎仅适用于PHPUnits的严格模式设置.
PHPUnit可以在执行测试时执行其他检查.除了对各种严格模式检查(见下文)的细粒度控制之外,您可以在PHPUnit的XML配置文件中使用--strict命令行选项或set strict ="true"来启用所有这些选项.
-
测试执行期间的输出
PHPUnit在测试期间可以严格控制输出.可以通过在命令行上使用--disallow-test-output选项或在PHPUnit的XML配置文件中设置beStrictAboutOutputDuringTests ="true"来启用此检查.
发出输出的测试(例如通过在测试代码或测试代码中调用print)将在启用此检查时标记为有风险.
我相信,我没有激活严格模式.我的命令行是"/ usr/bin/php/usr/bin/phpunit --colors --bootstrap /full/path/to/bootstrap.php --configuration/full/path/to/configuration.xml/full/path /to/Test.php".我还使用了" https://phpunit.de/manual/current/en/appendixes.configuration.html "中提供的配置.
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.3/phpunit.xsd"
backupGlobals="true"
backupStaticAttributes="false"
cacheTokens="false"
colors="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
mapTestClassNameToCoveredClassName="false"
printerClass="PHPUnit_TextUI_ResultPrinter"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader"
timeoutForSmallTests="1"
timeoutForMediumTests="10"
timeoutForLargeTests="60"
strict="false"
verbose="false">
</phpunit>
Run Code Online (Sandbox Code Playgroud)
我之前使用过这种配置的较短版本,提供了相同的结果.
<phpunit
beStrictAboutOutputDuringTests="false"
strict="false"
colors="false">
</phpunit>
Run Code Online (Sandbox Code Playgroud)
看看GitHub 它上面的代码似乎无论文档说什么,都会检查并报告输出缓冲问题.
因此,您观察到的症状并不意味着测试以strict模式运行.
github.com/sebastianbergmann/phpunit/blob/4.3/src/Framework/TestCase.php#L818
// ...
try {
$this->stopOutputBuffering();
} catch (PHPUnit_Framework_RiskyTestError $_e) {
if (!isset($e)) {
$e = $_e;
}
}
Run Code Online (Sandbox Code Playgroud)
github.com/sebastianbergmann/phpunit/blob/4.3/src/Framework/TestCase.php#L1938-L1946
private function stopOutputBuffering()
{
if (ob_get_level() != $this->outputBufferingLevel) {
while (ob_get_level() > 0) {
ob_end_clean();
}
throw new PHPUnit_Framework_RiskyTestError(
'Test code or tested code did not (only) close its own output buffers'
);
}
// ...
$this->outputBufferingActive = false;
$this->outputBufferingLevel = ob_get_level();
}
Run Code Online (Sandbox Code Playgroud)
在您最喜欢的PHPUnit测试调试器的上面的行放置断点可能会揭示一些其他依赖项(如disallowTestOutput标志......?)