Unit-Tests
                                  Schnell und einfach selbst gemacht


                                     TobiasSchlitt <toby@php.net>

                                           PHP World Kongress 2009


                                                2009-11-24




Tobias Schlitt (PHP World Kongress 2009)           Unit-Tests          2009-11-24   1 / 25
About me



         Tobias Schlitt <toby@php.net>
         PHP since 2001
         Freelancing consultant
         Qualified IT Specialist
         Studying CS at TU Dortmund
         (finishing mid 2010)
         OSS addicted
                eZ Components
                PHPUnit
                Various other projects . . .




Tobias Schlitt (PHP World Kongress 2009)       Unit-Tests   2009-11-24   2 / 25
Overview




   1 Testing


   2 PHPUnit


   3 Advanced scenarios (optional)


   4 The end




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   3 / 25
Outline




  1 Testing
          Methods of testing
          Unit tests

  2 PHPUnit


  3 Advanced scenarios (optional)


  4 The end




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   4 / 25
A little survey . . .




   Do you test?
       When?
          How?
          Who?




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   5 / 25
A little survey . . .




   Do you test?
       When?
          How?
          Who?




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   5 / 25
A little survey . . .




   Do you test?
       When?
          How?
          Who?




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   5 / 25
A little survey . . .




   Do you test?
       When?
          How?
          Who?




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   5 / 25
Ways of testing




          Automatic vs. manual
          Developer vs. tester
          Internal vs. external
          Back end vs. front end
          Code vs. appearance
          Functional vs. non-functional
          Dynamic vs. static




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   6 / 25
Ways of testing




          Automatic vs. manual
          Developer vs. tester
          Internal vs. external
          Back end vs. front end
          Code vs. appearance
          Functional vs. non-functional
          Dynamic vs. static




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   6 / 25
Ways of testing




          Automatic vs. manual
          Developer vs. tester
          Internal vs. external
          Back end vs. front end
          Code vs. appearance
          Functional vs. non-functional
          Dynamic vs. static




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   6 / 25
Ways of testing




          Automatic vs. manual
          Developer vs. tester
          Internal vs. external
          Back end vs. front end
          Code vs. appearance
          Functional vs. non-functional
          Dynamic vs. static




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   6 / 25
Ways of testing




          Automatic vs. manual
          Developer vs. tester
          Internal vs. external
          Back end vs. front end
          Code vs. appearance
          Functional vs. non-functional
          Dynamic vs. static




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   6 / 25
Ways of testing




          Automatic vs. manual
          Developer vs. tester
          Internal vs. external
          Back end vs. front end
          Code vs. appearance
          Functional vs. non-functional
          Dynamic vs. static




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   6 / 25
Ways of testing




          Automatic vs. manual
          Developer vs. tester
          Internal vs. external
          Back end vs. front end
          Code vs. appearance
          Functional vs. non-functional
          Dynamic vs. static




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   6 / 25
Ways of testing




          Automatic vs. manual
          Developer vs. tester
          Internal vs. external
          Back end vs. front end
          Code vs. appearance
          Functional vs. non-functional
          Dynamic vs. static




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   6 / 25
Test methods




          Unit tests
          Integration tests
          Regression tests
          Acceptance tests




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   7 / 25
Unit tests



          Validate functionality
          Test a single unit of code
          Avoid regressions
          Verify interfaces
          Test bugs dedicatedly
          Force code modularization
          Migrate safely
          Test driven development (TDD)




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   8 / 25
Unit tests



          Validate functionality
          Test a single unit of code
          Avoid regressions
          Verify interfaces
          Test bugs dedicatedly
          Force code modularization
          Migrate safely
          Test driven development (TDD)




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   8 / 25
Unit tests



          Validate functionality
          Test a single unit of code
          Avoid regressions
          Verify interfaces
          Test bugs dedicatedly
          Force code modularization
          Migrate safely
          Test driven development (TDD)




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   8 / 25
Unit tests



          Validate functionality
          Test a single unit of code
          Avoid regressions
          Verify interfaces
          Test bugs dedicatedly
          Force code modularization
          Migrate safely
          Test driven development (TDD)




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   8 / 25
Unit tests



          Validate functionality
          Test a single unit of code
          Avoid regressions
          Verify interfaces
          Test bugs dedicatedly
          Force code modularization
          Migrate safely
          Test driven development (TDD)




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   8 / 25
Unit tests



          Validate functionality
          Test a single unit of code
          Avoid regressions
          Verify interfaces
          Test bugs dedicatedly
          Force code modularization
          Migrate safely
          Test driven development (TDD)




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   8 / 25
Unit tests



          Validate functionality
          Test a single unit of code
          Avoid regressions
          Verify interfaces
          Test bugs dedicatedly
          Force code modularization
          Migrate safely
          Test driven development (TDD)




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   8 / 25
Unit tests



          Validate functionality
          Test a single unit of code
          Avoid regressions
          Verify interfaces
          Test bugs dedicatedly
          Force code modularization
          Migrate safely
          Test driven development (TDD)




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   8 / 25
Outline



  1 Testing


  2 PHPUnit
          Installation
          PHPUnit basics
          Code examples

  3 Advanced scenarios (optional)


  4 The end




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   9 / 25
PHPUnit




          Port of JUnit to PHP
          Many enhancements
                 Database tests
                 Code coverage
                 Data providers
          Invented by Sebastian Bergmann
          Standard for unit testing in PHP
          http://www.phpunit.de/




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   10 / 25
Installation




   Via PEAR
       $ pear channel-discover pear.phpunit.de
          $ pear install phpunit/PHPUnit




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   11 / 25
PHPUnit basics




                                           YourClass




