Phpunit: phpdbg下进程隔离抛出异常

创建于 2019-11-30  ·  3评论  ·  资料来源: sebastianbergmann/phpunit

- 请不要报告不再支持的 PHPUnit 版本的问题。 当前支持的 PHPUnit 版本列表可在 https://phpunit.de/supported-versions.html 获得。 - 如果您使用的 PHP 版本不受您使用的 PHPUnit 版本支持,请不要报告问题。 在 https://phpunit.de/supported-versions.html 上提供了一个列表,显示哪个版本的 PHPUnit 支持哪个版本的 PHPUnit。 - 请根据您的问题填写此模板。 - 请将下表显示在您问题的顶部。 - 如果您使用 Composer 安装 PHPUnit,请包括“composer info | sort”的输出。 - 请将代码作为文本发布(使用适当的标记)。 不要发布代码的屏幕截图。 - 如果您正在寻求支持,请访问 https://phpunit.de/support.html。 - 请在提交问题之前删除此评论。

| 问 | 一种
| --------------------| ---------------
| PHPUnit 版本 | 8.4.3
| PHP版本| 7.4.0 (phpdbg SAPI)
| 安装方法 | 作曲家

概括

使用进程隔离会在phpdbg下引发异常。 起初我以为这是#3772的回归,但似乎是一个单独的原因。

我认为这是能够跟踪bug到这条线在TestCaseMethod.tpl (也有类似的代码在TestCaseClass.tpl )。 这两行都尝试从STDOUT读取,而没有先检查它是否是可读流。

如果我使用stream_get_meta_data(STDOUT)放入调试语句,您可以看到STDOUT不可读:

array(9) {
  ["timed_out"]=>
  bool(false)
  ["blocked"]=>
  bool(true)
  ["eof"]=>
  bool(false)
  ["wrapper_type"]=>
  string(3) "PHP"
  ["stream_type"]=>
  string(5) "STDIO"
  ["mode"]=>
  string(2) "wb"
  ["unread_bytes"]=>
  int(0)
  ["seekable"]=>
  bool(false)
  ["uri"]=>
  string(12) "php://stdout"
}

也可以看看:

当前行为

任何在phpdbg下使用进程隔离的测试都不会运行,而是抛出类似于: PHPUnit\Framework\Exception: Notice: stream_get_contents(): read of 8192 bytes failed with errno=9 Bad file descriptor in Standard input code on line 336的异常。

如何繁殖

phpdbg下运行此测试:

<?php

use PHPUnit\Framework\TestCase;

class ReproTest extends TestCase
{
    /**
     * <strong i="20">@doesNotPerformAssertions</strong>
     * <strong i="21">@runInSeparateProcess</strong>
     */
    public function testProcessIsolation()
    {
    }
}

并看到这个输出:

$ phpdbg -qrr vendor/bin/phpunit
PHPUnit 8.4.3 by Sebastian Bergmann and contributors.

E                                                                   1 / 1 (100%)

Time: 121 ms, Memory: 6.00 MB

There was 1 error:

1) ReproTest::testProcessIsolation
PHPUnit\Framework\Exception: Notice: stream_get_contents(): read of 8192 bytes failed with errno=9 Bad file descriptor in Standard input code on line 336

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.

预期行为

进程隔离应该以与其他 PHP SAPI 相同的方式对phpdbg起作用。

composer info | sort

doctrine/instantiator              1.3.0   A small, lightweight utility to instantiate objects in PHP without invoking their constructors
myclabs/deep-copy                  1.9.3   Create deep copies (clones) of your objects
phar-io/manifest                   1.0.3   Component for reading phar.io manifest information from a PHP Archive (PHAR)
phar-io/version                    2.0.1   Library for handling version information and constraints
phpdocumentor/reflection-common    2.0.0   Common reflection classes used by phpdocumentor to reflect the code structure
phpdocumentor/reflection-docblock  4.3.2   With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.
phpdocumentor/type-resolver        1.0.1   A PSR-5 based resolver of Class names, Types and Structural Element Names
phpspec/prophecy                   1.9.0   Highly opinionated mocking framework for PHP 5.3+
phpunit/php-code-coverage          7.0.10  Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator          2.0.2   FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-text-template          1.2.1   Simple template engine.
phpunit/php-timer                  2.1.2   Utility class for timing
phpunit/php-token-stream           3.1.1   Wrapper around PHP's tokenizer extension.
phpunit/phpunit                    8.4.3   The PHP Unit Testing framework.
sebastian/code-unit-reverse-lookup 1.0.1   Looks up which function or method a line of code belongs to
sebastian/comparator               3.0.2   Provides the functionality to compare PHP values for equality
sebastian/diff                     3.0.2   Diff implementation
sebastian/environment              4.2.3   Provides functionality to handle HHVM/PHP environments
sebastian/exporter                 3.1.2   Provides the functionality to export PHP variables for visualization
sebastian/global-state             3.0.0   Snapshotting of global state
sebastian/object-enumerator        3.0.3   Traverses array structures and object graphs to enumerate all referenced objects
sebastian/object-reflector         1.1.1   Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context        3.0.0   Provides functionality to recursively process PHP variables
sebastian/resource-operations      2.0.1   Provides a list of PHP built-in functions that operate on resources
sebastian/type                     1.1.3   Collection of value objects that represent the types of the PHP type system
sebastian/version                  2.0.1   Library that helps with managing the version number of Git-hosted PHP projects
symfony/polyfill-ctype             v1.13.0 Symfony polyfill for ctype functions
theseer/tokenizer                  1.1.3   A small library for converting tokenized PHP source code into XML and potentially other formats
webmozart/assert                   1.6.0   Assertions to validate method input/output with nice error messages.
featurprocess-isolation typbug

所有3条评论

我确定。

我不会花时间调试只影响 PHPDBG 的问题。 老实说,我正在考虑从 php-code-coverage 以及 PHPUnit 本身中删除对它的支持。

仅举个例子,当使用常规 PHP 时,它也会将流报告为不可读:

php -r 'echo stream_get_meta_data(STDOUT)["mode"], "\n";' | cat
// Outputs: wb

这个问题最早出现在 PHP 7.4.0 中。 这可能是一个 PHP 错误,但我不知道更好。

此页面是否有帮助?
0 / 5 - 0 等级