【问题标题】:RuntimeException : Unable to guess the Kernel directoryRuntimeException:无法猜测内核目录
【发布时间】:2018-08-24 14:25:19
【问题描述】:

我正在使用 Symfony 3.4。突然,每当我尝试在 /tests 中运行我的测试(phpunit)时,我都会收到以下错误:

RuntimeException : Unable to guess the Kernel directory.

我的测试类看起来像:

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);
    }
}

这就是我的 phpunit.xml.dist 的样子:

<?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>

对此的任何帮助将不胜感激。

【问题讨论】:

    标签: php symfony phpunit symfony-3.4


    【解决方案1】:

    我想我几周前也遇到了同样的问题,你可以尝试添加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>
    

    【讨论】:

    • 如果可以,最好使用 KERNEL_CLASS - 因为 Symfony4 允许在应用程序中轻松使用多个内核,KERNEL_CLASS 将使用它在目录中找到的第一个。
    【解决方案2】:

    ./vendor/bin/simple-phpunit -c app/ 在执行测试命令时添加Appkernel目录,即app。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-23
      • 1970-01-01
      • 2018-08-08
      • 2018-09-06
      • 2013-12-06
      • 1970-01-01
      • 1970-01-01
      • 2016-06-19
      相关资源
      最近更新 更多