Tobias Schlitt (PHP World Kongress 2009)    Unit-Tests   2009-11-24   12 / 25
PHPUnit basics




                       YourClass                        YourClassTest




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests               2009-11-24   12 / 25
PHPUnit basics




                       YourClass                        YourClassTest




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests               2009-11-24   12 / 25
PHPUnit basics




                                                          TestCase




                       YourClass                        YourClassTest




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests                2009-11-24   12 / 25
PHPUnit basics



                                           TestRunner




                                                             TestCase




                       YourClass                           YourClassTest




Tobias Schlitt (PHP World Kongress 2009)      Unit-Tests                2009-11-24   12 / 25
PHPUnit basics



                                           TestRunner




                                                             TestCase




                       YourClass                           YourClassTest




Tobias Schlitt (PHP World Kongress 2009)      Unit-Tests                2009-11-24   12 / 25
Let’s dig into some code




 Let’s dig into some code




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   13 / 25
Outline



  1 Testing


  2 PHPUnit


  3 Advanced scenarios (optional)
          Custom test environment
          Testing a WebDAV server
          Testing graphic generation
          Testing parsers

  4 The end




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   14 / 25
eZ Component test runner




          Custom test runner
                 Integrated auto loading
                 Component base testing
                 Run all tests
          Extended test case / suite classes
                 Custom assertions
                 Database testing
                 Utility functions




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   15 / 25
eZ Webdav component




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   16 / 25
Semi-automatic regression tests




          Manual client test run
          Defined test receipe
          Capture request / response data
          Replay request in unit tests
          Detect response regressions




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   17 / 25
Binary regressions




          Binary differences in generated images
          Test failures depending on
                 PHP version
                 GD version
                 Operating system
          Images visually equivalent




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   18 / 25
Custom assertions




          Custom assertion
          Custom equality constraint
                 Based on ImageMagick
                 Allows defined gap




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   19 / 25
Untestable code




          Parsers are highly dependant
          De-coupling hardly possible
          Huge amount of mock objects




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   20 / 25
Integration tests




          Test parser as a whole
          Small test files
                 Manually create / validate
          Large overall tests
                 Manual inspection of generated data




