SlideShare a Scribd company logo
1 of 18
Download to read offline
TESTING WITH
CODECEPTION
Why use codeception if I already know phpunit and
behat?
● fast, as each functional/integration test is wrapped into transaction using
Doctrine ORM
● scenario-driven, it means that tests are linear, described in easy to get PHP
● can be used for testing complex interactions inside functional tests.
● easy to write, as Codeception already provides bundled actions and
assertions for most popular use cases.
● combine all testing levels (acceptance, functional, unit) in one tool.
Installing and setup
composer require --dev "codeception/codeception:~2.1"
- the unit and functional tests will reside inside the bundles, so we will have
only the acceptance tests placed globally
php bin/codecept bootstrap --empty
- after running this command, we will have the “tests” folder, and the
“codeception.yml” config file, at the app folder level;
php bin/codecept g:suite acceptance
Generate setup for unit and functional tests:
php bin/codecept bootstrap --empty -c src/AppBundle --namespace AppBundle
then, generate the test suites:
php bin/codecept g:suite functional -c src/AppBundle
php bin/codecept g:suite unit -c src/AppBundle
Symfony WebTestCase test vs. Codeception version
Configuration
src/AppBundle/tests/functional.yml
- enable specific modules needed by the test
- provide valid app and var paths for Symfony
- specify that Doctrine's EntityManager should be taken from Symfony DIC
Acceptance Testing
- acceptance testing can be performed by a non-technical person
- if you are developing a web-application the tester needs nothing more than a
web browser to check that your site works correctly
- you can reproduce an AcceptanceTester's actions in scenarios and run them
automatically after each site change
- you will be sure that site features work after the last changes were made
- there’s no need to manually test a long or cumbersome functionality or user
scenario over and over again
- this scenario can probably be read by non-technical people or Codeception
can even 'naturalize' this scenario, converting it into plain English
PHP Browser
- is the fastest way to run acceptance tests, since it doesn't require running an
actual browser
- it uses a PHP web scraper, which acts like a browser: it sends a request, then
receives and parses the response
- note that you can't test actual visibility of elements, or javascript interactions.
- the good thing about PhpBrowser is that it can be run in any environment with
just PHP and cURL required
- you can click only on links with valid urls or form submit buttons
- you can't fill fields that are not inside a form
- you can't work with JavaScript interactions: modal windows, datepickers, etc.
Selenium WebDriver
- a nice feature of Codeception is that most scenarios can be easily ported
between the testing backends
- the PhpBrowser tests can be executed inside a real browser (or PhantomJS)
with Selenium WebDriver
- the only thing we need to change is to reconfigure and rebuild the
AcceptanceTester class, to use WebDriver instead of PhpBrowser, by
modifying the yml configuration file
- you run acceptance tests with Selenium, Firefox will be started and all actions
will be performed step by step using browser engine
Modules
- test classes use Actors to perform actions and act as a dummy user
- actor classes are not written but generated from suite configuration
- methods of actor classes are generally taken from Codeception Modules
- each module provides predefined actions for different testing purposes, and
they can be combined to fit the testing environment
- Codeception tries to solve 90% of possible testing issues in its modules, so
you don't have reinvent the wheel
Asserts Module
assertContains
Checks that haystack contains needle
● param $needle
● param $haystack
● param string $message
assertEmpty
Checks that variable is empty.
● param $actual
● param string $message
assertEquals
Checks that two variables are equal.
● param $expected
● param $actual
● param string $message
assertFileExists
Checks if file exists
● param string $filename
● param string $message
assertSame
Checks that two variables are same
● param $expected
● param $actual
● param string $message
assertTrue
Checks that condition is positive.
● param $condition
● param string $message
Doctrine2 Module
Using the Symfony2 module:
modules:
enabled:
- Symfony2
- Doctrine2:
depends: Symfony2
-dontSeeInRepository
Flushes changes to database and performs ->findOneBy() call for current repository.
● param $entity
● param array $params
flushToDatabase
Performs $em->flush();
grabFromRepository
Selects field value from repository. It builds query based on array of parameters. You can use entity associations to
build complex queries.
Without using the Symfony2 module:
modules:
enabled:
- Doctrine2:
connection_callback: ['MyDb',
'createEntityManager']
PHP Browser Module
amOnPage
Opens the page for the given relative URI.
<?php
// opens /register page
$I->amOnPage('/register');
click
- if a fuzzy locator is given, the page will be searched for
a button, link, or image matching the locator string
- the second parameter is a context (CSS or XPath
locator) to narrow the search
<?php
// button of form
$I->click('Submit');
// CSS button
$I->click('#form input[type=submit]');
// link in context
$I->click('Logout', '#nav');
see
- checks that the current page contains the given string.
Specify a locator as the second parameter to match a
specific region
<?php
$I->see('Logout'); // I can suppose user is logged in
$I->see('Sign Up','h1'); // I can suppose it's a signup
page
seeResponseCodeIs
- checks that response code is equal to value provided.
● param $code
submitForm
- submits the given form on the page, optionally with the
given form values as an array
$I->submitForm('#login', [
'login' => 'davert',
'password' => '123456'
],
'submitButtonName');
REST Module
seeResponseContainsJson
Checks whether the last JSON response contains
provided array. The response is converted to array with
json_decode($response, true)
<?php
// response: {name: john, email: john@gmail.com}
$I->seeResponseContainsJson(array('name' => 'john'));
seeHttpHeader
Checks over the given HTTP header and (optionally) its
value, asserting that are there
● param $name
● param $value @part json
● Part: xml
seeResponseCodeIs
Checks response code equals to provided value.
@part json @part xml * param $code
sendPOST
Sends a POST request to given uri.
Parameters and files (as array of filenames) can be
provided.
● param $url
● param array|JsonSerializable $params
● param array $files @part json
sendPUT
Sends PUT request to given uri.
● param $url
● param array $params
● param array $files @part json
sendGET
Sends a GET request to given uri.
● param $url
● param array $params @part json

