Skip to content

Remove the deprecated PHPUnit_Extensions_TestDecorator part #28

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

Merged
merged 1 commit into from
Mar 15, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 0 additions & 62 deletions src/extending-phpunit.rst
Original file line number Diff line number Diff line change
Expand Up @@ -213,68 +213,6 @@ In :ref:`appendixes.configuration.test-listeners` you can see
how to configure PHPUnit to attach your test listener to the test
execution.

.. _extending-phpunit.PHPUnit_Extensions_TestDecorator:

Subclass PHPUnit_Extensions_TestDecorator
#########################################

You can wrap test cases or test suites in a subclass of
``PHPUnit_Extensions_TestDecorator`` and use the
Decorator design pattern to perform some actions before and after the
test runs.

PHPUnit ships with one concrete test decorator:
``PHPUnit_Extensions_RepeatedTest``. It is used to run a
test repeatedly and only count it as a success if all iterations are
successful.

:numref:`extending-phpunit.examples.RepeatedTest.php`
shows a cut-down version of the ``PHPUnit_Extensions_RepeatedTest``
test decorator that illustrates how to write your own test decorators.

.. code-block:: php
:caption: The RepeatedTest Decorator
:name: extending-phpunit.examples.RepeatedTest.php

<?php
use PHPUnit\Framework\TestCase;

require_once 'PHPUnit/Extensions/TestDecorator.php';

class PHPUnit_Extensions_RepeatedTest extends PHPUnit_Extensions_TestDecorator
{
private $timesRepeat = 1;

public function __construct(PHPUnit\Framework\Test $test, $timesRepeat = 1)
{
parent::__construct($test);

if (is_integer($timesRepeat) &&
$timesRepeat >= 0) {
$this->timesRepeat = $timesRepeat;
}
}

public function count()
{
return $this->timesRepeat * $this->test->count();
}

public function run(PHPUnit\Framework\TestResult $result = null)
{
if ($result === null) {
$result = $this->createResult();
}

for ($i = 0; $i < $this->timesRepeat && !$result->shouldStop(); $i++) {
$this->test->run($result);
}

return $result;
}
}
?>

.. _extending-phpunit.PHPUnit_Framework_Test:

Implement PHPUnit\Framework\Test
Expand Down