为什么代码覆盖率报告在php 7.2上失败?

时间:2017-06-14 16:44:52

标签: php phpunit code-coverage travis-ci php-7.2

我在travis-ci上为php 7.0和7.2运行了一个php构建矩阵。

https://travis-ci.org/uawcob/course-overrides/jobs/242630482

在7.0上,测试全部通过,代码覆盖率生成正常。

php 7 screenshot passes great

在7.2上,您可以看到所有测试都运行并传递相同,但生成代码覆盖率报告会引发异常,从而导致整个构建失败

screenshot php 7.2 code coverage exception

为什么会这样?

后代的完整错误堆栈:

Generating code coverage report in HTML format ...PHP Fatal error:  Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Container/Container.php:895
Stack trace:
#0 /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Container/Container.php(735): Illuminate\Container\Container->notInstantiable('Illuminate\\Cont...')
#1 /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Container/Container.php(608): Illuminate\Container\Container->build('Illuminate\\Cont...')
#2 /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Container/Container.php(575): Illuminate\Container\Container->resolve('Illuminate\\Cont...')
#3 /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(728): Illuminate\Container\Container->make('Illuminate\\Cont...')
#4 /home/travis/build/uawcob/cour in /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 895
Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 895
Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 895
Call Stack:
    3.7921    6622616   1. Illuminate\Foundation\Bootstrap\HandleExceptions->handleException() /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:0
    3.7921    6622616   2. Illuminate\Foundation\Bootstrap\HandleExceptions->getExceptionHandler() /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:80
    3.7921    6622616   3. Illuminate\Foundation\Application->make() /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:155
    3.7921    6622616   4. Illuminate\Foundation\Application->make() /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:728
    3.7921    6622616   5. Illuminate\Foundation\Application->resolve() /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Container/Container.php:575
    3.7921    6622616   6. Illuminate\Foundation\Application->build() /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Container/Container.php:608
    3.7921    6622728   7. Illuminate\Foundation\Application->notInstantiable() /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Container/Container.php:735
PHP Fatal error:  Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Container/Container.php:895
Stack trace:
#0 /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Container/Container.php(735): Illuminate\Container\Container->notInstantiable('Illuminate\\Cont...')
#1 /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Container/Container.php(608): Illuminate\Container\Container->build('Illuminate\\Cont...')
#2 /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Container/Container.php(575): Illuminate\Container\Container->resolve('Illuminate\\Cont...')
#3 /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(728): Illuminate\Container\Container->make('Illuminate\\Cont...')
#4 /home/travis/build/uawcob/cour in /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 895
Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 895
Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 895
Call Stack:
    3.7929    6633672   1. Illuminate\Foundation\Bootstrap\HandleExceptions->handleShutdown() /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:0
    3.7938    6641592   2. Illuminate\Foundation\Bootstrap\HandleExceptions->handleException() /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:119
    3.7938    6641592   3. Illuminate\Foundation\Bootstrap\HandleExceptions->getExceptionHandler() /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:80
    3.7938    6641592   4. Illuminate\Foundation\Application->make() /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:155
    3.7938    6641592   5. Illuminate\Foundation\Application->make() /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:728
    3.7938    6641592   6. Illuminate\Foundation\Application->resolve() /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Container/Container.php:575
    3.7939    6641592   7. Illuminate\Foundation\Application->build() /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Container/Container.php:608
    3.7939    6641704   8. Illuminate\Foundation\Application->notInstantiable() /home/travis/build/uawcob/course-overrides/vendor/laravel/framework/src/Illuminate/Container/Container.php:735

1 个答案:

答案 0 :(得分:2)

查看代码中的确切错误消息,the proposed fix upstream是从代码覆盖率中排除./app/Http/routes.php文件:

...
<whitelist processUncoveredFilesFromWhitelist="true">
    <directory suffix=".php">./app</directory>
        <exclude>
            <file>./app/Http/routes.php</file>

            <!-- ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^  -->

...

通过快速查看检查项目失败的构建源,可以看出这还没有在phpunit.xml.dist文件中设置。我不能说为什么这只发生在PHP 7.2版本中。因此,这可以减少一些光,也许这会响铃(例如不同的Phpunit版本)。