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

Cv site civil engineer
Cv site civil engineerCv site civil engineer
Cv site civil engineersandeep jangir
 
edwin cv for QA-QC Engineer
edwin cv for QA-QC Engineeredwin cv for QA-QC Engineer
edwin cv for QA-QC EngineerEdwin Aguinaldo
 
Danish AYTB Experience Certificate (PDF)
Danish AYTB Experience Certificate (PDF)Danish AYTB Experience Certificate (PDF)
Danish AYTB Experience Certificate (PDF)Danish Anis
 
Resume For Document Controller (Updated)
Resume For Document Controller (Updated)Resume For Document Controller (Updated)
Resume For Document Controller (Updated)Rizwan Younas
 
Document Controller Resume
Document Controller Resume   Document Controller Resume
Document Controller Resume Altaf Tanwar
 
Experience Certificate - Federal
Experience Certificate - FederalExperience Certificate - Federal
Experience Certificate - FederalMahmoud Basiony
 
Saad_CV Senior QA&QC Engineer
Saad_CV Senior QA&QC EngineerSaad_CV Senior QA&QC Engineer
Saad_CV Senior QA&QC EngineerSaad mohamed gad
 
Electrical Engineer having Experience (1)
Electrical Engineer having Experience (1)Electrical Engineer having Experience (1)
Electrical Engineer having Experience (1)s4over
 
Cv for qc inspector mechanical
Cv for qc inspector mechanicalCv for qc inspector mechanical
Cv for qc inspector mechanicalShaik Ghouse
 
Resume electrical engineer- for oil &amp; gas
Resume  electrical engineer- for oil &amp; gasResume  electrical engineer- for oil &amp; gas
Resume electrical engineer- for oil &amp; gasvineeth ravi
 
Naveed shahzad land surveyor cv
Naveed shahzad land surveyor cvNaveed shahzad land surveyor cv
Naveed shahzad land surveyor cvNaveed Shahzad
 
CV Sajid Akhtar - Lead Document Controller - 01 Jan 2017
CV Sajid Akhtar - Lead Document Controller - 01 Jan 2017CV Sajid Akhtar - Lead Document Controller - 01 Jan 2017
CV Sajid Akhtar - Lead Document Controller - 01 Jan 2017Sajid Akhtar
 
Resume of jaison varkey QA/QC Inspector welding,coating
Resume of jaison varkey QA/QC Inspector welding,coatingResume of jaison varkey QA/QC Inspector welding,coating
Resume of jaison varkey QA/QC Inspector welding,coatingjaison varkey
 
L & T Experiance certi
L & T Experiance certiL & T Experiance certi
L & T Experiance certiRAKESH PATEL
 
Protection engineer cv
Protection engineer cvProtection engineer cv
Protection engineer cvWael Elsayed
 

What's hot (20)

Cv site civil engineer
Cv site civil engineerCv site civil engineer
Cv site civil engineer
 
edwin cv for QA-QC Engineer
edwin cv for QA-QC Engineeredwin cv for QA-QC Engineer
edwin cv for QA-QC Engineer
 
Danish AYTB Experience Certificate (PDF)
Danish AYTB Experience Certificate (PDF)Danish AYTB Experience Certificate (PDF)
Danish AYTB Experience Certificate (PDF)
 
Recommendation letter 5
Recommendation letter 5Recommendation letter 5
Recommendation letter 5
 
Resume For Document Controller (Updated)
Resume For Document Controller (Updated)Resume For Document Controller (Updated)
Resume For Document Controller (Updated)
 
Document Controller Resume
Document Controller Resume   Document Controller Resume
Document Controller Resume
 
DOCUMENT CONTROLLER CV
DOCUMENT CONTROLLER  CVDOCUMENT CONTROLLER  CV
DOCUMENT CONTROLLER CV
 
Experience Certificate - Federal
Experience Certificate - FederalExperience Certificate - Federal
Experience Certificate - Federal
 
Saad_CV Senior QA&QC Engineer
Saad_CV Senior QA&QC EngineerSaad_CV Senior QA&QC Engineer
Saad_CV Senior QA&QC Engineer
 
Electrical Engineer having Experience (1)
Electrical Engineer having Experience (1)Electrical Engineer having Experience (1)
Electrical Engineer having Experience (1)
 
piping foreman resume
piping foreman resumepiping foreman resume
piping foreman resume
 
Cv for qc inspector mechanical
Cv for qc inspector mechanicalCv for qc inspector mechanical
Cv for qc inspector mechanical
 
Quantity Surveyor
Quantity SurveyorQuantity Surveyor
Quantity Surveyor
 
Resume electrical engineer- for oil &amp; gas
Resume  electrical engineer- for oil &amp; gasResume  electrical engineer- for oil &amp; gas
Resume electrical engineer- for oil &amp; gas
 
Naveed shahzad land surveyor cv
Naveed shahzad land surveyor cvNaveed shahzad land surveyor cv
Naveed shahzad land surveyor cv
 
CV Sajid Akhtar - Lead Document Controller - 01 Jan 2017
CV Sajid Akhtar - Lead Document Controller - 01 Jan 2017CV Sajid Akhtar - Lead Document Controller - 01 Jan 2017
CV Sajid Akhtar - Lead Document Controller - 01 Jan 2017
 
Resume of jaison varkey QA/QC Inspector welding,coating
Resume of jaison varkey QA/QC Inspector welding,coatingResume of jaison varkey QA/QC Inspector welding,coating
Resume of jaison varkey QA/QC Inspector welding,coating
 
L & T Experiance certi
L & T Experiance certiL & T Experiance certi
L & T Experiance certi
 
ROR is not mandatory for the Registration of land in Kerala www.jamesadhikara...
ROR is not mandatory for the Registration of land in Kerala www.jamesadhikara...ROR is not mandatory for the Registration of land in Kerala www.jamesadhikara...
ROR is not mandatory for the Registration of land in Kerala www.jamesadhikara...
 
Protection engineer cv
Protection engineer cvProtection engineer cv
Protection engineer cv
 

Similar to Codeception presentation

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)Ondřej Machulda
 
Release with confidence
Release with confidenceRelease with confidence
Release with confidenceJohn Congdon
 
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,...Ondřej Machulda
 
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsEffizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsDECK36
 
Better Testing With PHP Unit
Better Testing With PHP UnitBetter Testing With PHP Unit
Better Testing With PHP Unitsitecrafting
 
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 frameworkGosuke Miyashita
 
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 WebSocketsAndrei Sebastian Cîmpean
 
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 Applicationsqooxdoo
 
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!Puneet Kala
 
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 SuccessfullySpringPeople
 
Protractor framework architecture with example
Protractor framework architecture with exampleProtractor framework architecture with example
Protractor framework architecture with exampleshadabgilani
 
Beginning AngularJS
Beginning AngularJSBeginning AngularJS
Beginning AngularJSTroy Miles
 
Javascript tdd byandreapaciolla
Javascript tdd byandreapaciollaJavascript tdd byandreapaciolla
Javascript tdd byandreapaciollaAndrea Paciolla
 
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
 
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 PuppeteerPaul Jensen
 
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 2016Joe Ferguson
 
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 exploitsMunir Njiru
 
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 2016Dusan Lukic
 

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

Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...Akihiro Suda
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 

Recently uploaded (20)

Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 

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