Crash Course into Continuous Testing with Sismo

By Younes Rafie

The PHP community started to adopt the testing culture relatively recently. Despite there being some debates on how to achieve this, nobody can argue the importance of having your code fully covered by tests. In this article, we’re going to explore a tool that will help you in a major part of the testing culture called continuous testing. As described on Wikipedia:

Continuous testing is the process of executing automated tests as part of the software delivery pipeline to obtain immediate feedback on the business risks associated with a software release candidate.

Sismo is a small component which you can easily integrate with your projects to make the process of continuous testing easier. Sismo’s main focus is to run your tests and send you status notifications. That’s all!


How to Install

The Sismo project is available on GitHub and contains a compile script that you can run to generate a single file called sismo.php.

The other way is to download the file directly from the project’s website and add it to your project.

Configuring Sismo

To run Sismo, you need to have a configuration file which tells it how to run your tests and where to run them.

// tests/sismo-config.php

$projects = array();
$projects[] = new Sismo\Project('500px API (master branch)', __DIR__.'/../');

return $projects;

Now, we run sismo.php from the commandline.

php sismo.php build --config-file='tests/config.php'

# The --verbose option will tell you what the command is doing.
php sismo.php build --config-file='tests/config.php' --verbose

If you don’t specify your config.php file in the command, Sismo will look for it under the user directory ~/.sismo/config.php. You can also specify it using an environment variable that you can set using the command line:

export SISMO_CONFIG_PATH="tests/config.php"

The data path is where Sismo stores the projects temporarily to run tests. You can use the --data-path option directly in the command or use the SISMO_DATA_PATH environment variable to update it.

php sismo.php build --config-file='tests/config.php' --data-path='.sismo/data' --verbose

Sismo build
Sismo build verbose

If you’re working on a new feature or creating a patch for a bug, you can tell Sismo which branch to run the command on.

// tests/config.php

$projects = array();

$pxProject = new Sismo\Project('500px API (master branch)', __DIR__.'/../');

$projects[] = $pxProject;

return $projects;

By default, Sismo will run the phpunit command, but you can change this using the setCommand method when configuring your project. You may also specify a bash statement, because it will directly be run on the terminal.

// tests/config.php

$pxProject->setCommand('./; phpunit');

In our case, we have the project on our local machine, but Sismo supports GitHub, Bitbucket and SSH (remote) hosted projects.

// tests/config.php

$projects = array();

$pxProject = new Sismo\GithubProject('500px API (master branch)', 'whyounes/500pxAPI_Test');
$projects[] = $pxProject;

return $projects;

GitHub project

Using Notifiers

Sismo has a list of notifiers that you can use to notify you about the build status. The most common way type is via email, but the same example applies for IRC, GitHub, etc.

// tests/config.php

$projects = array();
$mailNotifier = new Sismo\Notifier\MailNotifier('');

$pxProject = new Sismo\Project('500px API (master branch)', __DIR__."/..");
$projects[] = $pxProject;

return $projects;

Creating Custom Notifiers

To create our own notifier, we need to extend the Sismo\Notifier\Notifier abstract class and define the notify method. We’re going to create a notifier for Slack, which will notify our team on the chat channel about the build status.

After cloning the Sismo repository from GitHub, you’ll find a folder under the Sismo namespace where contributors can add their custom notifiers.

To post a message to Slack, we need a token, channel name, and an optional username. You can check the documentation for the list of available parameters.

class SlackNotifier extends Notifier
    protected $token;
    protected $channel;
    protected $username;

    protected $apiEndpoint = "";
    protected $messageFormat = "%author% - %name% - %message% - %status%";

     * Constructor.
     * @param string       $token
     * @param string       $channel
     * @param string       $username
    public function __construct($token, $channel, $username = null)
        $this->token = $token;
        $this->channel = $channel;
        $this->username = $username;

    public function notify(Commit $commit)
        return $this->sendMessage($commit);

The notify method will receive a Commit containing all the details about the tested commit. We can also use the Notifier@format method to format the commit message using the messageFormat attribute.

class SlackNotifier extends Notifier

     * Format commit message using the message format
     * @param  Commit $commit
     * @return string
    protected function getCommitMessage($commit)
        $message = $this->format($this->messageFormat, $commit);

        return $message;

     * Push message to Slack
     * @param  Commit $commit
     * @return bool|string The response message, or false if an error occured.
    protected function sendMessage($commit)
        $curlData = [
            "token"     => $this->token,
            "channel"   => $this->channel,
            "username"  => $this->username ?: "Sismo Bot",
            "text"      => $this->getCommitMessage($commit)
        $url = $this->apiEndpoint . "?" . http_build_query($curlData);
        $output = file_get_contents($url);

        return $output;

Storing Build Information

Sismo stores all the test information inside an SQLite database that we can find under the data folder. We can use it for debugging or inspect it if something went wrong with the application while testing.

Sismo DB

We can also run a built-in PHP server php sismo.php run localhost:9000 to browse our projects and build statuses.

Using Git Hooks

A useful trick that could automate the process a little bit further is to attach Sismo directly to our Git process, and make it run whenever we commit new changes. Git hooks are scripts stored under the .git/hooks directory. We’ll use the post-commit hook to run Sismo. You can read more about Git hooks here, here and here.


rootDir=$(git rev-parse --show-toplevel)
export SISMO_CONFIG_PATH="$rootDir/tests/config.php"

cd $rootDir
php sismo.php build --verbose

The rootDir variable holds the root path to our project, and we use it to set the SISMO_CONFIG_PATH environment variable like we mentioned earlier. That’s it! The script will run after every commit.


Sismo does one thing, and does it well. In this article, we saw how we can integrate it with our development cycle and how to configure the notification system. If you’ve used Sismo before, let us know your experience with it! If you have any questions or comments, make sure to post them below and I’ll do my best to answer them!

No Reader comments



Because We Like You
Free Ebooks!

Grab SitePoint's top 10 web dev and design ebooks, completely free!

Get the latest in PHP, once a week, for free.