How to resolve this in PHPUnit where it is asking

2020-07-26 11:12发布

问题:

Here is my phpunit.xml file

<?xml version="1.0" encoding="UTF-8"?>
<phpunit
        colors="true"
        convertErrorsToExceptions="true"
        convertNoticesToExceptions="true"
        convertWarningsToExceptions="true"
        stopOnFailure="true"
        strict="true"
        bootstrap="./vendor/autoload.php">
    <testsuites>
        <php>
            <server name="KERNEL_DIR" value="app" />
            <ini name="display_errors" value="true"/>
        </php>
        <testsuite name="Functional Tests">
            <directory>./tests/src/myApp/AppBundle/functional</directory>
        </testsuite>
    </testsuites>

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

Here is the test class

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class MyTest extends WebTestCase
{
    private $client;

    public function setUp()
    {
        $this->client = static::createClient();
    }

When running the test I get at the line in setUp:

Either set KERNEL_DIR in your phpunit.xml according to https://symfony.com/doc/current/book/testing.html#your-first-functional-test or override the WebTestCase::createKernel() method

回答1:

Move the <php> ... </php> out of the <testsuites>... block to it's own top-level.

Here's a trimmed down copy of my own main project:

<phpunit 
    bootstrap = "app/bootstrap_test.php"
    verbose = "true"
>
    <php>
        <ini name="memory_limit" value="-1" />
        <!-- <server name="KERNEL_DIR" value="./app/" /> older-style -->
        <server name="KERNEL_CLASS" value="AppKernel" />
        <server name="SYMFONY_DEPRECATIONS_HELPER" value="weak" />
    </php>

    <testsuites>
        <testsuite name="project.name">
            <directory suffix=".php">./src/*Bundle</directory>
            <directory suffix=".php">./src/AppBundle</directory> -->
            <directory>./tests/App</directory>
        </testsuite>
    </testsuites>