Skip to content

Instantly share code, notes, and snippets.

@ludo237
Created July 4, 2016 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ludo237/ab12f1f4e477a1e3a356ab99855bd56b to your computer and use it in GitHub Desktop.
Save ludo237/ab12f1f4e477a1e3a356ab99855bd56b to your computer and use it in GitHub Desktop.
Simple bash that allows to autorun a test suite for Laravel
#!/bin/bash
clear
echo "---------------------------------"
echo "---- Automatic Tester -----"
echo "---- -----"
echo "---- v1.4 -----"
echo "---------------------------------"
echo "==> Testing if PHP is on Version 7.0+..."
VER=$(php -v | grep 'PHP' -m 1)
if [[ "$VER" != *"7.0"* ]]; then
echo "You don't have PHP 7.0. I'm sad"
else
echo "I found it:" $VER
fi
echo "==> Checking if I can access to Internet..."
wget -q --tries=1 --timeout=1 --spider http://kernel.org &> /dev/null
if [[ $? -eq 0 ]]; then
if [ ! -d vendor ]; then
echo "Cannot detect the vendor folder, this means that composer need to install all the dependencies";
composer install -q -o --no-progress --profile
else
echo "Vendor folder found, lets see if composer has some fresh update"
composer update -q -o --no-progress --profile
fi
else
echo "No Internetterino. I'm sad but I can test anyways, skipping composer..."
fi
echo "==> Checking if artisan is reachable..."
php artisan >/dev/null; echo "Artisan OK" || { echo "Where is Artisan? I'm sad"; exit 1; }
echo "==> Preparing the environment..."
if [ $(php artisan env | grep -o -E "(\w+){1}$") != "development" ]; then
echo "Nope I cannot test on this environment"
exit 1;
fi
echo "Good the Environment is setup correctly!"
echo "==> Removing previous Database for testing..."
rm -f database/test.sqlite; echo "Done" || { echo "I can't remove the .sqlite database. I'm sad"; exit 1; }
echo "==> Creating the new database in database/test.sqlite..."
touch database/test.sqlite; echo "Done" || { echo "I can't create the new .sqlite database. I'm sad"; exit 1;}
echo "==> Migrating and seeding the test database..."
php artisan migrate --database=sqlite >/dev/null; echo "Done" || { echo "Ops migration fails. I'm sad"; exit 1; }
echo "==> Checking that phpunit is installed..."
command -v vendor/bin/phpunit >/dev/null 2>&1; echo >&2 "Yest it is." $(vendor/bin/phpunit --version) || { echo >&2 "Where's PHPUnit? I'm sad"; exit 1; }
if [ ! -f .env ]; then
echo "==> Adding new .env file..."
touch .env
echo "==> Adding random key to the .env file..."
php artisan key:generate
fi
echo "==> Cleaning up reports and docs..."
rm -f tests/docs/* && rm -rf test/reports/*; echo "Done" || { echo "I can't clean the reports and docs. I'm sad"; exit 1; }
echo "==> Executing Tests Suite..."
vendor/bin/phpunit --coverage-html tests/reports --testdox-html tests/docs/reports.html -v --debug
echo "report generated >> test/reports. Documentation generated >> test/docs/reports.html"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment