TDD in PHP - A Brief Example (Nashville PHP 2010-10-12)
Upcoming SlideShare
Loading in...5

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






Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

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

  • TDD in PHP: A Brief Example
  • About Me Jeremy Kendall PHP Developer since 2001 Organizer Memphis PHP Contributor to FRAPI project ( [email_address] @JeremyKendall
  • TDD in PHP: A Brief Example Test Driven Development, you say?
  • Frankly, my dear . . .
  • 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
  • What is TDD?
    • From Wikipedia:
    • ” Test Driven Development (TDD) is a software development process that relies on the repetition of a very short development cycle . . .”
  • TDD Development Process
    • 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
  • TDD: The Benefits
    • High cohesion, loose coupling
    • Confidence
    • Faster time to resolution
    • Documentation
  • TDD: The Drawbacks
    • Tests only cover what you think should be tested
    • False sense of confidence
    • Without management and team buy-in, TDD is DOA
  • TDD: Live Code Example
      Live Coding? Really? Why?
  • TDD: Live Code Example
    • Goals
      • Practical example of TDD in action
      • Demonstrate refactoring with confidence
      • Demonstrate TDD impact on design decisions
  • TDD: Live Code Example
    • Code example will test a fictional math tutor application
      • Calculator class
      • Tutor class (consumes calculator)
  • TDD: Live Code Example
    • Calculator class
      • Adds one integer to another
      • Throws exceptions in the following cases:
        • Non-integer arguments provided
        • Integer overflow
        • Integer underflow
      • Code to interface not implementation
        • Tutor_Calculator_Interface
        • Tutor_Calculator_IntegerCalculator
  • TDD: Live Code Example
    • Tutor class
      • Verifies correct responses
      • Uses calculator class to test responses
      • Favors composition over inheritance
      • Tutor_MathTutor
  • TDD: Live Code Example
    • We'll be using PHPUnit
    • PHPUnit will be configured with phpunit.xml
    • phpunit.xml:
      • Calls bootstrap.php
      • Tells PHPUnit where to look for our tests
      • Code coverage and testdox reports
    • bootstrap.php:
      • Adds our library to the include path
      • Registers a simple autoloader
  • Resources
    • Test Driven Development at Wikipedia -
    • PHPUnit -
    • Xdebug -
    • The code example in this presentation was adapted for PHP from Przemysław Bielicki's TDD video tutorial at Agile Software Development. -
  • Thanks!
      [email_address] @JeremyKendall