RuntimeException : Unable to guess the Kernel directory
Asked Answered
N

2

7

I am using Symfony 3.4. Suddenly, whenever I try to run my tests (phpunit) in /tests, I get the following error:

RuntimeException : Unable to guess the Kernel directory.

My test class looks something like:

class PaymentCreditTest extends KernelTestCase
{
    /** @var PaymentRepository */
    public $paymentRepository;

    /**
     * {@inheritDoc}
     */
    protected function setUp()
    {
        $this->paymentRepository = self::bootKernel()->getContainer()->get('chaku.repository.payment');
    }

    public function test_canRetrieveDeadFreightNetAmount()
    {
        /** @var Payment $payment */
        $payment = $this->paymentRepository->findOneBy(['id' => 1000002]);

        // just to see payment object
        dump($payment);
    }
}

This is what my phpunit.xml.dist looks like:

<?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="app/autoload.php">
    <php>
        <ini name="error_reporting" value="-1" />
        <server name="KERNEL_CLASS" value="AppKernel" />
        <env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
    </php>

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

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

Any help with this will be well appreciated.

Nomi answered 15/3, 2018 at 16:57 Comment(0)
T
2

I think I had the exact same issue few weeks ago, can you try adding KERNEL_DIR:

<php>
    <ini name="error_reporting" value="-1" />
    <server name="KERNEL_CLASS" value="AppKernel" />
    <server name="KERNEL_DIR" value="app/" />
    <env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
</php>
Thant answered 15/3, 2018 at 21:40 Comment(1)
If you can, prefer using KERNEL_CLASS - as Symfony4 allows for easy use of multiple kernels in an app, KERNEL_CLASS would use the first it finds in the directory.Aha
M
0

./vendor/bin/simple-phpunit -c app/ add the Appkernel directory which is app while executing the command for testing.

Molasses answered 26/3, 2021 at 11:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.