Skip to content

Commit

Permalink
Reorganize documentation for test runner extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jul 13, 2019
1 parent d2a7477 commit 2127399
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions src/extending-phpunit.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,8 @@ used as a matcher when configuring mock objects.
Extending the TestRunner
########################

PHPUnit |version| supports TestRunner extensions that can hook
into various events during the test execution.
See :ref:`appendixes.configuration.extensions` for details on how
to register extensions in PHPUnit's XML configuration.

Each available event that the extension can hook into is represented by an
interface that the extension needs to implement.
:ref:`extending-phpunit.hooks` lists the available events in
PHPUnit |version|.

.. _extending-phpunit.hooks:

Available Hook Interfaces
-------------------------
PHPUnit's test runner can be extended by registering objects that implement
one or more of the following interfaces:

- ``AfterIncompleteTestHook``
- ``AfterLastTestHook``
Expand All @@ -152,29 +140,34 @@ Available Hook Interfaces
- ``BeforeFirstTestHook``
- ``BeforeTestHook``

Each "hook", meaning each of the interfaces listed above, represents an event
that can occur while the tests are being executed.

See :ref:`appendixes.configuration.extensions` for details on how
to register extensions in PHPUnit's XML configuration.

:numref:`extending-phpunit.examples.TestRunnerExtension` shows an example
for an extension implementing ``BeforeFirstTestHook`` and ``AfterLastTestHook``:

.. code-block:: php
:caption: TestRunner Extension Example
:name: extending-phpunit.examples.TestRunnerExtension
<?php
<?php declare(strict_types=1);
namespace Vendor;
use PHPUnit\Runner\AfterLastTestHook;
use PHPUnit\Runner\BeforeFirstTestHook;
use PHPUnit\Runner\AfterLastTestHook;
final class MyExtension implements BeforeFirstTestHook, AfterLastTestHook
{
public function executeAfterLastTest(): void
public function executeBeforeFirstTest(): void
{
// called after the last test has been run
// called before the first test is being run
}
public function executeBeforeFirstTest(): void
public function executeAfterLastTest(): void
{
// called before the first test is being run
// called after the last test has been run
}
}

0 comments on commit 2127399

Please sign in to comment.