Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhpStorm Docker PHPUnit Database

  • I setup PhpStorm: PHP, PHPUnit with Docker
  • I see schema in PhpStorm/Database viewer
  • I can use database in my application: register etc.
  • I can run phpunit in PhpStorm
  • But if I would like use database in tests, then I get the following error:

Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name does not resolve (SQL: select * from tablename)

The test working in container but broken in IDE. Do you have any ideas what is the problem in PhpStorm?

like image 379
T1k3 Avatar asked Feb 06 '18 20:02

T1k3


1 Answers

I ran into this exact issue. Assuming you already have the Docker container and PHP interpreter set up, this is how I got it to connect to the MySQL container:

  1. Run docker network ls from the CLI and saw the "lighthouse_default" network
  2. Went to PHP > Test Frameworks and edited (clicked the folder) on my Docker container
  3. Set Network mode to "lighthouse_default"
  4. Added the lighthouse_mysql_1 image to the Links section

Obviously, in your situation the network name will likely be different. The real point is that I had to make sure I was using the right network and make sure the database image is in the Container Links.

like image 56
Jason Adams Avatar answered Oct 11 '22 21:10

Jason Adams