SlideShare a Scribd company logo
Thomas Dutrion / @tdutrion - October 2014
Codeception
Introduction to PHP testing
About me
@tdutrion / @engineor / thomas@engineor.com
● Founder and developer/architect at Engineor
● Working with PHP since 2003
● Trying to work properly...
PHP3: simple web pages
PHP4: object? are you kidding?
PHP5: mature language, with namespaces, real objects and so on…
What is missing to compete with other languages?
TESTABILITY
Codeception
PHP best practice: industrialisation
● Unit testing
● Integration testing
● Functional testing
● Acceptance testing
● Mutation testing
● Monkey testing
● ...
Codeception
What can we test?
And you, how are you testing?
● Small unit of code
● SOLID principle (single Responsibility, Open-closed, Liskov substitution, Interface segregation and Dependency inversion)
● Requires complete isolation
● Long to write, requires continuous updates, expensive
=> very good for critical parts of the application!
Codeception
Unit testing
● Test modules as groups
● Simulate input
● Less work than Unit testing (smaller number of tests)
Codeception
Integration testing
● Test final application appearance
● Reproduce complete application execution
● Client point of view
● Less code, final result only, help on legacy projects
=> Can be used to prove the completion of the project
Codeception
Acceptance testing
Codeception
One tool: Codeception
General introduction
Codeception
History:
● Started in 2011
● Stable release in January 2012
● Version 2.1.3 in this month!
● Currently 4267 commits
● 295 contributors...
Problem solved:
● Bridge between all testing types
● No other languages required
● Extensible
● Covers major frameworks
Codeception
PHP 5.4 minimum (use at least 5.6 anyways!)
You already know it!
Based on recommended and proven tools
● PHPUnit
● Symfony browserkit
● Selenium / PhantomJS (optional)
● …
Test suite written in PHP => no need to learn another language.
Codeception
Follow the quickstart!
1. Install codeception (prefer using composer, globally or in dev only)
2. Bootstrap (directories and files structure, basic configuration)
3. Generate acceptance testing
4. Write tests
5. And run!
Codeception
Acceptance testing 101
$ php vendor/bin/codecept run
Codeception PHP Testing Framework v2.0.5
Powered by PHPUnit 4.2.5 by Sebastian Bergmann.
Acceptance Tests (1) ------------------------------------------------------------------------------------------------------------
Trying to ensure that frontpage works (WelcomeCept) Ok
---------------------------------------------------------------------------------------------------------------------------------
Functional Tests (0) ---------------------------------------------------------------------
Unit Tests (0) ---------------------------------------------------------------------------
Time: 382 ms, Memory: 8.50Mb
OK (1 test, 1 assertion)
Codeception
Basic example results (pass)
Acceptance Tests (1) ------------------------------------------------------------------------------------------------------------
Trying to ensure that frontpage works (WelcomeCept) Fail
There was 1 failure:
1) Failed to ensure that frontpage works in WelcomeCept (/Users/thomas/NetBeansProjects/Codeception01/tests/acceptance/WelcomeCept.
php)
Couldn't see "Not ok":
Failed asserting that /
→ Your HTML code here
[Content too long to display. See complete response in '_output' directory]
--> contains "not ok".
Scenario Steps:
2. I see "Not ok"
1. I am on page "/"
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
Codeception
Basic example results (fail)
● Since 2005, AJAX is everywhere (XmlHttpRequest)
● New architecture: MVVM javascript in front, PHP/node… in back
Testing problem: PHPBrowser / Curl can not read javascript modifications.
=> Codeception can work with Selenium!
Codeception
What about sexy frontends?
Demonstration: Firefox run
● No Firefox and or java on your servers => no Selenium on CI
● CI usually run only simple bash scripts
● Need to run the test in command line, emulating an headless browser
=> Codeception PhantomJS driver
Codeception
Headless testing for Continuous Integration
Codeception
Demonstration: headless run
Workflow improvement
Codeception
● Use Docker containers or Vagrant virtual boxes to add development, testing
and production servers configuration to your VCS repository
● Add CI server triggered on commits, with email results
Questions?
Codeception: introduction to PHP testing, by Thomas Dutrion from Engineor for Aberdeen PHP, October 2015
Special thanks to / reading recommendation:
● Jeremy Coates (@phpcodemonkey) for Testing with codeception
● PHPNW (@phpnw), great PHP group that made me discover Codeception
● All of you for your patience and supporting my French accent!
● Aberdeen PHP (@AberdeenPHP) to let me talk here
Please rate and comment this talk on SlideShare: http://goo.gl/JRd4W5

More Related Content

