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

Jmeter Performance Testing
Jmeter Performance TestingJmeter Performance Testing
Jmeter Performance Testing
Atul Pant
 
Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...
Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...
Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...
Simplilearn
 

What's hot (20)

Getting started with Next.js
Getting started with Next.jsGetting started with Next.js
Getting started with Next.js
 
Cross browser testing using BrowserStack
Cross browser testing using BrowserStack Cross browser testing using BrowserStack
Cross browser testing using BrowserStack
 
Webdriver.io
Webdriver.io Webdriver.io
Webdriver.io
 
Jmeter Performance Testing
Jmeter Performance TestingJmeter Performance Testing
Jmeter Performance Testing
 
Introducing Playwright's New Test Runner
Introducing Playwright's New Test RunnerIntroducing Playwright's New Test Runner
Introducing Playwright's New Test Runner
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Introduction to Selenium Web Driver
Introduction to Selenium Web DriverIntroduction to Selenium Web Driver
Introduction to Selenium Web Driver
 
webpack 101 slides
webpack 101 slideswebpack 101 slides
webpack 101 slides
 
QSpiders - Automation using Selenium
QSpiders - Automation using SeleniumQSpiders - Automation using Selenium
QSpiders - Automation using Selenium
 
Playwright: A New Test Automation Framework for the Modern Web
Playwright: A New Test Automation Framework for the Modern WebPlaywright: A New Test Automation Framework for the Modern Web
Playwright: A New Test Automation Framework for the Modern Web
 
Cypress-vs-Playwright: Let the Code Speak
Cypress-vs-Playwright: Let the Code SpeakCypress-vs-Playwright: Let the Code Speak
Cypress-vs-Playwright: Let the Code Speak
 
BDD with CucumberJS and WebdriverIO
BDD with CucumberJS and WebdriverIOBDD with CucumberJS and WebdriverIO
BDD with CucumberJS and WebdriverIO
 
How to Automate API Testing
How to Automate API TestingHow to Automate API Testing
How to Automate API Testing
 
Server side rendering review
Server side rendering reviewServer side rendering review
Server side rendering review
 
Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...
Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...
Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...
 
Ship quality mobile apps with speed [Webinar]
Ship quality mobile apps with speed [Webinar]Ship quality mobile apps with speed [Webinar]
Ship quality mobile apps with speed [Webinar]
 
Test NG Framework Complete Walk Through
Test NG Framework Complete Walk ThroughTest NG Framework Complete Walk Through
Test NG Framework Complete Walk Through
 
VueJS Introduction
VueJS IntroductionVueJS Introduction
VueJS Introduction
 
Introduction to selenium
Introduction to seleniumIntroduction to selenium
Introduction to selenium
 
Performance Monitoring with Google Lighthouse
Performance Monitoring with Google LighthousePerformance Monitoring with Google Lighthouse
Performance Monitoring with Google Lighthouse
 

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

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
 
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
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 

Recently uploaded (20)

Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
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
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
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 🔝✔️✔️
 
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
 
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
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
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
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
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-...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
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
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
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
 

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