Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3925

Symfony4: Doctrine2 works but no connection in PHPUnit test (kernel booted)

$
0
0

Strange issue in Symfony4: Doctrine works, I can validate the schema, create the database etc using php bin/console doctrine:schema:create. But my PHPUnit test does not have a connection. By running ./bin/phpunit I get SQLSTATE[HY000] [2002] No such file or directory exception.

I followed the steps within the docs regarding booting up the kernel:http://symfony.com/doc/current/testing/doctrine.html

My code:

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

Anyone know why this happens? A bug?

EDIT:

Apparently the .env file is not read properly. I moved the DATABASE_URL environment variable into the doctrine.yml file and now it works.


Viewing all articles
Browse latest Browse all 3925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>