gpt4 book ai didi

PHPUnit - 为什么 PHPUnit 似乎在严格模式下运行?

转载 作者:可可西里 更新时间:2023-11-01 12:54:12 44 4
gpt4 key购买 nike

问题:为什么 PHPUnit 似乎在严格模式下运行?

问题:

PHPUnit 4.3.1 by Sebastian Bergmann.

Configuration read from /full/path/to/configuration.xml

R

Time: 2.65 seconds, Memory: 11.50Mb

OK, but incomplete, skipped, or risky tests! Tests: 1, Assertions: 1, Risky: 1. Done.

还有:

Risky Test: Test code or tested code did not (only) close its own output buffers

我的 PHP 版本是 5.4。

如文档 (https://phpunit.de/manual/current/en/strict-mode.html) 中所述,这似乎仅适用于 PHPUnits 的严格模式设置。

PHPUnit can perform additional checks while it executes the tests. In addition to the fine-grained control over the various strict mode checks (see below) you may use the --strict commandline option or set strict="true" in PHPUnit's XML configuration file to enable all of them.

-

Output During Test Execution

PHPUnit can be strict about output during tests. This check can be enabled by using the --disallow-test-output option on the commandline or by setting beStrictAboutOutputDuringTests="true" in PHPUnit's XML configuration file.

A test that emits output, for instance by invoking print in either the test code or the tested code, will be marked as risky when this check is enabled.

不过我相信我没有激活严格模式。我的命令行是“/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>

我之前使用过此配置的较短版本,结果相同。

<phpunit
beStrictAboutOutputDuringTests="false"
strict="false"
colors="false">
</phpunit>

最佳答案

查看 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;
}
}

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

在您最喜欢的 PHPUnit 测试调试器的上述行中放置断点可能会揭示一些其他依赖项(例如 disallowTestOutput 标志...?)

关于PHPUnit - 为什么 PHPUnit 似乎在严格模式下运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27329949/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com