Codeception (established 2011) is an PHP acceptance testing tool. It is built on top of PHPUnit and can also be used for functional testing. In a previous episode PHPUnit was launched against the Orinoco River Zend Framework 2 demo project. Let’s give codeception a try.

Codeception@github.com posts release 1.8 as stable so this version is used although it requires a phpunit downgrade to 3.7 from 4.8

"require-dev":{
        "squizlabs/php_codesniffer": "1.*",
        "phpunit/phpunit": "3.7.*@dev",
        "codeception/codeception":"1.8"
    }    

One attempt to deploy codeception 2.* ended in failure with the not very helpful message:

Argument #3 (No Value) of PHPUnit_TextUI_ResultPrinter::__construct() must
  be a value from "never", "auto" or "always"


Note: this projects runs on Xampp / Windows 7.
Codeception is installed in the vendor folder and to the vendor/bin folder is added the codecept executable. Among it’s dependencies are Symfony and Behat libraries. The next command:

vendor/bin/codecept bootstrap

installs a tests folder and a codeception.yml file. The file tests/acceptance.suite.yml should contain the project url:

class_name: WebGuy
modules:
    enabled:
        - PhpBrowser
        - WebHelper
    config:
        PhpBrowser:
            url: 'http://zf2project.localhost'

To tests/acceptance the actual acceptance test file is added as WelcomeCept.php:

/** @var $I WebGuy */
$I = new WebGuy($scenario);
$I->wantTo('ensure that frontpage works');
$I->amOnPage('/');
$I->see('Hello world!');

All that remains is running the test:

vendor/bin/codecept run

with output:

$ vendor/bin/codecept run
Codeception PHP Testing Framework v1.8.0
Powered by PHPUnit 3.7.38 by Sebastian Bergmann.

Acceptance Tests (1) ----------------------------------------------
Trying to ensure that frontpage works (WelcomeCept.php)       Ok
-------------------------------------------------------------------

Functional Tests (0) ------------------------
---------------------------------------------

Unit Tests (0) ------------------------------
---------------------------------------------
Time: 5.97 seconds, Memory: 7.00Mb
OK (1 test, 1 assertion)

Key drawback compared to Selenium IDE: does not work with javascript.

Sources

* http://codeception.com/
* http://stackoverflow.com/questions/3370334/difference-between-acceptance-test-and-functional-test

Advertisements