Everything you can do is configure your tests in Project Settings.
1. Setup your prefer php version
You can setup your php, Laravel project version by usingphpenv
command
# Set php version through phpenv. 5.3, 5.4 and 5.5 available
phpenv local 5.5
2. Setup database for testing
Codeship supports Mysql/MariaDB, Prostgresql and MongoDB in default. For another, I think we should to use Docker to install them before.For Mysql, we have Mysql root account and an database named
test
. I do not know how to get the password of Mysql root account. So, I need to create another mysql user by using mysql -e
to run mysql command.
#Setup MySql
mysql -e 'create database forge;'
mysql -e 'CREATE USER 'forge'@'localhost' IDENTIFIED BY 'secret';'
mysql -e 'GRANT ALL PRIVILEGES ON * . * TO 'forge'@'localhost';'
I do not need to create a new database because I will you test database which was created in default by Codeship before.
3. Touch your .env
For Laravel project secret information, We saved them into.env
file. I need to touch a .env file before running our tests.
touch .env
echo "APP_ENV=testing">> .env
echo "APP_DEBUG=true" >> .env
echo "APP_KEY=iXGNAjVbw7731rzhGp1OATxxGeSyK4zd" >> .env
echo "APP_URL=YOUR_PREFER_URL" >> .env
echo "DB_CONNECTION=mysql" >> .env
echo "DB_HOST=localhost" >> .env
echo "DB_DATABASE= test" >> .env
echo "DB_USERNAME=forge">> .env
echo "DB_PASSWORD=secret" >> .env
# Add more .env here
4. Install your project
# Install dependencies through Composer
composer install --dev --no-interaction
# Migrate and seed database using the APP_ENV environment variable of 'testing'
php artisan migrate --force
#Prepare data test
php artisan db:seed --class=YOUR_SEED_CLASS --force
Now, you can add test command in Configure Test Pipeline to run your testcases.
5. TroubleShooting
5.1 PHPUnit Memory Allocation Exhausted
If you have a large testing suite, the unit tests will fail due to a memory allocation problem.If you want to increase memory_limit in php, just add the following command in Setup Commands:
sed -i'' 's/^memory_limit=.*/memory_limit = 2048m/g' /home/rof/.phpenv/versions/$(phpenv version-name)/etc/php.ini