Tobias Schlitt (PHP World Kongress 2009)      Unit-Tests   2009-11-24   21 / 25
Outline




  1 Testing


  2 PHPUnit


  3 Advanced scenarios (optional)


  4 The end




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   22 / 25
Questions / Answers




                                  Questions? Feedback? Critics?




Tobias Schlitt (PHP World Kongress 2009)     Unit-Tests           2009-11-24   23 / 25
The end




          I hope you enjoyed the session
          Slides and material
                 http://schlitt.info/opensource
                 http://www.slideshare.net/tobyS
          Contact: Tobias Schlitt <toby@php.net>




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   24 / 25
PHPUnderControl




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   25 / 25

More Related Content

PPTX
The Test way
KEY
Unit testing for Cocoa developers
PDF
Pragmatic Introduction to PHP Unit Testing (2015)
PDF
The Evolution of Development Testing
PDF
Automatic Comment Analysis
PPT
Dev305 Entity Framework 4 Emergency Slides
PDF
PDF
Profiling PHP Applications
The Test way
Unit testing for Cocoa developers
Pragmatic Introduction to PHP Unit Testing (2015)
The Evolution of Development Testing
Automatic Comment Analysis
Dev305 Entity Framework 4 Emergency Slides
Profiling PHP Applications

Similar to Unit-Tests (20)

ZIP
Test
PDF
Test Automation
PDF
Intro to PHP Testing
PDF
PHPUnit & Continuous Integration: An Introduction
PDF
Cursus phpunit
PDF
Your code are my tests
PPTX
Test in action week 2
PPT
Test Driven Development with PHPUnit
PPT
Test Driven Development with PHPUnit
KEY
Developer testing 101: Become a Testing Fanatic
PPTX
Test in action – week 1
KEY
Php Unit With Zend Framework Zendcon09
PDF
Unit testing in PHP
PPTX
Regression Testing with Symfony
ODP
PHPUnit from a developer's perspective
KEY
Unit Testing Your Application
PPT
Automated testing 101
PDF
Test Driven Development
PDF
Unit and integration Testing
KEY
Developer testing 201: When to Mock and When to Integrate
Test
Test Automation
Intro to PHP Testing
PHPUnit & Continuous Integration: An Introduction
Cursus phpunit
Your code are my tests
Test in action week 2
Test Driven Development with PHPUnit
Test Driven Development with PHPUnit
Developer testing 101: Become a Testing Fanatic
Test in action – week 1
Php Unit With Zend Framework Zendcon09
Unit testing in PHP
Regression Testing with Symfony
PHPUnit from a developer's perspective
Unit Testing Your Application
Automated testing 101
Test Driven Development
Unit and integration Testing
Developer testing 201: When to Mock and When to Integrate
Ad

More from Tobias Schlitt (7)

PDF
HTML to ODT to XML to PDF to …
PDF
Validating XML - Avoiding the pain
PDF
XPath - A practical guide
PDF
Professional XML with PHP
PDF
PDF
XML and XPath with PHP
PDF
WebDAV - The good, the bad and the evil
HTML to ODT to XML to PDF to …
Validating XML - Avoiding the pain
XPath - A practical guide
Professional XML with PHP
XML and XPath with PHP
WebDAV - The good, the bad and the evil
Ad

Recently uploaded (20)

