Introduction and project setup
  • Introduction
  • Install PHP and Composer (Windows)
  • Install PHP and Composer (macOS)
  • Install PHP and Composer (Linux)
  • Create a project folder and install PHPUnit
Unit testing with PHPUnit: the basics
  • Write and run your first test: an introduction to assertions
  • Test a function: using multiple assertions
  • Test that incorrect results are not returned: using multiple test methods
  • Test a class: fixing bugs through testing
  • How to name your test methods
  • Unit testing with PHPUnit: the basics
  • Write your first PHPUnit test method
Configuring the PHPUnit test environment
  • The PHPUnit test runner: specify different options when running tests
  • Configure PHPUnit: the XML configuration file
  • Autoload classes being tested using Composer
  • Configuring the PHPUnit test environment
Test dependencies, fixtures and exceptions
  • Unit test a queue class
  • Test dependencies: make one test method dependent on another
  • Fixtures: set up the known state of the tests using setUp and tearDown
  • Easily add a new test method using the test fixture
  • Share fixtures between tests for resource-intensive data
  • Testing exceptions: expecting code to throw an exception
  • Test dependencies, fixtures and exceptions
  • Test fixtures
Test doubles: mocks and stubs
  • Test doubles: create mock objects to remove dependencies on external resources
  • Dependency injection: inject objects that a class depends on
  • Test object interactions: verify how a dependency is used
  • Customise the creation of the mock object: the getMockBuilder method
  • Test doubles: mocks and stubs
Mockery - an alternative mocking framework with a human-readable syntax
  • Mock a dependency that doesn't exist yet
  • Using Mockery: installation and integration with PHPUnit
  • Using Mockery to mock a dependency that doesn't exist yet
  • PHPUnit vs Mockery: Returning different values on subsequent method calls
  • Mockery Spies: Make assertions on a call after the event
Test-driven development
  • Test-driven development: set up a TDD project
  • Write the test first, then write the code to make it pass
  • Write just enough code to make the test pass
  • Add tests and refactor code until the tests pass
  • Add more tests and application code functionality
  • Another test, more functionality, and more refactoring
  • Data providers: provide a test method with a collection of data
Testing non-public methods and properties and abstract classes
  • Testing non-public methods
  • Testing protected methods using inheritance
  • Testing private methods using reflection
  • Testing private methods with arguments using reflection
  • Testing protected and private attributes
  • Testing abstract classes
Testing static methods
  • Testing static methods
  • The problem with static methods: dependencies and mocking
  • Option 1: Refactor code to remove the static method
  • Option 2: Pass the dependency as a callable
  • Option 3: Use Mockery alias mocks to stub the static method call
Conclusion
  • Conclusion
  • Bonus Lecture: discount PHP hosting