Cover image for PHPUnit Pocket Guide

Book Description

Smart web developers will tell you that the sooner you detect your code mistakes, the quicker you can fix them, and the less the project will cost in the long run. Well, the most efficient way to detect your mistakes in PHP is with PHPUnit, an open source framework that automates unit testing by running a battery of tests as you go. The benefits of PHPUnit are significant:

  • a reduction in the effort required to frequently test code

  • fewer overall defects

  • added confidence in your code

  • improved relations with your open source teammates

  • The only problem with this popular testing tool was its lack of documentation-until now, that is. For this, O'Reilly went right to the source, as Sebastian Bergmann, the author of PHPUnit Pocket Guide, also happens to be PHPUnit's creator. This little book brings together hard-to-remember information, syntax, and rules for working with PHPUnit. It also delivers the insight and sage advice that can only come from the technology's creator. Coverage of testing under agile methodologies and Extreme Programming (XP) is also included.

    The latest in O'Reilly's series of handy Pocket Guides, this quick-reference book puts all the answers are right at your fingertips. It's an invaluable companion for anyone interested in testing the PHP code they write for web applications.

    Table of Contents

    1. PHPUnit Pocket Guide
      1. SPECIAL OFFER: Upgrade this ebook with O’Reilly
      2. Copyright
      3. 1. Introduction
        1. 1.1. Requirements
        2. 1.2. This Book Is Free
        3. 1.3. Conventions Used in This Book
        4. 1.4. How to Contact Us
        5. 1.5. Acknowledgments
      4. 2. Automating Tests
      5. 3. PHPUnit's Goals
      6. 4. Installing PHPUnit
      7. 5. The Command-Line Test Runner
      8. 6. Fixtures
        1. 6-1. More setUp( ) than tearDown( )
        2. 6-2. Variations
        3. 6-3. Suite-Level Setup
      9. 7. Testing Exceptions and Performance Regressions
        1. 7-1. Exceptions
        2. 7-2. Performance Regressions
      10. 8. Incomplete Tests
      11. 9. Test-First Programming
        1. 9-1. BankAccount Example
      12. 10. Code-Coverage Analysis
      13. 11. Stubs
        1. 11-1. Self-Shunting
      14. 12. Other Uses for Tests
        1. 12-1. Agile Documentation
        2. 12-2. Cross-Team Tests
        3. 12-3. Debugging Tests
        4. 12-4. Refactoring
      15. 13. PHPUnit and Phing
        1. 13-1. Formatting Feedback
      16. 14. PHPUnit's Implementation
      17. 15. PHPUnit API
        1. 15-1. Overview
        2. 15-2. PHPUnit2_Framework_Assert
        3. 15-3. PHPUnit2_Framework_Test
        4. 15-4. PHPUnit2_Framework_TestCase
        5. 15-5. PHPUnit2_Framework_TestSuite
        6. 15-6. PHPUnit2_Framework_TestResult
        7. 15-7. Package Structure
      18. 16. Extending PHPUnit
        1. 16-1. Subclass PHPUnit2_Framework_TestCase
        2. 16-2. Assert Classes
        3. 16-3. Subclass PHPUnit2_Extensions_TestDecorator
        4. 16-4. Implement PHPUnit2_Framework_Test
        5. 16-5. Subclass PHPUnit2_Framework_TestResult
        6. 16-6. Implement PHPUnit2_Framework_TestListener
        7. 16-7. New Test Runner
      19. 17. PHPUnit for PHP 4
      20. 18. Bibliography
      21. Index
      22. About the Author
      23. SPECIAL OFFER: Upgrade this ebook with O’Reilly