CI for Laravel

Code Quality

There are lots of code quality tools available! Some concentrate on coding style, some on test coverage, some on static analysis/type checking, and many more.

Quality Tools

Chipper CI lets you download and install any tools you need! For example, you may want to install PHP Codesniffer and use it to generate a report of your code versus a coding style.

Note that Chipper CI currently doesn't have write-access to your repositories - it will not change your code and create PR's or commits against your repositories.

Some other tools to look into:

Code Coverage

You can get code coverage reports via xdebug or pcov. Unless you have a specific reason to use xdebug, we suggest using pcov, which uses less resources and is faster.

These come pre-installed, but are disabled. To enable them, add the following to a pipeline script before running tests / generating coverage reports:

# Enable one or the other (but probably not both)
sudo phpenmod xdebug
sudo phpenmod pcov

# Tell phpunit to create some test coverage XML
# in directory coverage/xml
# Read the phpunit docs to learn more about coverage types
phpunit --coverage-xml coverage/xml

Coverage Testing

While PHPUnit can generate coverage reports, it does not plan on supporting a way to return errors (and thus fail a build) based on coverage.

This means we need some tools to help us!

To have your pipeline pass or fail a build based on test coverage, we can use a little utility as outlined here.

What we'll do is:

  1. Enable xDebug
  2. Have PHPUnit generate a coverage report
  3. Run a utility to check coverage and return a success or error response based on the coverage
# Download the coverage checker script
wget https://gist.githubusercontent.com/fideloper/5c7934396530c40d346a027ebd942719/raw/be4ff1935208c534fd0f11fcab8ba9cf0ee8b7b6/coverage.php
chmod +x coverage.php

# Enable xdebug and run phpunit
sudo phpenmod xdebug
phpunit --coverage-clover clover.xml

# Check the code coverage and return an error
# if code coverage is below 80%
./coverage.php clover.xml 80