PDF
Flame analysis and combustion estimation using large language and vision assi...
PPTX
The various Industrial Revolutions .pptx
PDF
Developing a website for English-speaking practice to English as a foreign la...
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PDF
Credit Without Borders: AI and Financial Inclusion in Bangladesh
PPTX
Benefits of Physical activity for teenagers.pptx
PPTX
Custom Battery Pack Design Considerations for Performance and Safety
PPTX
Chapter 5: Probability Theory and Statistics
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PPTX
Microsoft Excel 365/2024 Beginner's training
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PDF
Getting started with AI Agents and Multi-Agent Systems
PPT
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
PDF
UiPath Agentic Automation session 1: RPA to Agents
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
OpenACC and Open Hackathons Monthly Highlights July 2025
Flame analysis and combustion estimation using large language and vision assi...
The various Industrial Revolutions .pptx
Developing a website for English-speaking practice to English as a foreign la...
Zenith AI: Advanced Artificial Intelligence
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
Credit Without Borders: AI and Financial Inclusion in Bangladesh
Benefits of Physical activity for teenagers.pptx
Custom Battery Pack Design Considerations for Performance and Safety
Chapter 5: Probability Theory and Statistics
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Microsoft Excel 365/2024 Beginner's training
A comparative study of natural language inference in Swahili using monolingua...
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
sustainability-14-14877-v2.pddhzftheheeeee
Getting started with AI Agents and Multi-Agent Systems
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
UiPath Agentic Automation session 1: RPA to Agents
NewMind AI Weekly Chronicles – August ’25 Week III
OpenACC and Open Hackathons Monthly Highlights July 2025

