Laravel create database when testing

后端 未结 4 1514
清歌不尽
清歌不尽 2021-01-02 05:35

I am trying to run my unit test and create a database during setup. For some reason I am getting the error Unknown database \'coretest\'. If I create the databa

4条回答
  •  一向
    一向 (楼主)
    2021-01-02 06:08

    I feel like I have a much cleaner way of doing this. Just execute the commands normally through the shell.

    $host      = Config::get('database.connections.mysql.host');
    $database  = Config::get('database.connections.mysql.database');
    $username  = Config::get('database.connections.mysql.username');
    $password  = Config::get('database.connections.mysql.password');
    echo shell_exec('mysql -h ' . $host . ' -u ' . $username . ' -p' . $password . ' -e "DROP DATABASE ' . $database . '"');
    echo shell_exec('mysql -h ' . $host . ' -u ' . $username . ' -p' . $password . ' -e "CREATE DATABASE ' . $database . '"');
    

提交回复
热议问题