Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Testing with 
CODECEPTION 
“boot your tests in PHP is a real pain” 
Adam Štipák | @new_POPE
Testing tools 
● PHPUnit [https://phpunit.de/] 
● NetteTester [http://tester.nette.org/en/] 
● Simpletest [http://www.simp...
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 set...
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, Yi...
Very fast setup - installation 
$ bin/composer.phar require “codeception/codeception:*” 
$ vendor/bin/codeception bootstra...
Very fast setup - write a test 
// /tests/acceptance/WelcomeCept.php 
$I = new AcceptanceTester($scenario); 
$I->wantTo('e...
Very fast setup - configure 
// /tests/acceptance.suite.yml 
class_name: AcceptanceGuy 
modules: 
enabled: [PhpBrowser, Ac...
Very fast setup - run 
$ vendor/bin/codeception run 
Suite acceptance started 
Trying to ensure that frontpage works (Welc...
API - config 
class_name: ApiTester 
modules: 
enabled: [PhpBrowser, REST, ApiHelper] 
config: 
PhpBrowser: 
url: http://s...
API - test 
$I = new ApiTester($scenario); 
$I->wantTo('create a user via API'); 
$I->haveHttpHeader('Content-Type', 
'app...
Db - config 
modules: 
enabled: [Db] 
config: 
Db: 
dsn: 'mysql:host=localhost;dbname=testdb' 
user: 'root' 
password: '' ...
Db - test 
$I->haveInDatabase('users', ['name' => 'miles']); //* 
// $I->dontSeeInDatabase 
$I->seeInDatabase('users', [ 
...
Modules & addons 
● PhpBrowser 
● Queue 
● REST 
● Redis 
● SOAP 
● Sequence 
● Silex 
● Symfony 1 
● Symfony 2 
● WebDriv...
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...
Thanks 
Adam Štipák | @new_POPE
Upcoming SlideShare
Loading in …5
×

Testing with Codeception (Webelement #30)

1,089 views

Published on

Boot your tests with codeception. Write bdd style acceptance, functional tests very easy.

Published in: Internet
  • Be the first to comment

Testing with Codeception (Webelement #30)

  1. 1. Testing with CODECEPTION “boot your tests in PHP is a real pain” Adam Štipák | @new_POPE
  2. 2. Testing tools ● PHPUnit [https://phpunit.de/] ● NetteTester [http://tester.nette.org/en/] ● Simpletest [http://www.simpletest.org/] ● Testify.php [http://tutorialzine.com/projects/testify/] ● etc ...
  3. 3. Testing tools Yes, they are really cool, but it is a little problem here.
  4. 4. Problem LOW LEVEL
  5. 5. 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...
  6. 6. You can set up it manually, but WHY???
  7. 7. Just try CODECEPTION
  8. 8. 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 !!!
  9. 9. Very fast setup - installation $ bin/composer.phar require “codeception/codeception:*” $ vendor/bin/codeception bootstrap $ .../codeception generate:cept acceptance Welcome
  10. 10. 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');
  11. 11. 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}'
  12. 12. 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)
  13. 13. API - config class_name: ApiTester modules: enabled: [PhpBrowser, REST, ApiHelper] config: PhpBrowser: url: http://serviceapp/ REST: url: http://serviceapp/api/v1
  14. 14. 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"}');
  15. 15. Db - config modules: enabled: [Db] config: Db: dsn: 'mysql:host=localhost;dbname=testdb' user: 'root' password: '' dump: 'tests/_data/dump.sql' populate: true cleanup: false
  16. 16. Db - test $I->haveInDatabase('users', ['name' => 'miles']); //* // $I->dontSeeInDatabase $I->seeInDatabase('users', [ 'name' => 'Davert', 'email' => 'davert@mail.com' ]);
  17. 17. 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
  18. 18. Modules & addons ● PhpBuiltinServer ● Phantoman ● and many others ...
  19. 19. 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)?
  20. 20. Thanks Adam Štipák | @new_POPE

×