4

I have a problem when using Xdebug and PHPUnit.
Because I want to use AspectMock, so I create bootstrap in phpunit.xml configuration and it goes well.
However, when I try to turn on Xdebug to generate coverage report, it didn't use my bootstrap setting. (I'm not sure it's because it didn't read or the bootstrap setting was been covered)
I don't know why or where to find bugs.

Here is the result example(I have dump my mock): (it's the same with -c phpunit.xml)

$vendor/bin/phpunit test.php

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

$vendor/bin/phpunit --coverage-html build/coverage test.php (Because data didn't mock)

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 )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
with Xdebug v2.6.1, Copyright (c) 2002-2018, by 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>

tests/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',                                                                                    
    ],                                                                                                               
]); 
Sunny-work
  • 41
  • 2

0 Answers0