PDF
Acceptance testing in php with Codeception - Techmeetup Edinburgh
PDF
Testing PHP with Codeception
PPTX
Test automation with php codeception
PPTX
CI / CD w/ Codeception
PDF
Testing with Codeception
PDF
Codeception: introduction to php testing
PDF
Codeception
PDF
Codeception presentation
Acceptance testing in php with Codeception - Techmeetup Edinburgh
Testing PHP with Codeception
Test automation with php codeception
CI / CD w/ Codeception
Testing with Codeception
Codeception: introduction to php testing
Codeception
Codeception presentation

What's hot (20)

PDF
PHP Unit Testing in Yii
PDF
Codeception introduction and use in Yii
PDF
Testing with Codeception (Webelement #30)
PPTX
Codeception
PDF
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
PDF
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
PDF
Acceptance & Functional Testing with Codeception - Devspace 2015
PPTX
Automation testing with Drupal 8
PDF
Nginx pres
PPTX
Automated Web Testing With Selenium
PDF
Continuous Quality Assurance using Selenium WebDriver
 
PPT
Robotframework Presentation - Pinoy Python Meetup 2011January12
PDF
Fighting Fear-Driven-Development With PHPUnit
ODP
Integration Testing in Python
PDF
Unit testing - A&BP CC
PDF
How do I Write Testable Javascript so I can Test my CF API on Server and Client
PPTX
Robot framework
PPTX
Intro to JavaScript Tooling in Visual Studio Code
PPTX
Python in Test automation
PPT
Testing Java Web Apps With Selenium
PHP Unit Testing in Yii
Codeception introduction and use in Yii
Testing with Codeception (Webelement #30)
Codeception
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Acceptance & Functional Testing with Codeception - Devspace 2015
Automation testing with Drupal 8
Nginx pres
Automated Web Testing With Selenium
Continuous Quality Assurance using Selenium WebDriver
 
Robotframework Presentation - Pinoy Python Meetup 2011January12
Fighting Fear-Driven-Development With PHPUnit
Integration Testing in Python
Unit testing - A&BP CC
How do I Write Testable Javascript so I can Test my CF API on Server and Client
Robot framework
Intro to JavaScript Tooling in Visual Studio Code
Python in Test automation
Testing Java Web Apps With Selenium
Ad

Similar to Codeception: introduction to php testing (v2 - Aberdeen php) (20)

PDF
Joomla Code Quality Control and Automation Testing
PDF
Test all the things! Automated testing with Drupal 8
PDF
Continuous Integration In Php
PPT
[ENGLISH] TDC 2015 - PHP Trail - Tests and PHP Continuous Integration Enviro...
PDF
Pragmatic Introduction to PHP Unit Testing (2015)
PDF
TDD for joomla extensions
PPTX
Codeception @ New Business Dept Adira Finance
PDF
UPC Plone Testing Talk
PDF
Unit testing (eng)
PDF
PHP - Programming language war, does it matter
PPTX
Binary Studio Academy: .NET Code Testing
PDF
Continuous Integration at Mollie
ODP
Test Driven Development (TDD) with Windows PowerShell
PPTX
Framework
PDF
Behaviour testing for single-page applications and API’s
PDF
Behaviour Testing and Continuous Integration with Drupal
PPTX
NET Code Testing
PDF
Test driven development - Zombie proof your code
PDF
Test Driven Development with PHP
Joomla Code Quality Control and Automation Testing
Test all the things! Automated testing with Drupal 8
Continuous Integration In Php
[ENGLISH] TDC 2015 - PHP Trail - Tests and PHP Continuous Integration Enviro...
Pragmatic Introduction to PHP Unit Testing (2015)
TDD for joomla extensions
Codeception @ New Business Dept Adira Finance
UPC Plone Testing Talk
Unit testing (eng)
PHP - Programming language war, does it matter
Binary Studio Academy: .NET Code Testing
Continuous Integration at Mollie
Test Driven Development (TDD) with Windows PowerShell
Framework
Behaviour testing for single-page applications and API’s
Behaviour Testing and Continuous Integration with Drupal
NET Code Testing
Test driven development - Zombie proof your code
Test Driven Development with PHP
Ad

Recently uploaded (20)

PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Machine learning based COVID-19 study performance prediction
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Empathic Computing: Creating Shared Understanding
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
cuic standard and advanced reporting.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Tartificialntelligence_presentation.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
Spectral efficient network and resource selection model in 5G networks
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Encapsulation_ Review paper, used for researhc scholars
Machine learning based COVID-19 study performance prediction
Diabetes mellitus diagnosis method based random forest with bat algorithm
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Encapsulation theory and applications.pdf
Network Security Unit 5.pdf for BCA BBA.
Empathic Computing: Creating Shared Understanding
Dropbox Q2 2025 Financial Results & Investor Presentation
cuic standard and advanced reporting.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
20250228 LYD VKU AI Blended-Learning.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Tartificialntelligence_presentation.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Mobile App Security Testing_ A Comprehensive Guide.pdf

Codeception: introduction to php testing (v2 - Aberdeen php)

  • 1. Thomas Dutrion / @tdutrion - October 2014 Codeception Introduction to PHP testing
  • 2. About me @tdutrion / @engineor / [email protected] ● Founder and developer/architect at Engineor ● Working with PHP since 2003 ● Trying to work properly...
  • 3. PHP3: simple web pages PHP4: object? are you kidding? PHP5: mature language, with namespaces, real objects and so on… What is missing to compete with other languages? TESTABILITY Codeception PHP best practice: industrialisation
  • 4. ● Unit testing ● Integration testing ● Functional testing ● Acceptance testing ● Mutation testing ● Monkey testing ● ... Codeception What can we test? And you, how are you testing?
  • 5. ● Small unit of code ● SOLID principle (single Responsibility, Open-closed, Liskov substitution, Interface segregation and Dependency inversion) ● Requires complete isolation ● Long to write, requires continuous updates, expensive => very good for critical parts of the application! Codeception Unit testing
  • 6. ● Test modules as groups ● Simulate input ● Less work than Unit testing (smaller number of tests) Codeception Integration testing
  • 7. ● Test final application appearance ● Reproduce complete application execution ● Client point of view ● Less code, final result only, help on legacy projects => Can be used to prove the completion of the project Codeception Acceptance testing
  • 9. General introduction Codeception History: ● Started in 2011 ● Stable release in January 2012 ● Version 2.1.3 in this month! ● Currently 4267 commits ● 295 contributors... Problem solved: ● Bridge between all testing types ● No other languages required ● Extensible ● Covers major frameworks
  • 10. Codeception PHP 5.4 minimum (use at least 5.6 anyways!)
  • 11. You already know it! Based on recommended and proven tools ● PHPUnit ● Symfony browserkit ● Selenium / PhantomJS (optional) ● … Test suite written in PHP => no need to learn another language. Codeception
  • 12. Follow the quickstart! 1. Install codeception (prefer using composer, globally or in dev only) 2. Bootstrap (directories and files structure, basic configuration) 3. Generate acceptance testing 4. Write tests 5. And run! Codeception Acceptance testing 101
  • 13. $ php vendor/bin/codecept run Codeception PHP Testing Framework v2.0.5 Powered by PHPUnit 4.2.5 by Sebastian Bergmann. Acceptance Tests (1) ------------------------------------------------------------------------------------------------------------ Trying to ensure that frontpage works (WelcomeCept) Ok --------------------------------------------------------------------------------------------------------------------------------- Functional Tests (0) --------------------------------------------------------------------- Unit Tests (0) --------------------------------------------------------------------------- Time: 382 ms, Memory: 8.50Mb OK (1 test, 1 assertion) Codeception Basic example results (pass)
  • 14. Acceptance Tests (1) ------------------------------------------------------------------------------------------------------------ Trying to ensure that frontpage works (WelcomeCept) Fail There was 1 failure: 1) Failed to ensure that frontpage works in WelcomeCept (/Users/thomas/NetBeansProjects/Codeception01/tests/acceptance/WelcomeCept. php) Couldn't see "Not ok": Failed asserting that / → Your HTML code here [Content too long to display. See complete response in '_output' directory] --> contains "not ok". Scenario Steps: 2. I see "Not ok" 1. I am on page "/" FAILURES! Tests: 1, Assertions: 1, Failures: 1. Codeception Basic example results (fail)
  • 15. ● Since 2005, AJAX is everywhere (XmlHttpRequest) ● New architecture: MVVM javascript in front, PHP/node… in back Testing problem: PHPBrowser / Curl can not read javascript modifications. => Codeception can work with Selenium! Codeception What about sexy frontends?
  • 17. ● No Firefox and or java on your servers => no Selenium on CI ● CI usually run only simple bash scripts ● Need to run the test in command line, emulating an headless browser => Codeception PhantomJS driver Codeception Headless testing for Continuous Integration
  • 19. Workflow improvement Codeception ● Use Docker containers or Vagrant virtual boxes to add development, testing and production servers configuration to your VCS repository ● Add CI server triggered on commits, with email results
  • 20. Questions? Codeception: introduction to PHP testing, by Thomas Dutrion from Engineor for Aberdeen PHP, October 2015 Special thanks to / reading recommendation: ● Jeremy Coates (@phpcodemonkey) for Testing with codeception ● PHPNW (@phpnw), great PHP group that made me discover Codeception ● All of you for your patience and supporting my French accent! ● Aberdeen PHP (@AberdeenPHP) to let me talk here Please rate and comment this talk on SlideShare: http://goo.gl/JRd4W5