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

后端 未结 1 1025
醉酒成梦
醉酒成梦 2021-01-18 05:02

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

相关标签:
1条回答
  • 2021-01-18 05:06

    You have to put the DATABASE_URL into your phpunit.xml file, e.g. like this:

    <php>
            <ini name="error_reporting" value="-1" />
            <env name="KERNEL_CLASS" value="App\Kernel" />
            <env name="APP_ENV" value="test" />
    
            <!-- ###+ doctrine/doctrine-bundle ### -->
            <!-- Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url -->
            <!-- For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db" -->
            <!-- Configure your db driver and server_version in config/packages/doctrine.yaml -->
            <env name="DATABASE_URL" value="mysql://root@127.0.0.1:3306/symfony4-database"/>
            <!-- ###- doctrine/doctrine-bundle ### -->
        </php>
    
    0 讨论(0)
提交回复
热议问题