我正在使用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>
对此有任何帮助将不胜感激。
答案 0 :(得分: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>
答案 1 :(得分:0)
./vendor/bin/simple-phpunit -c app/ 执行测试命令时添加appkernel目录下的app。