Skip to content

Commit

Permalink
Closes #3002
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Feb 21, 2018
1 parent 9610800 commit 41c7584
Show file tree
Hide file tree
Showing 22 changed files with 585 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ChangeLog-7.1.md
Expand Up @@ -4,6 +4,10 @@ All notable changes of the PHPUnit 7.1 release series are documented in this fil

## [7.1.0] - 2018-04-06

### Added

* Implemented [#3002](https://github.com/sebastianbergmann/phpunit/issues/3002): Support for test runner extensions

### Changed

* `PHPUnit\Framework\Assert` is no longer searched for test methods
Expand Down
6 changes: 6 additions & 0 deletions phpunit.xsd
Expand Up @@ -50,6 +50,11 @@
<xs:element name="group" type="xs:string" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="extensionsType">
<xs:sequence>
<xs:element name="extension" type="objectType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="listenersType">
<xs:sequence>
<xs:element name="listener" type="objectType" maxOccurs="unbounded"/>
Expand Down Expand Up @@ -248,6 +253,7 @@
<xs:element name="testdoxGroups" type="groupsType" minOccurs="0"/>
<xs:element name="filter" type="filtersType" minOccurs="0"/>
<xs:element name="logging" type="loggersType" minOccurs="0"/>
<xs:element name="extensions" type="extensionsType" minOccurs="0"/>
<xs:element name="listeners" type="listenersType" minOccurs="0"/>
<xs:element name="php" type="phpType" minOccurs="0"/>
</xs:all>
Expand Down
16 changes: 16 additions & 0 deletions src/Runner/Hook/AfterIncompleteTestHook.php
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PHPUnit\Runner;

interface AfterIncompleteTestHook extends TestHook
{
public function executeAfterIncompleteTest(string $test, string $message, float $time): void;
}
16 changes: 16 additions & 0 deletions src/Runner/Hook/AfterLastTestHook.php
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PHPUnit\Runner;

interface AfterLastTestHook extends Hook
{
public function executeAfterLastTest(): void;
}
16 changes: 16 additions & 0 deletions src/Runner/Hook/AfterRiskyTestHook.php
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PHPUnit\Runner;

interface AfterRiskyTestHook extends TestHook
{
public function executeAfterRiskyTest(string $test, string $message, float $time): void;
}
16 changes: 16 additions & 0 deletions src/Runner/Hook/AfterSkippedTestHook.php
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PHPUnit\Runner;

interface AfterSkippedTestHook extends TestHook
{
public function executeAfterSkippedTest(string $test, string $message, float $time): void;
}
16 changes: 16 additions & 0 deletions src/Runner/Hook/AfterSuccessfulTestHook.php
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PHPUnit\Runner;

interface AfterSuccessfulTestHook extends TestHook
{
public function executeAfterSuccessfulTest(string $test, float $time): void;
}
16 changes: 16 additions & 0 deletions src/Runner/Hook/AfterTestErrorHook.php
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PHPUnit\Runner;

interface AfterTestErrorHook extends TestHook
{
public function executeAfterTestError(string $test, string $message, float $time): void;
}
16 changes: 16 additions & 0 deletions src/Runner/Hook/AfterTestFailureHook.php
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PHPUnit\Runner;

interface AfterTestFailureHook extends TestHook
{
public function executeAfterTestFailure(string $test, string $message, float $time): void;
}
16 changes: 16 additions & 0 deletions src/Runner/Hook/AfterTestWarningHook.php
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PHPUnit\Runner;

interface AfterTestWarningHook extends TestHook
{
public function executeAfterTestWarning(string $test, string $message, float $time): void;
}
16 changes: 16 additions & 0 deletions src/Runner/Hook/BeforeFirstTestHook.php
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PHPUnit\Runner;

interface BeforeFirstTestHook extends Hook
{
public function executeBeforeFirstTest(): void;
}
16 changes: 16 additions & 0 deletions src/Runner/Hook/BeforeTestHook.php
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PHPUnit\Runner;

interface BeforeTestHook extends TestHook
{
public function executeBeforeTest(string $test): void;
}
15 changes: 15 additions & 0 deletions src/Runner/Hook/Hook.php
@@ -0,0 +1,15 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PHPUnit\Runner;

interface Hook
{
}
15 changes: 15 additions & 0 deletions src/Runner/Hook/TestHook.php
@@ -0,0 +1,15 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PHPUnit\Runner;

interface TestHook extends Hook
{
}
134 changes: 134 additions & 0 deletions src/Runner/Hook/TestListenerAdapter.php
@@ -0,0 +1,134 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PHPUnit\Runner;

use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestListener;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Framework\Warning;
use PHPUnit\Util\Test as TestUtil;

final class TestListenerAdapter implements TestListener
{
/**
* @var TestHook[]
*/
private $hooks = [];

/**
* @var bool
*/
private $lastTestWasNotSuccessful;

public function add(TestHook $hook): void
{
$this->hooks[] = $hook;
}

public function startTest(Test $test): void
{
foreach ($this->hooks as $hook) {
if ($hook instanceof BeforeTestHook) {
$hook->executeBeforeTest(TestUtil::describeAsString($test));
}
}

$this->lastTestWasNotSuccessful = false;
}

public function addError(Test $test, \Throwable $t, float $time): void
{
foreach ($this->hooks as $hook) {
if ($hook instanceof AfterTestErrorHook) {
$hook->executeAfterTestError(TestUtil::describeAsString($test), $t->getMessage(), $time);
}
}

$this->lastTestWasNotSuccessful = true;
}

public function addWarning(Test $test, Warning $e, float $time): void
{
foreach ($this->hooks as $hook) {
if ($hook instanceof AfterTestWarningHook) {
$hook->executeAfterTestWarning(TestUtil::describeAsString($test), $e->getMessage(), $time);
}
}

$this->lastTestWasNotSuccessful = true;
}

public function addFailure(Test $test, AssertionFailedError $e, float $time): void
{
foreach ($this->hooks as $hook) {
if ($hook instanceof AfterTestFailureHook) {
$hook->executeAfterTestFailure(TestUtil::describeAsString($test), $e->getMessage(), $time);
}
}

$this->lastTestWasNotSuccessful = true;
}

public function addIncompleteTest(Test $test, \Throwable $t, float $time): void
{
foreach ($this->hooks as $hook) {
if ($hook instanceof AfterIncompleteTestHook) {
$hook->executeAfterIncompleteTest(TestUtil::describeAsString($test), $t->getMessage(), $time);
}
}

$this->lastTestWasNotSuccessful = true;
}

public function addRiskyTest(Test $test, \Throwable $t, float $time): void
{
foreach ($this->hooks as $hook) {
if ($hook instanceof AfterRiskyTestHook) {
$hook->executeAfterRiskyTest(TestUtil::describeAsString($test), $t->getMessage(), $time);
}
}

$this->lastTestWasNotSuccessful = true;
}

public function addSkippedTest(Test $test, \Throwable $t, float $time): void
{
foreach ($this->hooks as $hook) {
if ($hook instanceof AfterSkippedTestHook) {
$hook->executeAfterSkippedTest(TestUtil::describeAsString($test), $t->getMessage(), $time);
}
}

$this->lastTestWasNotSuccessful = true;
}

public function endTest(Test $test, float $time): void
{
if ($this->lastTestWasNotSuccessful === true) {
return;
}

foreach ($this->hooks as $hook) {
if ($hook instanceof AfterSuccessfulTestHook) {
$hook->executeAfterSuccessfulTest(TestUtil::describeAsString($test), $time);
}
}
}

public function startTestSuite(TestSuite $suite): void
{
}

public function endTestSuite(TestSuite $suite): void
{
}
}

0 comments on commit 41c7584

Please sign in to comment.