首页 > 解决方案 > 当我打开 Xdebug 时,phpunit 引导设置不起作用

问题描述

我在使用 Xdebug 和 PHPUnit 时遇到问题。
因为我想使用AspectMock,所以我在 phpunit.xml 配置中创建了引导程序,它运行良好。
但是,当我尝试打开 Xdebug 以生成覆盖率报告时,它并没有使用我的引导设置。(我不确定是因为它没有读取或引导设置被覆盖)
我不知道为什么或在哪里可以找到错误。

这是结果示例(我已经转储了我的模拟):(与 -c phpunit.xml 相同)

$vendor/bin/phpunit test.php

array: [
  "status" => "successed", 
  "data" => ["test" => "test"]
]

$vendor/bin/phpunit --coverage-html build/coverage test.php(因为数据没有模拟)

array: [
  "status" => "failed", 
  "data" => []
]



php.ini

[Xdebug]
zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so
xdebug.remote_enable=On


$php -v

PHP 7.1.16 (cli) (built: Mar 31 2018 02:59:59) (NTS)
版权所有 (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
with Xdebug v2 .6.1,版权所有 (c) 2002-2018,作者 Derick Rethans


phpunit.xml

<?xml version="1.0" encoding="UTF-8"?>                                                                               
<phpunit backupGlobals="false"                                                                                       
         backupStaticAttributes="false"                                                                              
         bootstrap="tests/bootstrap.php"                                                                             
         colors="true"                                                                                               
         convertErrorsToExceptions="true"                                                                            
         convertNoticesToExceptions="true"                                                                           
         convertWarningsToExceptions="true"                                                                          
         processIsolation="false"                                                                                    
         stopOnFailure="false">                                                                                      
    <testsuites>                                                                                                     
        <testsuite name="test">                                                                               
            <directory suffix="Test.php">./tests</directory>                                                         
        </testsuite>                                                                                                 
    </testsuites>                                                                                                    

<filter>                                                                                                         
    <whitelist processUncoveredFilesFromWhitelist="true">                                                        
        <directory suffix=".php">./app</directory>                                                               
    </whitelist>                                                                                                 
</filter> 

</phpunit>

测试/bootstrap.php

<?php                                                                                                                
include __DIR__.'/../vendor/autoload.php'; // composer autoload                                                      

$kernel = \AspectMock\Kernel::getInstance();                                                                         
$kernel->init([                                                                                                      
    'debug' => true,                                                                                                 
    'includePaths' => [__DIR__.'/../app'],                                                                           
    'cacheDir' => __DIR__.'/cache/aspectmock',                                                                       
    'excludePaths' => [                                                                                              
        __DIR__,                                                                                                     
        __DIR__ . '../../vendor',                                                                                    
    ],                                                                                                               
]); 

标签: phplaravelphpunitxdebug

解决方案


推荐阅读