More Related Content

What's hot

Composer 從入門到實戰
Composer 從入門到實戰Composer 從入門到實戰
Composer 從入門到實戰
Shengyou Fan
 

What's hot (20)

Handle Exceptions in Selenium Webdriver | Edureka
Handle Exceptions in Selenium Webdriver | EdurekaHandle Exceptions in Selenium Webdriver | Edureka
Handle Exceptions in Selenium Webdriver | Edureka
 
Composer 從入門到實戰
Composer 從入門到實戰Composer 從入門到實戰
Composer 從入門到實戰
 
Spring annotation
Spring annotationSpring annotation
Spring annotation
 
Selenium- A Software Testing Tool
Selenium- A Software Testing ToolSelenium- A Software Testing Tool
Selenium- A Software Testing Tool
 
Vue JS Intro
Vue JS IntroVue JS Intro
Vue JS Intro
 
Selenium WebDriver training
Selenium WebDriver trainingSelenium WebDriver training
Selenium WebDriver training
 
Flux architecture
Flux architectureFlux architecture
Flux architecture
 
Maven Basics - Explained
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - Explained
 
Hands-On Java web passando por Servlets, JSP, JSTL, JDBC, Hibernate, DAO, MV...
Hands-On Java web passando por  Servlets, JSP, JSTL, JDBC, Hibernate, DAO, MV...Hands-On Java web passando por  Servlets, JSP, JSTL, JDBC, Hibernate, DAO, MV...
Hands-On Java web passando por Servlets, JSP, JSTL, JDBC, Hibernate, DAO, MV...
 
Webinar: Selenium WebDriver - Automation Uncomplicated
Webinar: Selenium WebDriver - Automation UncomplicatedWebinar: Selenium WebDriver - Automation Uncomplicated
Webinar: Selenium WebDriver - Automation Uncomplicated
 
Selenium WebDriver
Selenium WebDriverSelenium WebDriver
Selenium WebDriver
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
 
Corejava ratan
Corejava ratanCorejava ratan
Corejava ratan
 
웹 Front-End 실무 이야기
웹 Front-End 실무 이야기웹 Front-End 실무 이야기
웹 Front-End 실무 이야기
 
Build RESTful API Using Express JS
Build RESTful API Using Express JSBuild RESTful API Using Express JS
Build RESTful API Using Express JS
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
Selenium Webdriver Interview Questions
Selenium Webdriver Interview QuestionsSelenium Webdriver Interview Questions
Selenium Webdriver Interview Questions
 
(애자일) 테스트 계획서 샘플
(애자일) 테스트 계획서 샘플(애자일) 테스트 계획서 샘플
(애자일) 테스트 계획서 샘플
 
Maven
MavenMaven
Maven
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
 

Similar to Codeception presentation

