Codeception Quickstart Guide

Codeception PHP Testing Framework is designed to work just out of the box. This means its installation requires minimal steps and no external dependencies preinstalled (except PHP, of course). Only one configuration step should be taken and you are ready to test your web application from an eye of actual user.

Requirements: PHP 5.4, CURL enabled

1. Download

Install via Composer

$ composer require "codeception/codeception"  // ./vendor/bin/codecept

$ alias codecept='./vendor/bin/codecept'


Install PHAR locally

$ wget http://codeception.com/codecept.phardownload 
$ wget http://codeception.com/php54/codecept.phar // PHP 5.4 and 5.5download 

$ alias codecept='codecept.phar'


Install PHAR globally

sudo curl -LsS http://codeception.com/codecept.phar -o /usr/local/bin/codecept
sudo chmod a+x /usr/local/bin/codecept

$ codecept

2. Install

Open console directory where you saved codecept.phar file and execute:

$ codecept bootstrap

This creates codeception.yml file and tests directory.

3. Create Test

Generate your first acceptance test. Acceptance tests emulate behavior of a real user visiting your site.

$ codecept generate:cept acceptance Welcome

Codeception scenario tests are called Cepts.

4. Write Basic Test

It's now time to write your first test. Edit the file we've just created tests/acceptance/WelcomeCept.php

<?php
  $I = new AcceptanceTester($scenario);
  $I->wantTo('ensure that frontpage works');
  $I->amOnPage('/');
  $I->see('Home');
?>

It will check that your frontpage contains the word Home in it.

5. Configure Acceptance Tests

Please make sure your local dev serveris running.  Put application URL into:  tests/acceptance.suite.yml 

class_name: AcceptanceTester
modules:
enabled:
  - PhpBrowser:
url: {YOUR APP'S URL}
  - \Helper\Acceptance

6. Run!

Codeception are executed with 'run' command

$ codecept run

This will execute our Welcome test with PhpBrowser. It's PHP script that can check HTML page contents, click links, fill forms, and submit POST and GET requests. For more complex tests that require a browser use Selenium with WebDriver module.

If you did everything right and your app has "Home" text on frontpage you will see this in output
Suite acceptance started
Trying to ensure that frontpage works (WelcomeCept.php) - Ok
Suite functional started
Suite unit started

Time: 1 second, Memory: 21.00Mb
OK (1 test, 1 assertions)

Follow the Acceptance Testing chapter to learn how to test your web application by clicking links, filling forms, as your regular users do.