Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve this in PHPUnit where it is asking me to set KERNEL_DIR in my phpunit.xml?

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

like image 354
Michael Millar Avatar asked Jan 28 '23 13:01

Michael Millar


1 Answers

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>
like image 105
Alister Bulman Avatar answered Jan 31 '23 08:01

Alister Bulman