symfony:无法运行功能测试

时间:2019-09-05 12:05:03

标签: symfony phpunit

版本: Symfony的3.4 phpunit 8.3

我的phpunit.xml文件:

2019-08-24 01:03:44.732999

我的测试文件:

<?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/4.8/phpunit.xsd"
         backupGlobals="false"
         colors="true"
         bootstrap="autoload.php">
    <php>
        <ini name="error_reporting" value="-1" />
        <env name="SYMFONY_DEPRECATIONS_HELPER" value="weak" />
        <!--
            <server name="KERNEL_DIR" value="/path/to/your/app/" />
        -->
    </php>

    <testsuites>
        <testsuite name="Project Test Suite">
            <directory>../src/*/*Bundle/Tests</directory>
            <directory>../src/*/Bundle/*Bundle/Tests</directory>
            <directory>../src/*Bundle/Tests</directory>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist>
            <directory>../src</directory>
            <exclude>
                <directory>../src/*Bundle/Resources</directory>
                <directory>../src/*Bundle/Tests</directory>
                <directory>../src/*/*Bundle/Resources</directory>
                <directory>../src/*/*Bundle/Tests</directory>
                <directory>../src/*/Bundle/*Bundle/Resources</directory>
                <directory>../src/*/Bundle/*Bundle/Tests</directory>
            </exclude>
        </whitelist>
    </filter>
</phpunit>

如果我像这样运行测试,就会出现此错误:

  

{“代码”:500,“消息”:“不允许对'SimpleXMLElement'进行序列化”}    C:\ wamp64 \ www \ chronos2017 \ src \ tests \ AppBundle \ Controller \ QuittancementControllerTest.php:44

写有状态200的断言,第二个断言为false,但是phpunit无法正确显示结果

如果我删除“ @runInSeparateProcess”行,则客户端调用失败:

  

{“代码”:500,“消息”:“未能启动会话,因为标头已经由\“ C:\ wamp64 \ www \ mySite \ src \ vendor \ phpunit \ phpunit \ src \ Util \发送Printer.php \“位于第109行。”}

使用symfony进行功能测试的正确方法是什么?你能帮我吗?

1 个答案:

答案 0 :(得分:0)

我也使用symfony 3.4,但使用的是phpunit 7,所以也许是因为phpunit 8,但是我不需要对phpunit.xml文件进行任何修改。根据错误,您的错误似乎来自xml文件。

我猜您已经使用过文档,但如果没有使用,则为:https://symfony.com/doc/3.4/testing.html

我的文件:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="phpunit.xsd"
         bootstrap="tests/bootstrap.php"
         cacheResult="true"
         verbose="true">
    <testsuites>
        <testsuite name="unit">
            <directory suffix="Test.php">tests/unit</directory>
        </testsuite>

        <testsuite name="end-to-end">
            <directory suffix=".phpt">tests/end-to-end</directory>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">src</directory>
            <exclude>
                <file>src/Framework/Assert/Functions.php</file>
                <file>src/Util/PHP/eval-stdin.php</file>
            </exclude>
        </whitelist>
    </filter>

    <php>
        <const name="PHPUNIT_TESTSUITE" value="true"/>
    </php>
</phpunit>