0
curl -s "https://laravel.build/example-app" | bash

I used above command to install laravel8 and sail up

It all works good.

However, I would like to have testing mysql as well.

mysql_test:
  image: "mysql:8.0"
  environment:
    MYSQL_ROOT_PASSWORD: "${DB_PASSWORD}"
    MYSQL_DATABASE: "${DB_DATABASE}"
    MYSQL_USER: "${DB_USERNAME}"
    MYSQL_PASSWORD: "${DB_PASSWORD}"
    MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
  networks:
    - sail

I added above to docker-composer.yml and ran sail up

DB_CONNECTION=mysql
DB_HOST=mysql_test
DB_PORT=3306
DB_DATABASE=laravel8_test
DB_USERNAME=sail
DB_PASSWORD=password

.env.testing

but when I ran sail test, I get an error

SQLSTATE[HY000] [1044] Access denied for user 'sail'@'%' to database 'laravel8_test' (SQL: select * from `users`)

and the test I ran is

public function test_example()
    {
        dd(User::all());
        $response = $this->get('/');

        $response->assertStatus(200);
    }

What else should I do?

Mike
  • 7
  • 1
  • 4

1 Answers1

0

Laravel does not create databases as far as I know. Try to create the database from a database client, like for example dbeaver and than let the migrations run. Hovever it is best practice to use the memory driver for testing.

online Thomas
  • 8,864
  • 6
  • 44
  • 85