TDD in PHP - Memphis PHP 2011-08-25
Upcoming SlideShare
Loading in...5
×
 

TDD in PHP - Memphis PHP 2011-08-25

on

  • 1,319 views

 

Statistics

Views

Total Views
1,319
Views on SlideShare
1,319
Embed Views
0

Actions

Likes
1
Downloads
13
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

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.

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

TDD in PHP - Memphis PHP 2011-08-25 TDD in PHP - Memphis PHP 2011-08-25 Presentation Transcript

  • TDD in PHP: A Brief Example
  • About Me Jeremy Kendall PHP Developer since 2001 Organizer Memphis PHP Author at http://csiphp.com [email_address] @JeremyKendall http://about.me/jeremykendall
  • TDD in PHP: A Brief Example Test Driven Development, you say?
  • Frankly, my dear . . .
  • Frankly, my dear . . .
  • Why You Should Give A Damn
      ” 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
        • TutorCalculatorCalculatorInterface
        • TutorCalculatorIntegerCalculator
  • TDD: Live Code Example
    • Tutor class
      • Verifies correct responses
      • Uses calculator class(es) to test responses
      • Favors composition over inheritance
    • TutorMathTutor
      • _construct(CalculatorInterface $c)
  • 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 simple autoloaders
  • LET'S GET IT ON!
  • Resources
    • Test Driven Development at Wikipedia - http://bit.ly/9Aa3Xr
    • PHPUnit - http://www.phpunit.de/
    • Xdebug - http://www.xdebug.org/
    • 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
  • Resources
  • Resources s
  • Resources
  • Thanks!
      [email_address] @JeremyKendall http://about.me/jeremykendall