Laravel 5 app always using 'testing' environment configuration

前端 未结 3 1658
南方客
南方客 2021-02-04 08:43

I have a Laravel 5 app with two environments and two configurations: testing (for PHPUnit configuration, in-memory db) and local (my development configuration).

Even whe

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-04 09:21

    1) open the config file database.php and add the following inside the 'connections' => [

    'sqlite_testing' => [
        'driver'   => 'sqlite',
        'database' => ':memory:',
        'prefix'   => '',
    ],
    

    this in memory sqlite will be used for your testing

    2) open the .env file and make sure it has the following:

    DB_CONNECTION=mysql
    

    3) open phpunit.xml and add the following inside the tag:

    
    

    here’s where you can add all the testing related env variables

    4) in your tests were you use a database connection use the Database Migration Trait:

    use DatabaseMigrations;
    

    for more details about the DatabaseMigrations refer to the documentation https://laravel.com/docs/5.1/testing#resetting-the-database-after-each-test

提交回复
热议问题