Database does not exist when trying to use MySQL for PHPUnit tests

Posted 3 months ago by AlexGodbehere

I have a MySQL database on my local machine that I use for development. Up to now, I've been using sqlite in-memory databases for my testing, but I want to test my suite against a MySQL database. I've set up a new connection that uses the same details as my local development MySQL, but with a different database name. If I try to run a test, I get the following error:

Illuminate\Database\QueryException : SQLSTATE[HY000] [1049] Unknown database 'app_testing' (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')

Ok, no problem - I'll make the database:

create database app_testing

But when I run the tests this time, I get the following error:

Illuminate\Database\QueryException : Database (app_testing) does not exist.

What's going on here? The app can see the database, so why can't PHPUnit? It must be able to some degree to change the error. Any advice would be appreciated.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.