Php Symfony 3.4-我们可以收集功能测试的代码覆盖率吗?

Php Symfony 3.4-我们可以收集功能测试的代码覆盖率吗?,php,symfony,phpunit,code-coverage,Php,Symfony,Phpunit,Code Coverage,我正在为我们的一些项目使用symfony 3.4。根据文档,我们应该为我们的控制器编写功能测试。然而,我们似乎无法收集功能测试的代码覆盖率,因为symfony将在另一个PHP进程中运行主代码 在phpunit进程中:var\u dump(xdebug\u code\u coverage\u start())=>true 在控制器代码中:var\u dump(xdebug\u code\u coverage\u start())=> 错误 更新:似乎只有当我将测试放在另一个文件夹src文件夹中

我正在为我们的一些项目使用symfony 3.4。根据文档,我们应该为我们的控制器编写功能测试。然而,我们似乎无法收集功能测试的代码覆盖率,因为symfony将在另一个PHP进程中运行主代码

  • 在phpunit进程中:
    var\u dump(xdebug\u code\u coverage\u start())=>true
  • 在控制器代码中:
    var\u dump(xdebug\u code\u coverage\u start())=>
    错误
更新:似乎只有当我将测试放在另一个文件夹
src
文件夹中时,问题才会出现。当我将测试放在同一个bundle文件夹(
src/MyBubndle/tests
)中时,它会工作

PHP单元配置

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.0/phpunit.xsd"
         backupGlobals="false"
         colors="true"
         processIsolation = "false"
         bootstrap="vendor/autoload.php"
>
    <php>
        <ini name="error_reporting" value="-1" />
        <server name="KERNEL_DIR" value="app/" />
        <env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
        <!--<env name="KERNEL_CLASS" value="App\Kernel" />-->
        <env name="APP_ENV" value="test"/>
        <env name="APP_DEBUG" value="1"/>
        <env name="SYMFONY_ENV" value="test"/>
        <env name="MYSQL_SERVER" value="127.0.0.1"/>
        <env name="MYSQL_DATABASE" value="db"/>
        <env name="MYSQL_USER" value="root"/>
        <env name="MYSQL_PASSWORD" value="root"/>
        <env name="MYSQL_PORT" value="3306"/>
        <env name="JWT_PUBLIC_KEY_PATH" value="jwt/public.pem"/>
        <env name="SYMFONY_PHPUNIT_VERSION" value="6.5.5"/>
    </php>

    <testsuites>
        <testsuite name="Project Test Suite">
            <directory suffix="Test.php" >.</directory>
            <exclude>vendor</exclude>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist>
            <directory suffix=".php">.</directory>
            <exclude>
                <directory>src/*Bundle/Resources</directory>
                <directory>src/*/*Bundle/Resources</directory>
                <directory>src/*/Bundle/*Bundle/Resources</directory>
                <directory>app</directory>
                <directory>bin</directory>
                <directory>docker</directory>
                <directory>jwt</directory>
                <directory>var</directory>
                <directory>vendor</directory>
                <directory>web</directory>
                <directory>tests</directory>
            </exclude>
        </whitelist>
    </filter>
    <logging>
        <log type="coverage-html" target="./var/logs/codeCoverage" charset="UTF-8"
             yui="true" highlight="true"
             lowUpperBound="50" highLowerBound="80"/>
        <log type="coverage-text" target="php://stdout" showOnlySummary = "true" showUncoveredFiles="false"/>
        <log type="testdox-html" target="./var/logs/testdox.html" />
        <log type="junit" target="./var/logs/testreport.xml" logIncompleteSkipped="false"/>
        <log type="coverage-clover" target="./var/logs/coverage.xml"/>
    </logging>
    <!--<listeners>-->
        <!--<listener class="Symfony\Bridge\PhpUnit\CoverageListener" />-->
    <!--</listeners>-->
</phpunit>

.
小贩
.
src/*Bundle/Resources
src/*/*捆绑包/资源
src/*/Bundle/*Bundle/Resources
应用程序
箱子
码头工人
jwt
变量
小贩
网状物
测验
还尝试:

<?xml version="1.0" encoding="UTF-8"?>

<!-- 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/6.0/phpunit.xsd"
         backupGlobals="false"
         colors="true"
         processIsolation = "false"
         bootstrap="vendor/autoload.php"
>
    <php>
        <ini name="error_reporting" value="-1" />
        <server name="KERNEL_DIR" value="app/" />
        <env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
        <!--<env name="KERNEL_CLASS" value="App\Kernel" />-->
        <env name="APP_ENV" value="test"/>
        <env name="APP_DEBUG" value="1"/>
        <env name="SYMFONY_ENV" value="test"/>
        <env name="MYSQL_SERVER" value="127.0.0.1"/>
        <env name="MYSQL_DATABASE" value="db"/>
        <env name="MYSQL_USER" value="root"/>
        <env name="MYSQL_PASSWORD" value="root"/>
        <env name="MYSQL_PORT" value="3306"/>
        <env name="JWT_PUBLIC_KEY_PATH" value="jwt/public.pem"/>
        <env name="SYMFONY_PHPUNIT_VERSION" value="6.5.5"/>
    </php>

    <testsuites>
        <testsuite name="Project Test Suite">
            <directory suffix="Test.php" >./tests</directory>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist>
            <directory suffix=".php">./src</directory>
            <exclude>
                <directory>src/*Bundle/Resources</directory>
                <directory>src/*/*Bundle/Resources</directory>
                <directory>src/*/Bundle/*Bundle/Resources</directory>
               </exclude>
        </whitelist>
    </filter>
    <logging>
        <log type="coverage-html" target="./var/logs/codeCoverage" charset="UTF-8"
             yui="true" highlight="true"
             lowUpperBound="50" highLowerBound="80"/>
        <log type="coverage-text" target="php://stdout" showOnlySummary = "true" showUncoveredFiles="false"/>
        <log type="testdox-html" target="./var/logs/testdox.html" />
        <log type="junit" target="./var/logs/testreport.xml" logIncompleteSkipped="false"/>
        <log type="coverage-clover" target="./var/logs/coverage.xml"/>
    </logging>
    <!--<listeners>-->
        <!--<listener class="Symfony\Bridge\PhpUnit\CoverageListener" />-->
    <!--</listeners>-->
</phpunit>

/测试
/src
src/*Bundle/Resources
src/*/*捆绑包/资源
src/*/Bundle/*Bundle/Resources
在不使用其他测试框架的情况下,是否有解决方法


非常感谢您的帮助

请编辑您的问题,以包含
phpunit.xml
@geoB的内容。我更新了phpunit.xmltried上的phpunit配置
/src/*
/*
,它仍然没有工作面对一个非常旧的遗留symfony
2.8.52
项目和PhpUnit
4.8.36
的相同问题-我们准备开始重构,以逐步将其从sf2升级到3、4和5,我们想做的第一件事是围绕遗留创建“功能测试”,而不涉及源代码,所以我们可以在以后适当地重构。我们希望确保所有要重构的文件都能覆盖100%。不过,我无法检查保险范围。