How to run laravel sail test in phpstrom

hi i am a big fan of run laravel indvisual test inside PHP storm but recently now I am using laravel sail which uses docker under the hood

and I can't run individual tests inside phpstorm it throw this errror

Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] php_network_getaddresses: 
getaddrinfo for mariadb failed:
Name or service not known (SQL: SHOW FULL TABLES
WHERE table_type = 'BASE TABLE')

 

0
3 comments

This should be generally working out of the box. Some customizations in your project/environment must be causing that. 

1. Do you have your laravel sail image added as a PHP Interpreter at Settings | PHP?

2. Did you add a PHPUnit config associated with this interpreter at File | Settings | PHP | Test Frameworks?

3. Check if switching PHP Interpreter lifecycle to "Always start a new container" helps:

-2

I had the same problem on Win11: PhpStrom 2022.2.2 / WSL2 / Docker Desktop 4.12.0

I cannot apply all settings as @Dmitry-Tronin recommends (maybe using other version of PhpStrom)

Workaround:
Use: php artisan test (--filter TestClass) for running PhpUnit tests in docker container

1. assign Run configuration for Shell Script (use 'Script text' execution):
   docker exec -it <docker_container_name> bash

2. Start script in PhpStorm (docker PHP container running) and then you have access to all related actions in PhpStorm Terminal window

0

Please sign in to leave a comment.