eBook - PHPUnit Explained

What you will learn:

  • Setting up a PHP CLI environment
  • Setting up PHPUnit
  • Writing and executing tests
  • Analysing test results
  • Writing testable code
  • Writing understandable tests

Had a great time (re)structuring the @phpunitbook together with @spriebsch. https://phpunitexplained.com/ This eBook will be amazing!

Sebastian Bergmann (@s_bergmann)

Table of Contents (Work in Progress)

  • Preface
  • Introduction
  • Getting Ready
    • PHP on the CLI
    • Installing PHPUnit
    • Global Installation
    • Your First Test
  • The Right Mindset
    • Short-Term Benefits of Testing
    • Long-Term Benefits of Testing
    • Without tests, how do you know you completed a task?
    • Do I have to write tests first?
    • How do I let tests drive the development?
  • Behind the Scenes
    • How PHPUnit runs your tests
    • How you should organize your tests
    • Why test isolation is important
  • Getting Started
    • Configuration
    • Running Tests
    • Testing Return Values
    • Assertions
  • Understanding Test Results
    • PhpStorm Integration
    • How to Fix Failing Tests
    • Errors versus Failures
    • Beyond Errors and Failures
  • Expecting the Unexpected
    • Testing Exceptions
  • Clean Tests
    • Readable Test Code
    • Meaningful Test Names
    • PHPUnit's TestDox Format
    • Tests as Specification
    • Tests as Documentation
    • Managing Test Fixture
  • Living with Legacy
    • Testing Procedural Code
    • Testing Code That Is Not Even Procedural
    • Dealing with Global State
    • Testing Output
    • Testing Headers
    • Testing Errors
    • Testing Database Interaction
    • Testing Web Services
    • Testing the User Interface
  • Dealing with Dependencies
    • Stubs
  • Clean Code
    • What makes code testable?
    • Using adapters for PHP built-in functions
    • Using adapters for 3rd-party code
    • Testing Time
  • Object Collaboration
    • Spies
    • Mocks
  • Isolation Trade-Offs
    • Test Dependencies
  • Testing by Example
    • Data Provider
  • Managing Risks
    • Code Coverage
    • Risky Tests
  • Continuous Integration
    • JUnit XML
    • Clover XML
    • Build Automation
  • The Big Picture
    • Acceptance Tests
    • Integration Tests
    • Characterization Tests
    • Grouping Tests
    • Alternatives to PHPUnit
  • Customizing PHPUnit
    • Comparator
    • Assertion
    • Test Listener
    • Result Printer
    • Test Runner Extension
  • The PHPUnit Project
    • Release Cycle
    • Updating
    • Contributing
  • The Story of Unit Testing
    • From SUnit via JUnit to PHPUnit