Assurer - a pluggable server testing/monitoring framework
Assurer - a pluggable server testing/monitoring frameworkAssurer - a pluggable server testing/monitoring framework
Assurer - a pluggable server testing/monitoring framework
Gosuke Miyashita
 
Beginning AngularJS
Beginning AngularJSBeginning AngularJS
Beginning AngularJS
Troy Miles
 
Acceptance & Functional Testing with Codeception - Devspace 2015
Acceptance & Functional Testing with Codeception - Devspace 2015 Acceptance & Functional Testing with Codeception - Devspace 2015
Acceptance & Functional Testing with Codeception - Devspace 2015
Joe Ferguson
 

Similar to Codeception presentation (20)

Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
 
Release with confidence
Release with confidenceRelease with confidence
Release with confidence
 
Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...
Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...
Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...
 
Codeception
CodeceptionCodeception
Codeception
 
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsEffizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
 
Better Testing With PHP Unit
Better Testing With PHP UnitBetter Testing With PHP Unit
Better Testing With PHP Unit
 
Assurer - a pluggable server testing/monitoring framework
Assurer - a pluggable server testing/monitoring frameworkAssurer - a pluggable server testing/monitoring framework
Assurer - a pluggable server testing/monitoring framework
 
An approach to responsive, realtime with Backbone.js and WebSockets
An approach to responsive, realtime with Backbone.js and WebSocketsAn approach to responsive, realtime with Backbone.js and WebSockets
An approach to responsive, realtime with Backbone.js and WebSockets
 
Selenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web ApplicationsSelenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web Applications
 
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullyMastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium Successfully
 
Protractor framework architecture with example
Protractor framework architecture with exampleProtractor framework architecture with example
Protractor framework architecture with example
 
Beginning AngularJS
Beginning AngularJSBeginning AngularJS
Beginning AngularJS
 
Javascript tdd byandreapaciolla
Javascript tdd byandreapaciollaJavascript tdd byandreapaciolla
Javascript tdd byandreapaciolla
 
Php unit (eng)
Php unit (eng)Php unit (eng)
Php unit (eng)
 
Acceptance & Functional Testing with Codeception - Devspace 2015
Acceptance & Functional Testing with Codeception - Devspace 2015 Acceptance & Functional Testing with Codeception - Devspace 2015
Acceptance & Functional Testing with Codeception - Devspace 2015
 
E2E testing Single Page Apps and APIs with Cucumber.js and Puppeteer
E2E testing Single Page Apps and APIs with Cucumber.js and PuppeteerE2E testing Single Page Apps and APIs with Cucumber.js and Puppeteer
E2E testing Single Page Apps and APIs with Cucumber.js and Puppeteer
 
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Acceptance & Functional Testing with Codeception - SunshinePHP 2016Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
 
Automation of web attacks from advisories to create real world exploits
Automation of web attacks from advisories to create real world exploitsAutomation of web attacks from advisories to create real world exploits
Automation of web attacks from advisories to create real world exploits
 
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
 

Recently uploaded

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Recently uploaded (20)

The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 

