• Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,327
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
15
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

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