Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Towards a better plugin infrastructure #3002

Closed
sebastianbergmann opened this issue Feb 12, 2018 · 0 comments
Closed

Towards a better plugin infrastructure #3002

sebastianbergmann opened this issue Feb 12, 2018 · 0 comments
Assignees
Labels
type/enhancement A new idea that should be implemented
Milestone

Comments

@sebastianbergmann
Copy link
Owner

sebastianbergmann commented Feb 12, 2018

It should be easier to extend PHPUnit's test runner. More importantly, it should be possible to do so without abusing the TestListener interface.

In a first step, two hooks should be implemented: one that is triggered before the first test is executed and one that is triggered after the last test is executed. This is simple enough to implement and has been requested a couple of times over the years.

Another possible hook could be test filtering and ordering for #2660.

I currently envision the following:

namespace PHPUnit\Runner;

interface Hook
{
}
namespace PHPUnit\Runner;

interface BeforeFirstTestHook extends Hook
{
    public function executeBeforeFirstTest(): void;
}
namespace PHPUnit\Runner;

interface AfterLastTestHook extends Hook
{
    public function executeAfterLastTest(): void;
}

Following the Interface Segregation Principle, the idea here is to avoid one big interface and instead have one interface per extension point at which extensions can hook into PHPUnit's test runner.

Here is an example of an extension that uses the two hooks mentioned above:

namespace vendor;

use PHPUnit\Runner\AfterLastTestHook;
use PHPUnit\Runner\BeforeFirstTestHook;

final class MyExtension implements BeforeFirstTestHook, AfterLastTestHook
{
    public function executeAfterLastTest(): void
    {
        // ...
    }

    public function executeBeforeFirstTest(): void
    {
        // ...
    }
}

Here is how you configure PHPUnit's test runner to use that extension:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.1/phpunit.xsd">
    <extensions>
        <extension class="vendor\MyExtension"/>
    </extensions>
</phpunit>
@sebastianbergmann sebastianbergmann added the type/enhancement A new idea that should be implemented label Feb 12, 2018
@sebastianbergmann sebastianbergmann added this to the PHPUnit 7.1 milestone Feb 12, 2018
@sebastianbergmann sebastianbergmann self-assigned this Feb 12, 2018
sebastianbergmann added a commit that referenced this issue Feb 12, 2018
sebastianbergmann added a commit that referenced this issue Feb 13, 2018
sebastianbergmann added a commit that referenced this issue Feb 21, 2018
sebastianbergmann pushed a commit to sebastianbergmann/phpunit-documentation-english that referenced this issue Apr 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement A new idea that should be implemented
Projects
None yet
Development

No branches or pull requests

1 participant