Unit testing with PHPUnit
Learn how to master unit tests and the test driven development methodology thanks to the PHPUnit framework.
This online training invites you to learn how to unit tests your code with the PHPUnit framework.
Coming sessions
Goals
In one day, you will learn how to install PHPUnit, write and execute your first unit tests suites thanks to the PHPUnit framework.
Program
Download the program as PDFIntroduction to unit test
- What are unit tests?
- Pros and cons
- The FIRST rule
Introduction to PHP Unit
- Introduction to PHP Unit
- Open Source PHP projects use PHP Unit
- IDEs integration
- PHPUnit installation from PEAR
- Lab: Install PHPUnit with PEAR
- Introduction to the Command Line Interface
- Write a first tests suite
- Run the test suite from the command line tool
- Lab: Write and run a PHPUnit tests suite from the command line
- Setup a tests suite with the
setup()method - Reset a testing environment with the
tearDown()method - Introduction to fixtures
- Lab: setup and reset a tests suite with
setup()andtearDown()methods - Write unit tests for methods, which can handle exceptions
- Testing exception with the
setExpectedException()assertion method - Testing exception by using the
@expectedExceptionannotation - Testing exception thanks to a
try { } catchcode block - Lab: implement unit tests for a method that can throw an exception
- Understanding the test driven development (TDD) methodology
- Main advantages of the TDD approach
- Implement code thanks to a test driven development approach
- Lab: fix and document a bug thanks to a TDD approach
- Understanding the data providers and fixtures concepts
- Create a new data provider method to run a test with several values
- Lab: implement a data provider method to test a method's edge cases
- Testing exceptions
- Using data providers to create fixtures
- Assertions to test a class and its attributes
- Assertions to test Boolean values
- Assertions to test string values
- Assertions to test XML values
- Understanding the code coverage concept
- Check XDebug extension is installed on the web server
- Generate a complete code coverage report from the command line interface
- Analyzing and understanding generated reports and statistics
- Understanding and using the special
@coversannotation - Ignore code blocks from coverage process thanks to
@codeCoverageIgnore(Start|End)annotation - Lab: Implement new methods and their tests to validate the code coverage rate
- Discovering and creating mock objects
- Test data model coupled to mock objects
- Check code coverage rate thanks to advanced unit tests
- Lab: implement mock objects to simulate real objects behaviors
- Export results as XML
- Export results as JSON
- Export results as TAP
- Check code coverage rate thanks to advanced unit tests
- Lab: export results as XML, JSON and TAP
- Discovering the continuous integration practice
- Installing and running a continuous integration tool
- Lab: install and running Jenkins CI
Write your first assertions
Initialize and reset a test
Testing exceptions
Test Driven Development
Data providers and fixtures
Advanced testing practices
Code coverage analysis
Using Mock objects
Generating reports
Monitoring the tests suite with Jenkins
Session details
Reference code
PHPUNITC1
Price
Starts at €590.00 (ex. tax)
Audience
Dévelopers
Duration
1 day (7 hours)
Training type
Workshop
Topics
TDD, unit testing, continuous integration, code coverage
Pre-requisites
Good knowledge of PHP
