TDD in PHP:  A Brief Example
About Me Jeremy Kendall PHP Developer since 2001 Organizer Memphis PHP Author at http://csiphp.com [email_address] @Jeremy...
TDD in PHP: A Brief Example Test Driven Development, you say?
Frankly, my dear . . .
Frankly, my dear . . .
Why You Should Give A Damn <ul>” Good design is testable, and design that isn't testable is bad.” – Michael C. Feathers </ul>
What is TDD? <ul><li>From Wikipedia:
” Test Driven Development (TDD)  is a software development process that relies on the repetition of a very short developme...
TDD Development Process <ul><li>Write a test
Run all tests, watch new test fail
Write just enough code to make the test pass
Run all tests, watch new test pass
Lather, rinse, repeat . . .
Refactor </li></ul>
TDD: The Benefits <ul><li>High cohesion, loose coupling
Confidence
Faster time to resolution
Documentation </li></ul>
TDD: The Drawbacks <ul><li>Tests only cover what you think should be tested
False sense of confidence
Without management and team buy-in, TDD is DOA </li></ul>
TDD: Live Code Example <ul>Live Coding?  Really?  Why? </ul>
Upcoming SlideShare
Loading in...5
×

TDD in PHP - Memphis PHP 2011-08-25

1,430

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,430
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
19
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "TDD in PHP - Memphis PHP 2011-08-25"

  1. 1. TDD in PHP: A Brief Example
  2. 2. About Me Jeremy Kendall PHP Developer since 2001 Organizer Memphis PHP Author at http://csiphp.com [email_address] @JeremyKendall http://about.me/jeremykendall
  3. 3. TDD in PHP: A Brief Example Test Driven Development, you say?
  4. 4. Frankly, my dear . . .
  5. 5. Frankly, my dear . . .
  6. 6. Why You Should Give A Damn <ul>” Good design is testable, and design that isn't testable is bad.” – Michael C. Feathers </ul>
  7. 7. What is TDD? <ul><li>From Wikipedia:
  8. 8. ” Test Driven Development (TDD) is a software development process that relies on the repetition of a very short development cycle . . .” </li></ul>
  9. 9. TDD Development Process <ul><li>Write a test
  10. 10. Run all tests, watch new test fail
  11. 11. Write just enough code to make the test pass
  12. 12. Run all tests, watch new test pass
  13. 13. Lather, rinse, repeat . . .
  14. 14. Refactor </li></ul>
  15. 15. TDD: The Benefits <ul><li>High cohesion, loose coupling
  16. 16. Confidence
  17. 17. Faster time to resolution
  18. 18. Documentation </li></ul>
  19. 19. TDD: The Drawbacks <ul><li>Tests only cover what you think should be tested
  20. 20. False sense of confidence
  21. 21. Without management and team buy-in, TDD is DOA </li></ul>
  22. 22. TDD: Live Code Example <ul>Live Coding? Really? Why? </ul>
  23. 23. TDD: Live Code Example <ul><li>Goals </li><ul><li>Practical example of TDD in action
  24. 24. Demonstrate refactoring with confidence
  25. 25. Demonstrate TDD impact on design decisions </li></ul></ul>
  26. 26. TDD: Live Code Example <ul><li>Code example will test a fictional math tutor application </li><ul><li>Calculator class
  27. 27. Tutor class (consumes calculator) </li></ul></ul>
  28. 28. TDD: Live Code Example <ul><li>Calculator class </li><ul><li>Adds one integer to another
  29. 29. Throws exceptions in the following cases: </li><ul><li>Non-integer arguments provided
  30. 30. Integer overflow
  31. 31. Integer underflow </li></ul><li>Code to interface not implementation </li><ul><li>TutorCalculatorCalculatorInterface
  32. 32. TutorCalculatorIntegerCalculator </li></ul></ul></ul>
  33. 33. TDD: Live Code Example <ul><li>Tutor class </li><ul><li>Verifies correct responses
  34. 34. Uses calculator class(es) to test responses
  35. 35. Favors composition over inheritance </li></ul><li>TutorMathTutor </li><ul><li>_construct(CalculatorInterface $c) </li></ul></ul>
  36. 36. TDD: Live Code Example <ul><li>We'll be using PHPUnit
  37. 37. PHPUnit will be configured with phpunit.xml
  38. 38. phpunit.xml: </li><ul><li>Calls bootstrap.php
  39. 39. Tells PHPUnit where to look for our tests
  40. 40. Code coverage and testdox reports </li></ul><li>bootstrap.php: </li><ul><li>Adds our library to the include path
  41. 41. Registers simple autoloaders </li></ul></ul>
  42. 42. LET'S GET IT ON!
  43. 43. Resources <ul><li>Test Driven Development at Wikipedia - http://bit.ly/9Aa3Xr
  44. 44. PHPUnit - http://www.phpunit.de/
  45. 45. Xdebug - http://www.xdebug.org/
  46. 46. The code example in this presentation was adapted for PHP from Przemysław Bielicki's TDD video tutorial at Agile Software Development. - http://bit.ly/byDZOA </li></ul>
  47. 47. Resources
  48. 48. Resources s
  49. 49. Resources
  50. 50. Thanks! <ul>[email_address] @JeremyKendall http://about.me/jeremykendall </ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×