Unit-Tests

  • 1. Unit-Tests Schnell und einfach selbst gemacht TobiasSchlitt <toby@php.net> PHP World Kongress 2009 2009-11-24 Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 1 / 25
  • 2. About me Tobias Schlitt <toby@php.net> PHP since 2001 Freelancing consultant Qualified IT Specialist Studying CS at TU Dortmund (finishing mid 2010) OSS addicted eZ Components PHPUnit Various other projects . . . Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 2 / 25
  • 3. Overview 1 Testing 2 PHPUnit 3 Advanced scenarios (optional) 4 The end Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 3 / 25
  • 4. Outline 1 Testing Methods of testing Unit tests 2 PHPUnit 3 Advanced scenarios (optional) 4 The end Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 4 / 25
  • 5. A little survey . . . Do you test? When? How? Who? Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 5 / 25
  • 6. A little survey . . . Do you test? When? How? Who? Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 5 / 25
  • 7. A little survey . . . Do you test? When? How? Who? Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 5 / 25
  • 8. A little survey . . . Do you test? When? How? Who? Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 5 / 25
  • 9. Ways of testing Automatic vs. manual Developer vs. tester Internal vs. external Back end vs. front end Code vs. appearance Functional vs. non-functional Dynamic vs. static Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 6 / 25
  • 10. Ways of testing Automatic vs. manual Developer vs. tester Internal vs. external Back end vs. front end Code vs. appearance Functional vs. non-functional Dynamic vs. static Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 6 / 25
  • 11. Ways of testing Automatic vs. manual Developer vs. tester Internal vs. external Back end vs. front end Code vs. appearance Functional vs. non-functional Dynamic vs. static Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 6 / 25
  • 12. Ways of testing Automatic vs. manual Developer vs. tester Internal vs. external Back end vs. front end Code vs. appearance Functional vs. non-functional Dynamic vs. static Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 6 / 25
  • 13. Ways of testing Automatic vs. manual Developer vs. tester Internal vs. external Back end vs. front end Code vs. appearance Functional vs. non-functional Dynamic vs. static Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 6 / 25
  • 14. Ways of testing Automatic vs. manual Developer vs. tester Internal vs. external Back end vs. front end Code vs. appearance Functional vs. non-functional Dynamic vs. static Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 6 / 25
  • 15. Ways of testing Automatic vs. manual Developer vs. tester Internal vs. external Back end vs. front end Code vs. appearance Functional vs. non-functional Dynamic vs. static Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 6 / 25
  • 16. Ways of testing Automatic vs. manual Developer vs. tester Internal vs. external Back end vs. front end Code vs. appearance Functional vs. non-functional Dynamic vs. static Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 6 / 25
  • 17. Test methods Unit tests Integration tests Regression tests Acceptance tests Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 7 / 25
  • 18. Unit tests Validate functionality Test a single unit of code Avoid regressions Verify interfaces Test bugs dedicatedly Force code modularization Migrate safely Test driven development (TDD) Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 8 / 25
  • 19. Unit tests Validate functionality Test a single unit of code Avoid regressions Verify interfaces Test bugs dedicatedly Force code modularization Migrate safely Test driven development (TDD) Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 8 / 25
  • 20. Unit tests Validate functionality Test a single unit of code Avoid regressions Verify interfaces Test bugs dedicatedly Force code modularization Migrate safely Test driven development (TDD) Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 8 / 25
  • 21. Unit tests Validate functionality Test a single unit of code Avoid regressions Verify interfaces Test bugs dedicatedly Force code modularization Migrate safely Test driven development (TDD) Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 8 / 25
  • 22. Unit tests Validate functionality Test a single unit of code Avoid regressions Verify interfaces Test bugs dedicatedly Force code modularization Migrate safely Test driven development (TDD) Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 8 / 25
  • 23. Unit tests Validate functionality Test a single unit of code Avoid regressions Verify interfaces Test bugs dedicatedly Force code modularization Migrate safely Test driven development (TDD) Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 8 / 25
  • 24. Unit tests Validate functionality Test a single unit of code Avoid regressions Verify interfaces Test bugs dedicatedly Force code modularization Migrate safely Test driven development (TDD) Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 8 / 25
  • 25. Unit tests Validate functionality Test a single unit of code Avoid regressions Verify interfaces Test bugs dedicatedly Force code modularization Migrate safely Test driven development (TDD) Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 8 / 25
  • 26. Outline 1 Testing 2 PHPUnit Installation PHPUnit basics Code examples 3 Advanced scenarios (optional) 4 The end Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 9 / 25
  • 27. PHPUnit Port of JUnit to PHP Many enhancements Database tests Code coverage Data providers Invented by Sebastian Bergmann Standard for unit testing in PHP http://www.phpunit.de/ Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 10 / 25
  • 28. Installation Via PEAR $ pear channel-discover pear.phpunit.de $ pear install phpunit/PHPUnit Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 11 / 25
  • 29. PHPUnit basics YourClass Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 12 / 25
  • 30. PHPUnit basics YourClass YourClassTest Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 12 / 25
  • 31. PHPUnit basics YourClass YourClassTest Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 12 / 25
  • 32. PHPUnit basics TestCase YourClass YourClassTest Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 12 / 25
  • 33. PHPUnit basics TestRunner TestCase YourClass YourClassTest Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 12 / 25
  • 34. PHPUnit basics TestRunner TestCase YourClass YourClassTest Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 12 / 25
  • 35. Let’s dig into some code Let’s dig into some code Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 13 / 25
  • 36. Outline 1 Testing 2 PHPUnit 3 Advanced scenarios (optional) Custom test environment Testing a WebDAV server Testing graphic generation Testing parsers 4 The end Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 14 / 25
  • 37. eZ Component test runner Custom test runner Integrated auto loading Component base testing Run all tests Extended test case / suite classes Custom assertions Database testing Utility functions Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 15 / 25
  • 38. eZ Webdav component Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 16 / 25
  • 39. Semi-automatic regression tests Manual client test run Defined test receipe Capture request / response data Replay request in unit tests Detect response regressions Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 17 / 25
  • 40. Binary regressions Binary differences in generated images Test failures depending on PHP version GD version Operating system Images visually equivalent Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 18 / 25
  • 41. Custom assertions Custom assertion Custom equality constraint Based on ImageMagick Allows defined gap Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 19 / 25
  • 42. Untestable code Parsers are highly dependant De-coupling hardly possible Huge amount of mock objects Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 20 / 25
  • 43. Integration tests Test parser as a whole Small test files Manually create / validate Large overall tests Manual inspection of generated data Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 21 / 25
  • 44. Outline 1 Testing 2 PHPUnit 3 Advanced scenarios (optional) 4 The end Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 22 / 25
  • 45. Questions / Answers Questions? Feedback? Critics? Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 23 / 25
  • 46. The end I hope you enjoyed the session Slides and material http://schlitt.info/opensource http://www.slideshare.net/tobyS Contact: Tobias Schlitt <toby@php.net> Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 24 / 25
  • 47. PHPUnderControl Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 25 / 25