TDD in PHP - A Brief Example (Nashville PHP 2010-10-12)

  • 3,108 views
Uploaded on

 

More in: Technology
  • 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
3,108
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
30
Comments
0
Likes
2

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 Contributor to FRAPI project (getfrapi.com) [email_address] @JeremyKendall http://jeremykendall.net
  • 3. TDD in PHP: A Brief Example Test Driven Development, you say?
  • 4. Frankly, my dear . . .
  • 5. Why You Should Give A Damn
      Test Driven Development is perhaps one of the best and fastest ways to improve your understanding and command of object-oriented principles and best practices. ” Good design is testable, and design that isn't testable is bad.” - Michael C. Feathers
  • 6. What is TDD?
    • From Wikipedia:
    • 7. ” Test Driven Development (TDD) is a software development process that relies on the repetition of a very short development cycle . . .”
  • 8. TDD Development Process
    • Write a test
    • 9. Run all tests, watch new test fail
    • 10. Write just enough code to make the test pass
    • 11. Run all tests, watch new test pass
    • 12. Lather, rinse, repeat . . .
    • 13. Refactor
  • 14. TDD: The Benefits
    • High cohesion, loose coupling
    • 15. Confidence
    • 16. Faster time to resolution
    • 17. Documentation
  • 18. TDD: The Drawbacks
    • Tests only cover what you think should be tested
    • 19. False sense of confidence
    • 20. Without management and team buy-in, TDD is DOA
  • 21. TDD: Live Code Example
      Live Coding? Really? Why?
  • 22. TDD: Live Code Example
    • Goals
      • Practical example of TDD in action
      • 23. Demonstrate refactoring with confidence
      • 24. Demonstrate TDD impact on design decisions
  • 25. TDD: Live Code Example
    • Code example will test a fictional math tutor application
      • Calculator class
      • 26. Tutor class (consumes calculator)
  • 27. TDD: Live Code Example
    • Calculator class
      • Adds one integer to another
      • 28. Throws exceptions in the following cases:
        • Non-integer arguments provided
        • 29. Integer overflow
        • 30. Integer underflow
      • Code to interface not implementation
        • Tutor_Calculator_Interface
        • 31. Tutor_Calculator_IntegerCalculator
  • 32. TDD: Live Code Example
    • Tutor class
      • Verifies correct responses
      • 33. Uses calculator class to test responses
      • 34. Favors composition over inheritance
      • 35. Tutor_MathTutor
  • 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 a simple autoloader
  • 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. Thanks!
      [email_address] @JeremyKendall http://jeremykendall.net