Skip to content

Continuous Integration

JP Barbosa edited this page Mar 14, 2016 · 7 revisions

Continuous Integration

Install xdebug for code coverage
brew install php70-xdebug
Configure xdebug
echo "remote_enable=on" >> /usr/local/etc/php/7.0/conf.d/ext-xdebug.ini
echo "remote_handler=dbgp" >> /usr/local/etc/php/7.0/conf.d/ext-xdebug.ini
echo "remote_host=localhost" >> /usr/local/etc/php/7.0/conf.d/ext-xdebug.ini
echo "remote_port=8000" >> /usr/local/etc/php/7.0/conf.d/ext-xdebug.ini
Require the Codeception c3 package (Coverage with Selenium)
nano composer.json
...
"require-dev": {
    ...
    "codeception/c3": "2.*"
},
...
Install c3
composer update
Add c3.php to .gitignore
echo 'c3.php' >> .gitignore
Load c3 in your application
nano public/index.php
...
$app = require_once __DIR__.'/../bootstrap/app.php';

if (env('APP_ENV') == 'testing') {
    require __DIR__.'/../c3.php';
}
...
Configure test coverage
nano codeception.yml
...
coverage:
    enabled: true
    c3_url: 'http://localhost:8000'
    include:
        - app/*
Run Redis server
redis-server
Run the server
php artisan serve --env=testing
Run Selenium server
selenium-server
Run test coverage
vendor/bin/codecept run --coverage --coverage-xml --env=testing
...
OK (10 tests, 10 assertions)

Code Coverage Report:
  2015-07-17 17:14:26

 Summary:
  Classes: 48.39% (15/31)
  Methods: 30.77% (16/52)
  Lines:   32.02% (65/203)
...
XML report generated in coverage.xml
Configure Code Climate

The follow steps require that you pushed your repository to GitHub.

open https://codeclimate.com/github/signup

Add repository in codeclimate

Get CODECLIMATE_REPO_TOKEN and export it in the shell

Get key for code coverage

export CODECLIMATE_REPO_TOKEN=XXXXXXXXXXXXXXXX
Move code coverage report XML to Code Climate path
mkdir build
mkdir build/logs/
cp tests/_output/coverage.xml build/logs/clover.xml
echo "build" >> .gitignore
Add Code Climate configuration file
nano .codeclimate.yml
languages:
  PHP: true
  JavaScript: true
exclude_paths:
 - ".bowerrc_files/*"
 - ".bootstrap/cache/*"
 - "node_modules/*"
 - "public/*"
 - "storage/*"
 - "tests/_data/*"
 - "tests/_output/*"
 - "tests/_support/*"
 - "vendor/*"
Add Code Climate test reporter with composer
composer require codeclimate/php-test-reporter
Send the coverage report to Code Climate
./vendor/bin/test-reporter
Test coverage data sent.
Check result

Codeclimate status

Get Selenium script for Codeship
wget https://raw.githubusercontent.com/codeship/scripts/master/packages/selenium_server.sh
Open Codeship
open https://codeship.com/projects
Create a new project from GitHub

Codeship new project

Choose test settings

Codeship test settings

Change the configuration as follow (Setup Commands)

Do not forget to replace YOUR_APP_KEY.

## Set env variables
export APP_ENV=testing
export APP_DEBUG=true
export APP_KEY=YOUR_APP_KEY
export DB_CONNECTION=sqlite
export SQLITE_FILE=testing.sqlite

## Set php version through phpenv. 5.5, 5.6 and 7.0 available
phpenv local 7.0

## Install dependencies through composer
composer install --no-interaction

## Install app node packages, bower and gulp
nvm install 4.0
npm install

## Install app bower packages
bower install --config.interactive=false

## Compile assets
gulp --production

## Database
touch database/testing.sqlite
php artisan migrate --env=testing
Configure test pipelines
## Start server
php artisan serve >/dev/null 2>&1 &
sh selenium_server.sh

## Run tests
vendor/bin/codecept run --no-interaction --fail-fast
Add continuous integration to Git and push it to GitHub
git add .
git commit -m "Add code coverage, Codeship and Code Climate"
git push -u origin master
Open Codeship and check the result
open https://codeship.com/projects

Codeship Result

Tip: If you changed some configuration and got any problem, try to click on "Reset Dependency Cache"

Next step: Deploy with Heroku
Clone this wiki locally