0

I don't know why when I run a PHPUnit test, I get the following error:

PDOException: SQLSTATE[HY000] [2002] No such file or directory

My testing environment database setting is:

return [

    'fetch' => PDO::FETCH_CLASS,

    'default' => 'mysql',

    'connections' => [
        'mysql' => [
            'driver'    => 'mysql',
            'host'      => 'localhost',
            'database'  => 'clg_test',
            'username'  => 'root',
            'password'  => 'veryHardPass',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
        ]
    ],

    'migrations' => 'migrations',

];

The reason why I am using MySQL as oppose to SQLite is because my migration files use dropColumn which is not supported by SQLite. I call the migration via Artisan::call('migrate') in the setup.

If I actually call migration manually in the terminal via php artisan migrate --env=testing then the migration IS successful and the databases are created.

Why am I then facing the above problem?

1 Answer 1

3

Try changing localhost to 127.0.0.1. The message you're getting is indicative of the script not being able to connect to MySQL through a socket, but using an ip should work.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, so now I am getting a connection refused error!
Well, that's a start... :) unfortunately, I don't know what might cause that. I hope you find the error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.