@lmuzinic
You probably use framework when coding (unless you are Rasmus :))
so it is only logical to use it while writing tests
How to test a testing framework?
PHPUnit on steroids
Readable tests, BDD style
Describes actions from user's perspective
Integrates with most frameworks
Written in PHP on top of proven packages
"require": {
"php": ">=5.3.19",
"behat/mink": "1.5.*",
"phpunit/phpunit": "3.7.*",
"facebook/webdriver": "0.3",
"behat/mink-goutte-driver": "1.0.*",
"behat/mink-selenium2-driver": "1.1.*",
"monolog/monolog": "*",
"symfony/finder": "~2.3",
"symfony/console": "~2.3",
"symfony/event-dispatcher": "~2.3",
"symfony/yaml": "~2.3"
}
~ wget http://codeception.com/codecept.phar -O /usr/local/bin/codeception
~ codeception bootstrap
~ codeception generate:phpunit unit XitiTranslate
~ codeception generate:test unit XitiTranslate
class XitiTranslateTest extends \Codeception\TestCase\Test {
protected $codeGuy;
protected $xitiTranslate = null;
protected function _before() {
$this->xitiTranslate = new XitiTranslate($data);
}
protected function _after() {
unset($this->xitiTranslate);
}
public function testXitiTranslations() {
$this->assertEquals('Hofer KG', $this->xitiTranslate->companyName());
$this->assertEquals(2, $this->xitiTranslate->companyId());
// ...
don't need to install PHPUnit
use modules to add integration testing
~ codeception generate:cept functional MobileApiIndustries
<?php
$I = new TestGuy($scenario);
$I->wantTo('test MobileApp API to return all necessary fields for industries');
$I->haveHttpHeader('Fetch-Type', 'full');
$I->haveHttpHeader('Api-Version', '2');
$I->sendGET('/industries');
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContains('{industries:[...]}');
with framework integration you don't need a web server
simulate request and response
~ codeception generate:cept acceptance HeaderNavigationCategories
<?php
$I = new WebGuy($scenario);
$I->wantTo('see that categories are in navigation');
$I->amOnPage('/');
$I->click("Branchen & Themen", "nav.main_nav_entities");
$I->click("Alle Kategorien");
$I->see("Bauen & Garten",".nav_panel .drop");
$I->see("Sport & Fitness",".nav_panel .drop");
test any site, even live ones
uses browser, indifferent to framework used
describe testing actions in PHP
~ codeception run
AMQP, Db, Memcache, Cli, Filesystem
Symfony, Zend, Yii, Laravel, Kohana
$I->runShellCommand($command)
$I->seeInShellOutput($text)
modules:
enabled: [Db]
config:
Db:
dsn: 'mysql:host=localhost;dbname=testdb'
user: 'root'
password: ''
dump: 'tests/_data/dump.sql'
populate: true
cleanup: false
$I->seeInDatabase('users', array('username' => 'phpday'));
SELECT COUNT(*) FROM users WHERE username = 'phpday';
$I->seeFileFound('process.lock','app/lock');
$I->seeInThisFile(PID);
$I->grabValueFromMemcached('key');
beta
RC
RC2
give Codeception a try
use it together with your clients
great way for a project newcomers
include testing culture in your organization
You are loosing arguments every day thanks to Codeception!