Posted by & filed under Webdev.

Modern PHP testing for everyone.

codeception

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.

Project Home Yii2 extension
Acceptance Test

<?php
$I = new AcceptanceTester($scenario);
$I->wantTo('create wiki page');
$I->amOnPage('/');
$I->click('Pages');
$I->click('New');
$I->see('New Page');
$I->fillField('title', 'Hobbit');
$I->fillField('body', 'By Peter Jackson');
$I->click('Save');
$I->see('page created'); // notice generated
$I->see('Hobbit','h1'); // head of page of is our title
$I->seeInCurrentUrl('pages/hobbit'); 
$I->seeInDatabase('pages', array('title' => 'Hobbit'));
?>

API Test

<?php
$I = new ApiTester($scenario);
$I->wantTo('create a new user by API');
$I->amHttpAuthenticated('davert','123456');
$I->haveHttpHeader('Content-Type','application/x-www-form-urlencoded');
$I->sendPOST('/users', array('name' => 'davert' ));
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(array('result' => 'ok'));
?>

Unit Test

<?php
use \Codeception\Util\Stub;
class UserTest extends \Codeception\TestCase\Test
{
    public function testUserSave() {
        $user = Stub::make('User');
        $user->setName('davert');
        $this->assertEquals('davert', $user->getName());
        $user->save();
        $this->tester->seeInDatabase('users', array('name' => 'davert'));
    }
}
?>

Comments are closed.