Codeception presentation

  • 2.
  • 3. Why use codeception if I already know phpunit and behat? ● fast, as each functional/integration test is wrapped into transaction using Doctrine ORM ● scenario-driven, it means that tests are linear, described in easy to get PHP ● can be used for testing complex interactions inside functional tests. ● easy to write, as Codeception already provides bundled actions and assertions for most popular use cases. ● combine all testing levels (acceptance, functional, unit) in one tool.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8. Installing and setup composer require --dev "codeception/codeception:~2.1" - the unit and functional tests will reside inside the bundles, so we will have only the acceptance tests placed globally php bin/codecept bootstrap --empty - after running this command, we will have the “tests” folder, and the “codeception.yml” config file, at the app folder level; php bin/codecept g:suite acceptance Generate setup for unit and functional tests: php bin/codecept bootstrap --empty -c src/AppBundle --namespace AppBundle then, generate the test suites: php bin/codecept g:suite functional -c src/AppBundle php bin/codecept g:suite unit -c src/AppBundle
  • 9. Symfony WebTestCase test vs. Codeception version
  • 10. Configuration src/AppBundle/tests/functional.yml - enable specific modules needed by the test - provide valid app and var paths for Symfony - specify that Doctrine's EntityManager should be taken from Symfony DIC
  • 11. Acceptance Testing - acceptance testing can be performed by a non-technical person - if you are developing a web-application the tester needs nothing more than a web browser to check that your site works correctly - you can reproduce an AcceptanceTester's actions in scenarios and run them automatically after each site change - you will be sure that site features work after the last changes were made - there’s no need to manually test a long or cumbersome functionality or user scenario over and over again - this scenario can probably be read by non-technical people or Codeception can even 'naturalize' this scenario, converting it into plain English
  • 12. PHP Browser - is the fastest way to run acceptance tests, since it doesn't require running an actual browser - it uses a PHP web scraper, which acts like a browser: it sends a request, then receives and parses the response - note that you can't test actual visibility of elements, or javascript interactions. - the good thing about PhpBrowser is that it can be run in any environment with just PHP and cURL required - you can click only on links with valid urls or form submit buttons - you can't fill fields that are not inside a form - you can't work with JavaScript interactions: modal windows, datepickers, etc.
  • 13. Selenium WebDriver - a nice feature of Codeception is that most scenarios can be easily ported between the testing backends - the PhpBrowser tests can be executed inside a real browser (or PhantomJS) with Selenium WebDriver - the only thing we need to change is to reconfigure and rebuild the AcceptanceTester class, to use WebDriver instead of PhpBrowser, by modifying the yml configuration file - you run acceptance tests with Selenium, Firefox will be started and all actions will be performed step by step using browser engine
  • 14. Modules - test classes use Actors to perform actions and act as a dummy user - actor classes are not written but generated from suite configuration - methods of actor classes are generally taken from Codeception Modules - each module provides predefined actions for different testing purposes, and they can be combined to fit the testing environment - Codeception tries to solve 90% of possible testing issues in its modules, so you don't have reinvent the wheel
  • 15. Asserts Module assertContains Checks that haystack contains needle ● param $needle ● param $haystack ● param string $message assertEmpty Checks that variable is empty. ● param $actual ● param string $message assertEquals Checks that two variables are equal. ● param $expected ● param $actual ● param string $message assertFileExists Checks if file exists ● param string $filename ● param string $message assertSame Checks that two variables are same ● param $expected ● param $actual ● param string $message assertTrue Checks that condition is positive. ● param $condition ● param string $message
  • 16. Doctrine2 Module Using the Symfony2 module: modules: enabled: - Symfony2 - Doctrine2: depends: Symfony2 -dontSeeInRepository Flushes changes to database and performs ->findOneBy() call for current repository. ● param $entity ● param array $params flushToDatabase Performs $em->flush(); grabFromRepository Selects field value from repository. It builds query based on array of parameters. You can use entity associations to build complex queries. Without using the Symfony2 module: modules: enabled: - Doctrine2: connection_callback: ['MyDb', 'createEntityManager']
  • 17. PHP Browser Module amOnPage Opens the page for the given relative URI. <?php // opens /register page $I->amOnPage('/register'); click - if a fuzzy locator is given, the page will be searched for a button, link, or image matching the locator string - the second parameter is a context (CSS or XPath locator) to narrow the search <?php // button of form $I->click('Submit'); // CSS button $I->click('#form input[type=submit]'); // link in context $I->click('Logout', '#nav'); see - checks that the current page contains the given string. Specify a locator as the second parameter to match a specific region <?php $I->see('Logout'); // I can suppose user is logged in $I->see('Sign Up','h1'); // I can suppose it's a signup page seeResponseCodeIs - checks that response code is equal to value provided. ● param $code submitForm - submits the given form on the page, optionally with the given form values as an array $I->submitForm('#login', [ 'login' => 'davert', 'password' => '123456' ], 'submitButtonName');
  • 18. REST Module seeResponseContainsJson Checks whether the last JSON response contains provided array. The response is converted to array with json_decode($response, true) <?php // response: {name: john, email: john@gmail.com} $I->seeResponseContainsJson(array('name' => 'john')); seeHttpHeader Checks over the given HTTP header and (optionally) its value, asserting that are there ● param $name ● param $value @part json ● Part: xml seeResponseCodeIs Checks response code equals to provided value. @part json @part xml * param $code sendPOST Sends a POST request to given uri. Parameters and files (as array of filenames) can be provided. ● param $url ● param array|JsonSerializable $params ● param array $files @part json sendPUT Sends PUT request to given uri. ● param $url ● param array $params ● param array $files @part json sendGET Sends a GET request to given uri. ● param $url ● param array $params @part json