Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RuntimeException : Unable to guess the Kernel directory

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.

like image 540
Babagana Zannah Avatar asked Mar 15 '18 16:03

Babagana Zannah


1 Answers

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>
like image 137
fsevestre Avatar answered Sep 29 '22 03:09

fsevestre