Ad

How To Run Custom Mysql Script For Laravel App In Test Pipeline In CodeShip Basic?

- 1 answer

Relative newbie to PhpUnit and testing in general. We do not use migrations in our project, but have a couple of scripts that I need to run in order to set up the database for testing. How can I run mysql scripts from the project in the test pipeline? I also need to create a new database with a specific name before running those scripts.

Thanks!

Ad

Answer

OK, after some digging I found out how to do all this. Below is the script I used for testing with a new mysql schema created with specific user from a sql script. Hope this helps someone in the future.

mysql -u $MYSQL_USER -p$MYSQL_PASSWORD -e "CREATE USER 'myuser'@'%' IDENTIFIED BY 'testpassword';"
mysql -u $MYSQL_USER -p$MYSQL_PASSWORD -e "CREATE SCHEMA myschemaname;"
mysql -u $MYSQL_USER -p$MYSQL_PASSWORD -e "GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'testpassword';"
mysql -u $MYSQL_USER -p$MYSQL_PASSWORD myschemaname < ./app/Ship/Migrations/1of2-schema.sql
mysql -u $MYSQL_USER -p$MYSQL_PASSWORD myschemaname < ./app/Ship/Migrations/2of2-seed.sql
php artisan passport:install
./vendor/bin/phpunit

$MYSQL_USER and $MYSQL_PASSWORD are replaced by Codeship - these are the env variables for the user and password for the mysql that exists in the build container.

the -e switch on the mysql call runs the script given and exits. Had to do it this way since I couldn't interact with the mysql client.

Ad
source: stackoverflow.com
Ad