DataBase connection problem with PHPUnit and WordPress

When running the PHPUnit tests, WordPress will load the config from wp-tests-config.php instead of wp-config.php. You need to add your database connection details in wp-tests-config.php.

And if you use MAMP or AMPPS to host your database, you will have to use 127.0.0.1 as DB_HOST instead of localhost. Alternatively use the PHP version supplied by the Solution stack of choice, or set DB_HOST to ‘:/path/to/soulution/stack/mysql.socket’.