Cigar: Smoke testing in PHP

Warning: This post is over a year old. The information may be out of date.

Inspired by something I saw a friend write in Go, I’ve written a small smoke testing tool in PHP.

Smoke testing is said to have come from a type of hardware testing. You plug in and turn on the device, if it did not catch fire or release that oh-so-annoying electronic smoke, then it is considered working.

Edit: I’ve edited this post to reflect the new .cigar.json file changes that were introduced.

This type of testing is only meant to be an initial “looks good, let’s continue” form of testing. Checking for basic things such as the application booting correctly, or on the web, a series of status codes being correct on some key pages. It does not seek to replace fuller test suites of Unit, Functional and Integration tests. It’s just there to check that it’s even worth continuing with further tests.

For this, I’ve written a tool called cigar (inspired by vape) - it’s designed to be simple to use and requires minimal setup.

Installation & setup

Installation is handled through composer.

composer require --dev brunty/cigar

Once installed, you should create a .cigar.json file that contains an array of json objects specifying the url, status and (optional) content to check.

[
  {
    "url": "http://httpbin.org/status/418",
    "status": 418,
    "content": "teapot"
  },
  {
    "url": "http://httpbin.org/status/200",
    "status": 200
  },
  {
    "url": "http://httpbin.org/status/304",
    "status": 304
  },
  {
    "url": "http://httpbin.org/status/500",
    "status": 500
  }
]

Once this is in place, simply run the tool in order to have it check the URLs you want checked.

vendor/bin/cigar

The output of the command will be a line-by-line status of each of the URLs you’ve specified (colour coded for pass/fail), and the return code will be 0 if successful, and 1 if the tests fail:

pass/fail url [expected_code:actual_code] "optional string to look for"

cigar tool output

If you pass the --quiet option to the command, it’ll run and just return the exit code without any output.

At this stage, the tool was written in very little time and could use some improvement, but it’s working and doesn’t have many external dependencies. (I considered using something like symfony/console for it, but felt that it wasn’t particularly needed for the few options & simplicity of the project right now)