Skip to content

Commit f808c37

Browse files
committed
Merge branch 'master' into extension-upgrade
2 parents 69e6ed0 + f1cc189 commit f808c37

File tree

5 files changed

+42
-18
lines changed

5 files changed

+42
-18
lines changed

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,16 @@ Changes are required if you have extended SpeedTrapListener. See
2121
* `phpunit.xml` requires registering using <extension> element instead of <listener> element. See README.
2222
* Removed option `stopOnSlow` because Extensions can no longer manipulate the Test Runner
2323

24-
## 4.0 (xxxx-xx-xx)
24+
## 4.0.1 (2022-10-16)
2525

26-
* New option `stopOnSlow` stops execution upon first slow test. Default: false.
26+
* README documents working with Symfony Framework `simple-phpunit`
27+
28+
## 4.0.0 (2021-05-03)
29+
30+
* Changelog ([`v3.3.0...v.4.0.0`](https://github.com/johnkary/phpunit-speedtrap/compare/v3.3.0...v4.0.0))
31+
* [PR #81](https://github.com/johnkary/phpunit-speedtrap/pull/81) Reformat slow test case output for compatibility with PHPUnit --filter option
32+
* [PR #82](https://github.com/johnkary/phpunit-speedtrap/pull/82) New option `stopOnSlow` stops execution upon first slow test. Default: false.
33+
* [PR #84](https://github.com/johnkary/phpunit-speedtrap/pull/84) New annotation option `@slowThreshold 0` disables checks for individual tests.
2734

2835
## 3.3.0 (2020-12-18)
2936

README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ class SomeTestCase extends PHPUnit\Framework\TestCase
8181
}
8282
```
8383

84+
Setting `@slowThreshold 0` will never report that test as slow.
85+
8486
## Disable slowness profiling using an environment variable
8587

8688
SpeedTrap profiles for slow tests when enabled in phpunit.xml. But using an environment variable named `PHPUNIT_SPEEDTRAP` can enable or disable the extension:
@@ -176,15 +178,24 @@ $ PHPUNIT_SPEEDTRAP=enabled ./vendor/bin/phpunit
176178

177179
## Using with Symfony Framework
178180

179-
**Executing `vendor/bin/simple-phpunit` will not work while PHPUnit SpeedTrap is installed.**
181+
[Symfony Framework](https://symfony.com/) comes with package [symfony/phpunit-bridge](https://packagist.org/packages/symfony/phpunit-bridge) that installs its own version of PHPUnit and **ignores** what is defined in your project's composer.json or composer.lock file. See the PHPUnit versions it installs with command `ls vendor/bin/.phpunit/`
180182

181-
**Use the PHPUnit binary `vendor/bin/phpunit` while PHPUnit SpeedTrap is installed.**
183+
symfony/phpunit-bridge allows environment variable `SYMFONY_PHPUNIT_REQUIRE` to define additional dependencies while installing phpunit.
182184

183-
[Symfony Framework](https://symfony.com/) comes with package [symfony/phpunit-bridge](https://packagist.org/packages/symfony/phpunit-bridge) that installs its own version of PHPUnit and **ignores** what is defined in your project's composer.json or composer.lock file. See the PHPUnit versions it installs with command `ls vendor/bin/.phpunit/`
185+
The easiest way to set environment variables for the script `simple-phpunit` is via phpunit.xml.dist:
184186

185-
symfony/phpunit-bridge allows environment variable `SYMFONY_PHPUNIT_VERSION` to define the PHPUnit version it uses. However, this appears incompatible with PHPUnit SpeedTrap.
187+
phpunit.xml.dist
188+
```xml
189+
<phpunit bootstrap="vendor/autoload.php">
190+
<php>
191+
<env name="SYMFONY_PHPUNIT_REQUIRE" value="johnkary/phpunit-speedtrap:^4"/>
192+
<env name="SYMFONY_PHPUNIT_VERSION" value="9"/>
193+
</php>
194+
</phpunit>
195+
```
196+
(add the listener as described above)
186197

187-
Please submit a PR if you have a solution!
198+
Using the above example, running `vendor/bin/simple-phpunit` will now install the latest PHPUnit 9 and require the latest phpunit-speedtrap v4.
188199

189200
## Development
190201

phpunit.xml.dist

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
3+
<!-- https://phpunit.readthedocs.io/en/stable/configuration.html -->
44
<phpunit
55
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
66
xsi:noNamespaceSchemaLocation = "vendor/phpunit/phpunit/phpunit.xsd"
7-
backupGlobals = "false"
8-
backupStaticAttributes = "false"
97
colors = "true"
10-
convertErrorsToExceptions = "true"
11-
convertNoticesToExceptions = "true"
12-
convertWarningsToExceptions = "true"
13-
processIsolation = "false"
14-
stopOnFailure = "false"
158
bootstrap = "vendor/autoload.php">
169

1710
<testsuites>

src/SpeedTrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function executeAfterLastTest(): void
116116
*/
117117
protected function isSlow(int $time, int $slowThreshold): bool
118118
{
119-
return $time >= $slowThreshold;
119+
return $slowThreshold && $time >= $slowThreshold;
120120
}
121121

122122
/**

tests/SomeSlowTest.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public function testCanSetLowerSlowThreshold()
6666

6767
/**
6868
* This test's runtime would normally be over the suite's threshold, but
69-
* this annotation sets a higher threshold, causing it to be not be
70-
* considered slow and not reported on in the test output.
69+
* this annotation sets a higher threshold causing it not to be
70+
* considered slow and not reported in the test output.
7171
*
7272
* @slowThreshold 50000
7373
*/
@@ -77,6 +77,19 @@ public function testCanSetHigherSlowThreshold()
7777
$this->assertTrue(true);
7878
}
7979

80+
/**
81+
* This test's runtime would normally be over the suite's threshold, but
82+
* this annotation disables threshold checks causing it not to be
83+
* considered slow and not reported in the test output.
84+
*
85+
* @slowThreshold 0
86+
*/
87+
public function testCanDisableSlowThreshold()
88+
{
89+
$this->extendTime(600);
90+
$this->assertTrue(true);
91+
}
92+
8093
/**
8194
* @param int $ms Number of additional microseconds to execute code
8295
*/

0 commit comments

Comments
 (0)