Onsite training

Bring our trainers team onsite to train your employees.

Learn more


Best practices

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


No session is currently scheduled.

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 PDF

Introduction 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
    • Write your first assertions

      • 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

      Initialize and reset a test

      • 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() and tearDown() methods

      Testing exceptions

      • Write unit tests for methods, which can handle exceptions
      • Testing exception with the setExpectedException() assertion method
      • Testing exception by using the @expectedException annotation
      • Testing exception thanks to a try { } catch code block
      • Lab: implement unit tests for a method that can throw an exception

      Test Driven Development

      • 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

      Data providers and fixtures

      • 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

      Advanced testing practices

      • 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

      Code coverage analysis

      • 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 @covers annotation
      • 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
        • Using Mock objects

          • 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

          Generating reports

          • 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

          Monitoring the tests suite with Jenkins

          • Discovering the continuous integration practice
          • Installing and running a continuous integration tool
          • Lab: install and running Jenkins CI

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


For further information

We remain at your disposal for further information.

Contact us