Recipe 33Test a PHP App with cuke4php

Problem

You want to be able to run quick tests of your PHP app without the overhead of launching a browser.

Ingredients

  • PHP 5.3.x[213]

  • Cuke4php,[214] a tool for writing step definitions in PHP

  • Cucumber’s wire protocol,[215] used behind the scenes by Cuke4php

  • The PHPUnit test framework[216] for assertions

  • (Optional) An environment for running full browser tests afterward: Selenium, Firefox, and a web server

Solution

You’re probably testing your PHP app at a few different layers. At the bottom layer, you may be using PHPUnit to test individual classes and functions. At the top layer, you might have something like Selenium for testing the app in a live browser.

Cuke4php sits somewhere in the middle. ...

Get Cucumber Recipes now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.