Laravel 5.1 Behat and Codeship

Posted: 2015-07-04 14:38:05

The new integration testing features with Laravel 5.1 make Behat almost not needed BUT we do a lot of AngularJs work and instead of using karma to test the ui we enjoy using behat since we like the Gherkin Syntax and how we can easily code custom steps in PHP.

Here are some steps to getting behat going on Codeship so you get full CI even of Angular.

This is all based off of https://github.com/laracasts/Behat-Laravel-Extension

Behat.yml

behat.yml looks like this for me

default:
    extensions:
        Laracasts\Behat:
            # env_path: .env.behat
        Behat\MinkExtension:
            base_url: https://microservicehub.dev:44300
            default_session: laravel
            laravel: ~
            selenium2:
              wd_host: "http://192.168.10.1:4444/wd/hub"
            browser_name: chrome

codeship:
    extensions:
        Laracasts\Behat:
            env_path: .env.codeship
        Behat\MinkExtension:
            base_url: http://localhost:8080
            default_session: laravel
            laravel: ~
            selenium2:
              wd_host: "http://localhost:4444/wd/hub"
            browser_name: chrome

This is so I can run it locally as needed. The Codeship profile will then call in the .env.codeship and update the url as needed.

.env.codeship

This file has

APP_ENV=testing
APP_DEBUG=true
APP_KEY=f5edkkfijPDKQXPLHyYNDhiNZZrpT0Qd

DB_HOST=localhost
DB_DATABASE=test

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

Build Script for Codeship

Using the code they offer on their site I add that to my projects folder under tests/selenium_server.sh it is this file here

Maybe some do not need to be there?

Codeship Test Settings

Now in the settings I end up with inside the CodeShip UI are as follows

Here for example is the URL for my project to find these settings.

https://codeship.com/projects/8844/configure_tests

Under Setup Commands

# Set php version through phpenv. 5.3, 5.4 and 5.5 available
phpenv local 5.5
# Install dependencies through Composer
composer config -g github-oauth.github.com foobar
touch .env
echo "APP_ENV='testing'" >> .env
echo "DB_DATABASE='test'" >> .env
echo "MYSQL_TESTING_URL='localhost'" >> .env
echo "APP_KEY=DHMbPIbNLd1jI0ZEZZSxRFOHj03SU4P5" >> .env
echo "CACHE_DRIVER=file" >> .env
echo "SESSION_DRIVER=file" >> .env
echo "QUEUE_DRIVER=sync" >> .env
echo "MAIL_DRIVER=smtp" >> .env
echo "MAIL_HOST=smtp.mailgun.org" >> .env
echo "MAIL_PORT=2525" >> .env
composer install --dev
php artisan migrate
php artisan db:seed
nohup bash -c "sh tests/selenium_server.sh &" && sleep 9
cd public && nohup bash -c "php -S localhost:8080 &" && sleep 9
cd ../

Under Configure Test

DB_DATABASE=test phpunit
php artisan migrate
php artisan db:seed
vendor/bin/behat --profile=codeship --stop-on-failure

I run the migration one more time to get it ready for behat

behat


Tags:

laravel php bdd