testing with codeception (webelement #30)
TRANSCRIPT
Testing with
CODECEPTION“boot your tests in PHP is a real pain”
Adam Štipák | @new_POPE
Testing tools
● PHPUnit [https://phpunit.de/]
● Nette\Tester [http://tester.nette.org/en/]
● Simpletest [http://www.simpletest.org/]
● Testify.php [http://tutorialzine.com/projects/testify/]
● etc ...
Testing tools
Yes, they are really cool,but it is a little problem here.
Problem
LOW LEVEL
How can I set up other things?
● Selenium tests● API tests● Functional tests● Access to DB for check a state or setup prerequisities
● Data cleanup● and many, many things...
You can set up it manually,but WHY???
Just try CODECEPTION
Features● very fast setup● Unit (powered by PHPUnit)● API (REST, SOAP, XML-RPC)● Functional (Symfony2, Laravel, Yii, Zend)● Acceptance (PhpBrowser, Selenium)● Db (Db, Doctrine 1 & 2)● BDD - style readable tests● Modules & Addons !!!
Very fast setup - installation$ bin/composer.phar require “codeception/codeception:*”
$ vendor/bin/codeception bootstrap
$ .../codeception generate:cept acceptance Welcome
Very fast setup - write a test
// /tests/acceptance/WelcomeCept.php
$I = new AcceptanceTester($scenario);
$I->wantTo('ensure that frontpage works');
$I->amOnPage('/');
$I->see('Home');
Very fast setup - configure
// /tests/acceptance.suite.yml
class_name: AcceptanceGuy
modules:
enabled: [PhpBrowser, AcceptanceHelper]
# WebDriver instead of PhpBrowser for Selenium
config:
PhpBrowser:
url: '{YOUR APP'S URL}'
Very fast setup - run$ vendor/bin/codeception run
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)
API - config
class_name: ApiTester
modules:
enabled: [PhpBrowser, REST, ApiHelper]
config:
PhpBrowser:
url: http://serviceapp/
REST:
url: http://serviceapp/api/v1
API - test$I = new ApiTester($scenario);
$I->wantTo('create a user via API');
$I->haveHttpHeader('Content-Type',
'application/json');
$I->sendPOST('/users', ['name' => 'davert']);
$I->seeResponseCodeIs(201);
$I->seeResponseIsJson();
$I->seeResponseContains('{"result":"ok"}');
Db - configmodules:
enabled: [Db]
config:
Db:
dsn: 'mysql:host=localhost;dbname=testdb'
user: 'root'
password: ''
dump: 'tests/_data/dump.sql'
populate: true
cleanup: false
Db - test
$I->haveInDatabase('users', ['name' => 'miles']); //*
// $I->dontSeeInDatabase
$I->seeInDatabase('users', [
'name' => 'Davert',
'email' => '[email protected]'
]);
Modules & addons● PhpBrowser● Queue● REST● Redis● SOAP● Sequence● Silex● Symfony 1● Symfony 2● WebDriver● XMLRPC● Yii 1● Yii2● Zend 1 & 2
● AMQP● Asserts● Cli● Db● Dbh● Doctrine 1 & 2● FTP● Facebook● Filesystem● Kohana● Laravel4● Memcache● MongoDb● Phalcon1
Modules & addons● PhpBuiltinServer
● Phantoman
● and many others ...
FAQ
● how can I setup different URLs for REST?
● can I write OO oriented tests?
● what is interactive console?
● can I use DRY principle in tests (for login)?
Thanks
Adam Štipák | @new_POPE