DEV Community

Cover image for Test automation for Laravel 7 and MySQL with GitHub Actions

Test automation for Laravel 7 and MySQL with GitHub Actions

Roberto B. on June 04, 2020

GitHub Actions (https://github.com/features/actions) is a powerful service provided by GitHub for continuous integration and continuous delivery. ...
Collapse
 
oandreyev profile image
Oleg Andreyev

Few things:

  • when running unit test you don’t need database, otherwise it’s not a unit tests. I’d suggest split test cases in test suites, e.g.: unit and functional (running unnecessary steps is just taking seconds and billed)
  • no needs to store test database as a secret, how cares about it? I personally use secrets for “real secret” as PAT
Collapse
 
robertobutti profile image
Roberto B.

thank you for the feedback. very useful and everything make sense. i will update the article with latest version of the tools, and i will also take in consideration your feedback. thank you again!!!

Collapse
 
zaratedev profile image
Jonathan Zarate

Hi, Roberto.
I have the same configuration, but github actions throws me the exception.

 SQLSTATE[HY000] [2002] Connection refused (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')
Enter fullscreen mode Exit fullscreen mode
Collapse
 
robertobutti profile image
Roberto B.

Hi Jonathan. Thank you for the feedback.
I woul like to check one thing. Assuming that all things are correct, how is confogured your DB_HOST?
On your .env file :
DB_HOST=127.0.0.1
Later i will be at my laptop and i will try to replicate your issue.

Collapse
 
zaratedev profile image
Jonathan Zarate

Yeah, the DB_HOST is 127.0.0.1

Can I share my configuration of my yaml file?

Thread Thread
 
robertobutti profile image
Roberto B.

Sure!

Thread Thread
 
zaratedev profile image
Jonathan Zarate
Thread Thread
 
robertobutti profile image
Roberto B.

I see you are using MYSQL_ALLOW_EMPTY_PASSWORD.
Just to give a try , instead of MYSQL_ALLOW_EMPTY_PASSWORD , please try to use a password.
MYSQL_ROOT_PASSWORD: secret

and setting the same passoword in the env section with DB_PASSWORD: secret

Thread Thread
 
zaratedev profile image
Jonathan Zarate

Hello Roberto.

I'm trying to run the laravel dusk tests, but sadly I keep getting the connection refused error.
The phpunit tests with database migrations trait run successful.

Thread Thread
 
robertobutti profile image
Roberto B.

Ok, I was able to replicate your problem with your YML file.
The difference is that the phpunit is executed via command line and dusk is executed with the webserver (php artisan serve). The problem is to pass the env to the right process.
With phpunit is enough to set the env before executing the command.
With dusk , you need to set the env variables before to launch the webserver.
Try to take a look this one:
github.com/roberto-butti/laravel7-...

Collapse
 
robertobutti profile image
Roberto B.

I created an Open Source tool for creating GitHub Actions workflow for Laravel application. The source code is: github.com/Hi-Folks/gh-actions-yam... . You can use a demo here: ghygen.hi-folks.dev/

Collapse
 
bobbyiliev profile image
Bobby Iliev

This tool is supper cool!

Collapse
 
robertobutti profile image
Roberto B.

Thank you! If you have any feedback or suggestion or feature request, feel free to raise your hand 🚀