Skip to content

Commit 9623417

Browse files
committed
chore: add PHPUnit 8 support
1 parent 30932b9 commit 9623417

File tree

4 files changed

+34
-23
lines changed

4 files changed

+34
-23
lines changed

README.md

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,12 @@
11
# PHPUnit Extra
22

33
PHPUnit Extra provides a PHPUnit listener to improve performance of your
4-
PHPUnit test suites by cleaning up classes variables at the end of each
4+
PHPUnit test suites by cleaning up classes variables at the end of each
55
TestCase. Thanks [Kris Wallsmith for this tip](http://kriswallsmith.net/post/18029585104/faster-phpunit).
66

77
## Installation
88

9-
### Step 1: Make sure composer knows how to access the library
10-
11-
Add the path to the private repository in your `composer.json`:
12-
13-
```json
14-
"repositories": [
15-
{
16-
"type": "vcs",
17-
"url": "https://github.com/theodo/phpunit-extra"
18-
}
19-
]
20-
```
21-
22-
### Step 2: Install the library
9+
### Step 1: Install the library
2310

2411
Open a command console, enter your project directory and execute the
2512
following command to download the latest stable version of this bundle:
@@ -32,15 +19,20 @@ This command requires you to have Composer installed globally, as explained
3219
in the [installation chapter](https://getcomposer.org/doc/00-intro.md)
3320
of the Composer documentation.
3421

35-
Github will ask you to create a token and to paste it so that it can
36-
download the private Github repository.
22+
### Step 2: Configure the listener in PHPUnit
3723

38-
### Step 3: Configure the listener in PHPUnit
24+
For PHPUnit >= 7.5, add the extension in your XML config file (e.g. `phpunit.xml.dist`).
25+
26+
```xml
27+
<extensions>
28+
<extension class="\Theodo\PHPUnitExtra\PHPUnit\PHPUnitExtension" />
29+
</extensions>
30+
```
3931

40-
Add a listener in your `phpunit.xml.dist`.
32+
For PHPUnit < 7.5 add the listener in your XML config file (e.g. `phpunit.xml.dist`).
4133

4234
```xml
4335
<listeners>
44-
<listener class="\Theodo\PHPUnitExtra\PHPUnitListener\PHPUnitListener" />
36+
<listener class="\Theodo\PHPUnitExtra\PHPUnit\PHPUnitListener" />
4537
</listeners>
4638
```

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "theodo/phpunit-extra",
3-
"description": "PHP library improve PHPUnit test performance",
3+
"description": "PHP library which improves PHPUnit test suite performance",
44
"type": "library",
55
"keywords": ["tests", "phpunit", "performance", "clean up", "symfony", "functional tests"],
66
"license": "MIT",

src/PHPUnit/PHPUnitExtension.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Theodo\PHPUnitExtra\PHPUnit;
6+
7+
class PHPUnitExtension implements \PHPUnit\Runner\AfterTestHook
8+
{
9+
public function executeAfterTest(string $test, float $time): void
10+
{
11+
$reflectionObject = new \ReflectionObject($test);
12+
foreach ($reflectionObject->getProperties() as $prop) {
13+
if (!$prop->isStatic() && 0 !== strpos($prop->getDeclaringClass()->getName(), 'PHPUnit_')) {
14+
$prop->setAccessible(true);
15+
$prop->setValue($test, null);
16+
}
17+
};
18+
}
19+
20+
}

src/PHPUnitListener/PHPUnitListener.php renamed to src/PHPUnit/PHPUnitListener.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Theodo\PHPUnitExtra\PHPUnitListener;
5+
namespace Theodo\PHPUnitExtra\PHPUnit;
66

77
class PHPUnitListener implements \PHPUnit\Framework\TestListener
88
{
@@ -18,5 +18,4 @@ public function endTest(\PHPUnit\Framework\Test $test, float $timer): void
1818
}
1919
};
2020
}
21-
2221
}

0 commit comments

Comments
 (0)