Skip to content

Commit

Permalink
Merge branch 'master' into extension-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkary committed Oct 17, 2022
2 parents 69e6ed0 + f1cc189 commit f808c37
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 18 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ Changes are required if you have extended SpeedTrapListener. See
* `phpunit.xml` requires registering using <extension> element instead of <listener> element. See README.
* Removed option `stopOnSlow` because Extensions can no longer manipulate the Test Runner

## 4.0 (xxxx-xx-xx)
## 4.0.1 (2022-10-16)

* New option `stopOnSlow` stops execution upon first slow test. Default: false.
* README documents working with Symfony Framework `simple-phpunit`

## 4.0.0 (2021-05-03)

* Changelog ([`v3.3.0...v.4.0.0`](https://github.com/johnkary/phpunit-speedtrap/compare/v3.3.0...v4.0.0))
* [PR #81](https://github.com/johnkary/phpunit-speedtrap/pull/81) Reformat slow test case output for compatibility with PHPUnit --filter option
* [PR #82](https://github.com/johnkary/phpunit-speedtrap/pull/82) New option `stopOnSlow` stops execution upon first slow test. Default: false.
* [PR #84](https://github.com/johnkary/phpunit-speedtrap/pull/84) New annotation option `@slowThreshold 0` disables checks for individual tests.

## 3.3.0 (2020-12-18)

Expand Down
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class SomeTestCase extends PHPUnit\Framework\TestCase
}
```

Setting `@slowThreshold 0` will never report that test as slow.

## Disable slowness profiling using an environment variable

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

## Using with Symfony Framework

**Executing `vendor/bin/simple-phpunit` will not work while PHPUnit SpeedTrap is installed.**
[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/`

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

[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/`
The easiest way to set environment variables for the script `simple-phpunit` is via phpunit.xml.dist:

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

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

## Development

Expand Down
9 changes: 1 addition & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
<!-- https://phpunit.readthedocs.io/en/stable/configuration.html -->
<phpunit
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation = "vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals = "false"
backupStaticAttributes = "false"
colors = "true"
convertErrorsToExceptions = "true"
convertNoticesToExceptions = "true"
convertWarningsToExceptions = "true"
processIsolation = "false"
stopOnFailure = "false"
bootstrap = "vendor/autoload.php">

<testsuites>
Expand Down
2 changes: 1 addition & 1 deletion src/SpeedTrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function executeAfterLastTest(): void
*/
protected function isSlow(int $time, int $slowThreshold): bool
{
return $time >= $slowThreshold;
return $slowThreshold && $time >= $slowThreshold;
}

/**
Expand Down
17 changes: 15 additions & 2 deletions tests/SomeSlowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public function testCanSetLowerSlowThreshold()

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

/**
* This test's runtime would normally be over the suite's threshold, but
* this annotation disables threshold checks causing it not to be
* considered slow and not reported in the test output.
*
* @slowThreshold 0
*/
public function testCanDisableSlowThreshold()
{
$this->extendTime(600);
$this->assertTrue(true);
}

/**
* @param int $ms Number of additional microseconds to execute code
*/
Expand Down

0 comments on commit f808c37

Please sign in to comment.