Codeception: introduction to php testing
-
Upload
engineor -
Category
Technology
-
view
862 -
download
5
description
Transcript of Codeception: introduction to php testing
![Page 1: Codeception: introduction to php testing](https://reader033.fdocuments.net/reader033/viewer/2022052619/5565829cd8b42a2b6d8b46b4/html5/thumbnails/1.jpg)
Thomas Dutrion / @tdutrion - September 2014
CodeceptionIntroduction to PHP testing
![Page 2: Codeception: introduction to php testing](https://reader033.fdocuments.net/reader033/viewer/2022052619/5565829cd8b42a2b6d8b46b4/html5/thumbnails/2.jpg)
About me
@tdutrion / @engineor / [email protected]
● Founder and developer/architect at Engineor
● Working with PHP since 2003
● Trying to work properly...
![Page 3: Codeception: introduction to php testing](https://reader033.fdocuments.net/reader033/viewer/2022052619/5565829cd8b42a2b6d8b46b4/html5/thumbnails/3.jpg)
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
![Page 4: Codeception: introduction to php testing](https://reader033.fdocuments.net/reader033/viewer/2022052619/5565829cd8b42a2b6d8b46b4/html5/thumbnails/4.jpg)
● Unit testing
● Integration testing
● Functional testing
● Acceptance testing
● Mutation testing
● Monkey testing
● ...
Codeception
What can we test?
And you, how are you testing?
![Page 5: Codeception: introduction to php testing](https://reader033.fdocuments.net/reader033/viewer/2022052619/5565829cd8b42a2b6d8b46b4/html5/thumbnails/5.jpg)
● 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
![Page 6: Codeception: introduction to php testing](https://reader033.fdocuments.net/reader033/viewer/2022052619/5565829cd8b42a2b6d8b46b4/html5/thumbnails/6.jpg)
● Test modules as groups
● Simulate input
● Less work than Unit testing (smaller number of tests)
Codeception
Integration testing
![Page 7: Codeception: introduction to php testing](https://reader033.fdocuments.net/reader033/viewer/2022052619/5565829cd8b42a2b6d8b46b4/html5/thumbnails/7.jpg)
● 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
![Page 8: Codeception: introduction to php testing](https://reader033.fdocuments.net/reader033/viewer/2022052619/5565829cd8b42a2b6d8b46b4/html5/thumbnails/8.jpg)
Codeception
One tool: Codeception
![Page 9: Codeception: introduction to php testing](https://reader033.fdocuments.net/reader033/viewer/2022052619/5565829cd8b42a2b6d8b46b4/html5/thumbnails/9.jpg)
General introduction
Codeception
History:
● Started in 2011
● Stable release in January 2012
● Version 2.0.5 in August 2014!
● Currently 2725 commits
● 175 contributors...
Problem solved:
● Bridge between all testing types
● No other languages required
● Extensible
● Covers major frameworks
![Page 10: Codeception: introduction to php testing](https://reader033.fdocuments.net/reader033/viewer/2022052619/5565829cd8b42a2b6d8b46b4/html5/thumbnails/10.jpg)
Codeception
PHP 5.4 minimum!!!! (you can do that, right!)
![Page 11: Codeception: introduction to php testing](https://reader033.fdocuments.net/reader033/viewer/2022052619/5565829cd8b42a2b6d8b46b4/html5/thumbnails/11.jpg)
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
![Page 12: Codeception: introduction to php testing](https://reader033.fdocuments.net/reader033/viewer/2022052619/5565829cd8b42a2b6d8b46b4/html5/thumbnails/12.jpg)
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
![Page 13: Codeception: introduction to php testing](https://reader033.fdocuments.net/reader033/viewer/2022052619/5565829cd8b42a2b6d8b46b4/html5/thumbnails/13.jpg)
$ 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)
![Page 14: Codeception: introduction to php testing](https://reader033.fdocuments.net/reader033/viewer/2022052619/5565829cd8b42a2b6d8b46b4/html5/thumbnails/14.jpg)
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)
![Page 15: Codeception: introduction to php testing](https://reader033.fdocuments.net/reader033/viewer/2022052619/5565829cd8b42a2b6d8b46b4/html5/thumbnails/15.jpg)
● 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?
![Page 16: Codeception: introduction to php testing](https://reader033.fdocuments.net/reader033/viewer/2022052619/5565829cd8b42a2b6d8b46b4/html5/thumbnails/16.jpg)
Demonstration: Firefox run
![Page 17: Codeception: introduction to php testing](https://reader033.fdocuments.net/reader033/viewer/2022052619/5565829cd8b42a2b6d8b46b4/html5/thumbnails/17.jpg)
● 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
![Page 18: Codeception: introduction to php testing](https://reader033.fdocuments.net/reader033/viewer/2022052619/5565829cd8b42a2b6d8b46b4/html5/thumbnails/18.jpg)
Codeception
Demonstration: headless run
![Page 19: Codeception: introduction to php testing](https://reader033.fdocuments.net/reader033/viewer/2022052619/5565829cd8b42a2b6d8b46b4/html5/thumbnails/19.jpg)
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
![Page 20: Codeception: introduction to php testing](https://reader033.fdocuments.net/reader033/viewer/2022052619/5565829cd8b42a2b6d8b46b4/html5/thumbnails/20.jpg)
Questions?
Codeception: introduction to PHP testing, by Thomas Dutrion from Engineor for Glasgow PHP, September 2014
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!
● Glasgow PHP (@glasgowphp) to let me talk here
Please rate and comment this talk on SlideShare: http://goo.gl/uJIh7G