Symfony4 中的奇怪问题:Doctrine 有效,我可以使用php bin/console doctrine:schema:create
. 但是我的 PHPUnit 测试没有连接。通过运行./bin/phpunit
我得到SQLSTATE[HY000] [2002] No such file or directory
异常。
我按照文档中有关启动内核的步骤进行操作:http: //symfony.com/doc/current/testing/doctrine.html
我的代码:
class PersistingResultTest extends KernelTestCase
{
protected $em;
protected function setUp()
{
$kernel = self::bootKernel();
$this->em = $kernel->getContainer()
->get('doctrine')
->getManager();
}
public function testPersistingLogFile()
{
// Just a simple schema command to test connection
$tool = new SchemaTool($this->em);
$tool->createSchema($this->em->getMetadataFactory()->getAllMetadata());
}
protected function tearDown()
{
parent::tearDown();
$this->em->close();
$this->em = null; // avoid memory leaks
}
}
有谁知道为什么会这样?一个错误?
编辑:
显然该.env
文件未正确读取。我将DATABASE_URL
环境变量移到doctrine.yml
文件中,现在它可以工作了。