diff --git a/.github/settings.yml b/.github/settings.yml index 5a160c8e..2216b7bf 100644 --- a/.github/settings.yml +++ b/.github/settings.yml @@ -21,6 +21,14 @@ branches: - context: "Refactoring (7.4, locked)" - context: "Security Analysis (7.4, locked)" - context: "Static Code Analysis (7.4, locked)" + - context: "Tests (6.5.0, 7.1, highest)" + - context: "Tests (6.5.0, 7.1, lowest)" + - context: "Tests (6.5.0, 7.2, highest)" + - context: "Tests (6.5.0, 7.2, lowest)" + - context: "Tests (6.5.0, 7.3, highest)" + - context: "Tests (6.5.0, 7.3, lowest)" + - context: "Tests (6.5.0, 7.4, highest)" + - context: "Tests (6.5.0, 7.4, lowest)" - context: "Tests (7.5.0, 7.1, highest)" - context: "Tests (7.5.0, 7.1, lowest)" - context: "Tests (7.5.0, 7.2, highest)" diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml index 538ae3e0..8cfd424e 100644 --- a/.github/workflows/integrate.yaml +++ b/.github/workflows/integrate.yaml @@ -457,7 +457,7 @@ jobs: fail-fast: false matrix: phpunit-version: - - "7.5.0" + - "6.5.0" php-version: - "7.1" @@ -470,6 +470,38 @@ jobs: - "highest" include: + - phpunit-version: "7.5.0" + php-version: "7.1" + dependencies: "lowest" + + - phpunit-version: "7.5.0" + php-version: "7.1" + dependencies: "highest" + + - phpunit-version: "7.5.0" + php-version: "7.2" + dependencies: "lowest" + + - phpunit-version: "7.5.0" + php-version: "7.2" + dependencies: "highest" + + - phpunit-version: "7.5.0" + php-version: "7.3" + dependencies: "lowest" + + - phpunit-version: "7.5.0" + php-version: "7.3" + dependencies: "highest" + + - phpunit-version: "7.5.0" + php-version: "7.4" + dependencies: "lowest" + + - phpunit-version: "7.5.0" + php-version: "7.4" + dependencies: "highest" + - phpunit-version: "8.5.19" php-version: "7.2" dependencies: "lowest" @@ -675,6 +707,10 @@ jobs: wget -O gh-4486.patch https://github.com/sebastianbergmann/phpunit/commit/0a488f22925b3c8732338ef0fbfe7f13cb4cf1d2.patch patch -p1 < gh-4486.patch + - name: "Run end-to-end tests with phpunit/phpunit:6.5.0" + if: "matrix.phpunit-version == '6.5.0'" + run: "vendor/bin/phpunit --colors=always --configuration=test/EndToEnd/Version06/phpunit.xml" + - name: "Run end-to-end tests with phpunit/phpunit:7.5.0" if: "matrix.phpunit-version == '7.5.0'" run: "vendor/bin/phpunit --colors=always --configuration=test/EndToEnd/Version07/phpunit.xml" diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 846083a3..83ce546d 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -30,6 +30,7 @@ ->withHeader($license->header()) ->withRules(PhpCsFixer\Config\Rules::fromArray([ 'mb_str_functions' => false, + 'void_return' => false, ])); $config = PhpCsFixer\Config\Factory::fromRuleSet($ruleSet); diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a1a1f1d..680f61c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), For a full diff see [`2.13.0...main`][2.13.0...main]. +### Changed + +- Added support for `phpunit/phpunit:^6.5.0` ([#533]), by [@localheinz] + ## [`2.13.0`][2.13.0] For a full diff see [`2.12.0...2.13.0`][2.12.0...2.13.0]. @@ -313,6 +317,7 @@ For a full diff see [`7afa59c...1.0.0`][7afa59c...1.0.0]. [#495]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/495 [#531]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/531 [#532]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/532 +[#533]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/533 [@HypeMC]: https://github.com/HypeMC [@localheinz]: https://github.com/localheinz diff --git a/README.md b/README.md index 60bb12fd..f2748aa4 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ This project provides a [`composer`](https://getcomposer.org) package and a [Pha The extension is compatible with the following versions of `phpunit/phpunit`: +- [`phpunit/phpunit:^6.5.0`](https://github.com/sebastianbergmann/phpunit/tree/6.5.0) - [`phpunit/phpunit:^7.5.0`](https://github.com/sebastianbergmann/phpunit/tree/7.5.0) - [`phpunit/phpunit:^8.5.19`](https://github.com/sebastianbergmann/phpunit/tree/8.5.19) - [`phpunit/phpunit:^9.0.0`](https://github.com/sebastianbergmann/phpunit/tree/9.0.0) @@ -48,6 +49,31 @@ Before the extension can detect slow tests in `phpunit/phpunit`, you need to boo To bootstrap the extension as a `composer` package when using +- `phpunit/phpunit:^6.5.0` + +adjust your `phpunit.xml` configuration file and configure the + +- [`listeners` element](https://phpunit.de/manual/6.5/en/appendixes.configuration.html#appendixes.configuration.test-listeners) on [`phpunit/phpunit:^6.5.0`](https://phpunit.de/manual/6.5/en/) + +```diff + ++ ++ ++ + + + test/Unit/ + + + +``` + +To bootstrap the extension as a `composer` package when using + - `phpunit/phpunit:^7.5.0` - `phpunit/phpunit:^8.5.19` - `phpunit/phpunit:^9.0.0` @@ -175,6 +201,45 @@ The configuration mechanism depends on the version of `phpunit/phpunit` you are To configure the extension when using +- `phpunit/phpunit:^6.5.0` + +adjust your `phpunit.xml` configuration file and configure the + +- [`arguments` element](https://phpunit.de/manual/6.5/en/appendixes.configuration.html#appendixes.configuration.test-listeners) on [`phpunit/phpunit:^6.5.0`](https://phpunit.de/manual/6.5/en/) + +The following example configures the maximum count of slow tests to three, and the maximum duration for all tests to 250 milliseconds: + +```diff + + +- ++ ++ ++ ++ ++ 3 ++ ++ ++ 250 ++ ++ ++ ++ + + + + test/Unit/ + + + +``` + +To configure the extension when using + - `phpunit/phpunit:^7.5.0` - `phpunit/phpunit:^8.5.19` - `phpunit/phpunit:^9.0.0` @@ -257,10 +322,12 @@ You can configure the maximum duration for a single test case with - `phpunit/phpunit:^10.0.0` - `phpunit/phpunit:^11.0.0` - a `@maximumDuration` annotation in the DocBlock when using + - `phpunit/phpunit:^6.5.0` - `phpunit/phpunit:^7.5.0` - `phpunit/phpunit:^8.5.19` - `phpunit/phpunit:^9.0.0` - a `@slowThreshold` annotation in the DocBlock when using + - `phpunit/phpunit:^6.5.0` - `phpunit/phpunit:^7.5.0` - `phpunit/phpunit:^8.5.19` - `phpunit/phpunit:^9.0.0` @@ -350,6 +417,7 @@ OK (13 tests, 13 assertions) When using +- `phpunit/phpunit:^6.5.0` - `phpunit/phpunit:^7.5.0` - `phpunit/phpunit:^8.5.19` - `phpunit/phpunit:^9.0.0` diff --git a/psalm-baseline.xml b/psalm-baseline.xml index aa90aa56..83f29a84 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -3,6 +3,7 @@ + @@ -105,6 +106,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Extension.php b/src/Extension.php index 3a3973a0..5f0c68a3 100644 --- a/src/Extension.php +++ b/src/Extension.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPUnit\SlowTestDetector; +use PHPUnit\Framework; use PHPUnit\Runner; use PHPUnit\TextUI; use PHPUnit\Util; @@ -26,6 +27,204 @@ )); } +if ($phpUnitVersionSeries->major()->equals(Version\Major::fromInt(6))) { + final class Extension implements Framework\TestListener + { + /** + * @var int + */ + private $suites = 0; + + /** + * @var Duration + */ + private $maximumDuration; + + /** + * @var Collector\Collector + */ + private $collector; + + /** + * @var Reporter\Reporter + */ + private $reporter; + + public function __construct(array $options = []) + { + $maximumCount = Count::fromInt(10); + + if (\array_key_exists('maximum-count', $options)) { + $maximumCount = Count::fromInt((int) $options['maximum-count']); + } + + $maximumDuration = Duration::fromMilliseconds(500); + + if (\array_key_exists('maximum-duration', $options)) { + $maximumDuration = Duration::fromMilliseconds((int) $options['maximum-duration']); + } + + $this->maximumDuration = $maximumDuration; + $this->collector = new Collector\DefaultCollector(); + $this->reporter = new Reporter\DefaultReporter( + new Formatter\DefaultDurationFormatter(), + $maximumDuration, + $maximumCount + ); + } + + public function addError( + Framework\Test $test, + \Exception $e, + $time + ) { + } + + public function addWarning( + Framework\Test $test, + Framework\Warning $e, + $time + ) { + } + + public function addFailure( + Framework\Test $test, + Framework\AssertionFailedError $e, + $time + ) { + } + + public function addIncompleteTest( + Framework\Test $test, + \Exception $e, + $time + ) { + } + + public function addRiskyTest( + Framework\Test $test, + \Exception $e, + $time + ) { + } + + public function addSkippedTest( + Framework\Test $test, + \Exception $e, + $time + ) { + } + + public function startTestSuite(Framework\TestSuite $suite) + { + ++$this->suites; + } + + public function endTestSuite(Framework\TestSuite $suite) + { + --$this->suites; + + if (0 < $this->suites) { + return; + } + + $slowTests = $this->collector->collected(); + + if ([] === $slowTests) { + return; + } + + $report = $this->reporter->report(...$slowTests); + + if ('' === $report) { + return; + } + + echo <<resolveMaximumDuration($test); + + if (!$duration->isGreaterThan($maximumDuration)) { + return; + } + + $testIdentifier = TestIdentifier::fromString(\sprintf( + '%s::%s', + \get_class($test), + $test->getName() + )); + + $slowTest = SlowTest::create( + $testIdentifier, + $duration, + $maximumDuration + ); + + $this->collector->collect($slowTest); + } + + private function resolveMaximumDuration(Framework\Test $test): Duration + { + $annotations = [ + 'maximumDuration', + 'slowThreshold', + ]; + + $symbolAnnotations = Util\Test::parseTestMethodAnnotations( + \get_class($test), + $test->getName(false) + ); + + foreach ($annotations as $annotation) { + if (!\is_array($symbolAnnotations['method'])) { + continue; + } + + if (!\array_key_exists($annotation, $symbolAnnotations['method'])) { + continue; + } + + if (!\is_array($symbolAnnotations['method'][$annotation])) { + continue; + } + + $maximumDuration = \reset($symbolAnnotations['method'][$annotation]); + + if (1 !== \preg_match('/^\d+$/', $maximumDuration)) { + continue; + } + + return Duration::fromMilliseconds((int) $maximumDuration); + } + + return $this->maximumDuration; + } + } + + return; +} + if ($phpUnitVersionSeries->major()->isOneOf(Version\Major::fromInt(7), Version\Major::fromInt(8), Version\Major::fromInt(9))) { /** * @internal diff --git a/test/EndToEnd/Version06/Configuration/Defaults/SleeperTest.php b/test/EndToEnd/Version06/Configuration/Defaults/SleeperTest.php new file mode 100644 index 00000000..b32d19f4 --- /dev/null +++ b/test/EndToEnd/Version06/Configuration/Defaults/SleeperTest.php @@ -0,0 +1,64 @@ +sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @dataProvider provideMillisecondsGreaterThanDefaultMaximumDuration + */ + public function testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider(int $milliseconds): void + { + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @return \Generator + */ + public static function provideMillisecondsGreaterThanDefaultMaximumDuration(): iterable + { + $values = \range( + 600, + 1600, + 100 + ); + + foreach ($values as $value) { + yield $value => [ + $value, + ]; + } + } +} diff --git a/test/EndToEnd/Version06/Configuration/Defaults/phpunit.xml b/test/EndToEnd/Version06/Configuration/Defaults/phpunit.xml new file mode 100644 index 00000000..55fa6137 --- /dev/null +++ b/test/EndToEnd/Version06/Configuration/Defaults/phpunit.xml @@ -0,0 +1,26 @@ + + + + + + + . + + + diff --git a/test/EndToEnd/Version06/Configuration/Defaults/test.phpt b/test/EndToEnd/Version06/Configuration/Defaults/test.phpt new file mode 100644 index 00000000..78c1855b --- /dev/null +++ b/test/EndToEnd/Version06/Configuration/Defaults/test.phpt @@ -0,0 +1,40 @@ +--TEST-- +With default configuration +--FILE-- +sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @dataProvider provideMillisecondsGreaterThanDefaultMaximumDuration + */ + public function testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider(int $milliseconds): void + { + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @return \Generator + */ + public static function provideMillisecondsGreaterThanDefaultMaximumDuration(): iterable + { + $values = \range( + 600, + 1000, + 100 + ); + + foreach ($values as $value) { + yield $value => [ + $value, + ]; + } + } +} diff --git a/test/EndToEnd/Version06/Configuration/MaximumCount/phpunit.xml b/test/EndToEnd/Version06/Configuration/MaximumCount/phpunit.xml new file mode 100644 index 00000000..b0f77e72 --- /dev/null +++ b/test/EndToEnd/Version06/Configuration/MaximumCount/phpunit.xml @@ -0,0 +1,34 @@ + + + + + + + 3 + + + + + + + + . + + + diff --git a/test/EndToEnd/Version06/Configuration/MaximumCount/test.phpt b/test/EndToEnd/Version06/Configuration/MaximumCount/test.phpt new file mode 100644 index 00000000..447eb998 --- /dev/null +++ b/test/EndToEnd/Version06/Configuration/MaximumCount/test.phpt @@ -0,0 +1,33 @@ +--TEST-- +With custom configuration setting the "maximum-count" parameter in the XML configuration file +--FILE-- +sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @dataProvider provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration + */ + public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void + { + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @return \Generator + */ + public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable + { + $values = \range( + 200, + 1200, + 100 + ); + + foreach ($values as $value) { + yield $value => [ + $value, + ]; + } + } +} diff --git a/test/EndToEnd/Version06/Configuration/MaximumDuration/phpunit.xml b/test/EndToEnd/Version06/Configuration/MaximumDuration/phpunit.xml new file mode 100644 index 00000000..5c65fc97 --- /dev/null +++ b/test/EndToEnd/Version06/Configuration/MaximumDuration/phpunit.xml @@ -0,0 +1,34 @@ + + + + + + + 100 + + + + + + + + . + + + diff --git a/test/EndToEnd/Version06/Configuration/MaximumDuration/test.phpt b/test/EndToEnd/Version06/Configuration/MaximumDuration/test.phpt new file mode 100644 index 00000000..2459c9f2 --- /dev/null +++ b/test/EndToEnd/Version06/Configuration/MaximumDuration/test.phpt @@ -0,0 +1,40 @@ +--TEST-- +With custom configuration setting the "maximum-duration" parameter in the XML configuration file +--FILE-- +sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @dataProvider provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration + */ + public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void + { + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @return \Generator + */ + public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable + { + $values = \range( + 200, + 300, + 100 + ); + + foreach ($values as $value) { + yield $value => [ + $value, + ]; + } + } +} diff --git a/test/EndToEnd/Version06/TestCase/Bare/phpunit.xml b/test/EndToEnd/Version06/TestCase/Bare/phpunit.xml new file mode 100644 index 00000000..5c65fc97 --- /dev/null +++ b/test/EndToEnd/Version06/TestCase/Bare/phpunit.xml @@ -0,0 +1,34 @@ + + + + + + + 100 + + + + + + + + . + + + diff --git a/test/EndToEnd/Version06/TestCase/Bare/test.phpt b/test/EndToEnd/Version06/TestCase/Bare/test.phpt new file mode 100644 index 00000000..449c7cb1 --- /dev/null +++ b/test/EndToEnd/Version06/TestCase/Bare/test.phpt @@ -0,0 +1,30 @@ +--TEST-- +With a test case that does not sleep in methods that are not test methods +--FILE-- +sleep(); + } + + public static function tearDownAfterClass(): void + { + Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); + } + + protected function setUp(): void + { + Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); + } + + protected function assertPreConditions(): void + { + Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); + } + + protected function assertPostConditions(): void + { + Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); + } + + protected function tearDown(): void + { + Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); + } + + /** + * @before + */ + public function sleepWithBeforeAnnotation(): void + { + Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); + } + + /** + * @beforeClass + */ + public function sleepWithBeforeClassAnnotation(): void + { + Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); + } + + /** + * @after + */ + public function sleepWithAfterAnnotation(): void + { + Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); + } + + /** + * @afterClass + */ + public static function sleepWithAfterClassAnnotation(): void + { + Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); + } + + public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void + { + $milliseconds = 10; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @dataProvider provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration + */ + public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void + { + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @return \Generator + */ + public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable + { + $values = \range( + 200, + 300, + 100 + ); + + foreach ($values as $value) { + Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); + + yield $value => [ + $value, + ]; + } + } +} diff --git a/test/EndToEnd/Version06/TestCase/Combination/phpunit.xml b/test/EndToEnd/Version06/TestCase/Combination/phpunit.xml new file mode 100644 index 00000000..5c65fc97 --- /dev/null +++ b/test/EndToEnd/Version06/TestCase/Combination/phpunit.xml @@ -0,0 +1,34 @@ + + + + + + + 100 + + + + + + + + . + + + diff --git a/test/EndToEnd/Version06/TestCase/Combination/test.phpt b/test/EndToEnd/Version06/TestCase/Combination/test.phpt new file mode 100644 index 00000000..14fd9ca1 --- /dev/null +++ b/test/EndToEnd/Version06/TestCase/Combination/test.phpt @@ -0,0 +1,31 @@ +--TEST-- +With a test case that sleeps in data provider, hook, and test methods +--FILE-- +sleep(); + } + + public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void + { + $milliseconds = 10; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @dataProvider provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration + */ + public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void + { + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @return \Generator + */ + public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable + { + $values = \range( + 200, + 300, + 100 + ); + + foreach ($values as $value) { + yield $value => [ + $value, + ]; + } + } +} diff --git a/test/EndToEnd/Version06/TestCase/WithAfterAnnotation/phpunit.xml b/test/EndToEnd/Version06/TestCase/WithAfterAnnotation/phpunit.xml new file mode 100644 index 00000000..5c65fc97 --- /dev/null +++ b/test/EndToEnd/Version06/TestCase/WithAfterAnnotation/phpunit.xml @@ -0,0 +1,34 @@ + + + + + + + 100 + + + + + + + + . + + + diff --git a/test/EndToEnd/Version06/TestCase/WithAfterAnnotation/test.phpt b/test/EndToEnd/Version06/TestCase/WithAfterAnnotation/test.phpt new file mode 100644 index 00000000..b3f82813 --- /dev/null +++ b/test/EndToEnd/Version06/TestCase/WithAfterAnnotation/test.phpt @@ -0,0 +1,31 @@ +--TEST-- +With a test case that sleeps in a method with @after annotation +--FILE-- +sleep(); + } + + public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void + { + $milliseconds = 10; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @dataProvider provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration + */ + public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void + { + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @return \Generator + */ + public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable + { + $values = \range( + 200, + 300, + 100 + ); + + foreach ($values as $value) { + yield $value => [ + $value, + ]; + } + } +} diff --git a/test/EndToEnd/Version06/TestCase/WithAfterClassAnnotation/phpunit.xml b/test/EndToEnd/Version06/TestCase/WithAfterClassAnnotation/phpunit.xml new file mode 100644 index 00000000..5c65fc97 --- /dev/null +++ b/test/EndToEnd/Version06/TestCase/WithAfterClassAnnotation/phpunit.xml @@ -0,0 +1,34 @@ + + + + + + + 100 + + + + + + + + . + + + diff --git a/test/EndToEnd/Version06/TestCase/WithAfterClassAnnotation/test.phpt b/test/EndToEnd/Version06/TestCase/WithAfterClassAnnotation/test.phpt new file mode 100644 index 00000000..6b44ee70 --- /dev/null +++ b/test/EndToEnd/Version06/TestCase/WithAfterClassAnnotation/test.phpt @@ -0,0 +1,30 @@ +--TEST-- +With a test case that sleeps in a method with @afterClass annotation +--FILE-- +sleep(); + } + + public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void + { + $milliseconds = 10; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @dataProvider provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration + */ + public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void + { + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @return \Generator + */ + public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable + { + $values = \range( + 200, + 300, + 100 + ); + + foreach ($values as $value) { + yield $value => [ + $value, + ]; + } + } +} diff --git a/test/EndToEnd/Version06/TestCase/WithAssertPostConditions/phpunit.xml b/test/EndToEnd/Version06/TestCase/WithAssertPostConditions/phpunit.xml new file mode 100644 index 00000000..5c65fc97 --- /dev/null +++ b/test/EndToEnd/Version06/TestCase/WithAssertPostConditions/phpunit.xml @@ -0,0 +1,34 @@ + + + + + + + 100 + + + + + + + + . + + + diff --git a/test/EndToEnd/Version06/TestCase/WithAssertPostConditions/test.phpt b/test/EndToEnd/Version06/TestCase/WithAssertPostConditions/test.phpt new file mode 100644 index 00000000..b363a885 --- /dev/null +++ b/test/EndToEnd/Version06/TestCase/WithAssertPostConditions/test.phpt @@ -0,0 +1,31 @@ +--TEST-- +With a test case that sleeps in assertPostConditions() method +--FILE-- +sleep(); + } + + public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void + { + $milliseconds = 10; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @dataProvider provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration + */ + public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void + { + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @return \Generator + */ + public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable + { + $values = \range( + 200, + 300, + 100 + ); + + foreach ($values as $value) { + yield $value => [ + $value, + ]; + } + } +} diff --git a/test/EndToEnd/Version06/TestCase/WithAssertPreConditions/phpunit.xml b/test/EndToEnd/Version06/TestCase/WithAssertPreConditions/phpunit.xml new file mode 100644 index 00000000..5c65fc97 --- /dev/null +++ b/test/EndToEnd/Version06/TestCase/WithAssertPreConditions/phpunit.xml @@ -0,0 +1,34 @@ + + + + + + + 100 + + + + + + + + . + + + diff --git a/test/EndToEnd/Version06/TestCase/WithAssertPreConditions/test.phpt b/test/EndToEnd/Version06/TestCase/WithAssertPreConditions/test.phpt new file mode 100644 index 00000000..12ab7246 --- /dev/null +++ b/test/EndToEnd/Version06/TestCase/WithAssertPreConditions/test.phpt @@ -0,0 +1,31 @@ +--TEST-- +With a test case that sleeps in assertPreConditions() method +--FILE-- +sleep(); + } + + public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void + { + $milliseconds = 10; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @dataProvider provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration + */ + public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void + { + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @return \Generator + */ + public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable + { + $values = \range( + 200, + 300, + 100 + ); + + foreach ($values as $value) { + yield $value => [ + $value, + ]; + } + } +} diff --git a/test/EndToEnd/Version06/TestCase/WithBeforeAnnotation/phpunit.xml b/test/EndToEnd/Version06/TestCase/WithBeforeAnnotation/phpunit.xml new file mode 100644 index 00000000..5c65fc97 --- /dev/null +++ b/test/EndToEnd/Version06/TestCase/WithBeforeAnnotation/phpunit.xml @@ -0,0 +1,34 @@ + + + + + + + 100 + + + + + + + + . + + + diff --git a/test/EndToEnd/Version06/TestCase/WithBeforeAnnotation/test.phpt b/test/EndToEnd/Version06/TestCase/WithBeforeAnnotation/test.phpt new file mode 100644 index 00000000..9bdc2c00 --- /dev/null +++ b/test/EndToEnd/Version06/TestCase/WithBeforeAnnotation/test.phpt @@ -0,0 +1,31 @@ +--TEST-- +With a test case that sleeps in a method with @before annotation +--FILE-- +sleep(); + } + + public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void + { + $milliseconds = 10; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @dataProvider provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration + */ + public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void + { + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @return \Generator + */ + public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable + { + $values = \range( + 200, + 300, + 100 + ); + + foreach ($values as $value) { + yield $value => [ + $value, + ]; + } + } +} diff --git a/test/EndToEnd/Version06/TestCase/WithBeforeClassAnnotation/phpunit.xml b/test/EndToEnd/Version06/TestCase/WithBeforeClassAnnotation/phpunit.xml new file mode 100644 index 00000000..5c65fc97 --- /dev/null +++ b/test/EndToEnd/Version06/TestCase/WithBeforeClassAnnotation/phpunit.xml @@ -0,0 +1,34 @@ + + + + + + + 100 + + + + + + + + . + + + diff --git a/test/EndToEnd/Version06/TestCase/WithBeforeClassAnnotation/test.phpt b/test/EndToEnd/Version06/TestCase/WithBeforeClassAnnotation/test.phpt new file mode 100644 index 00000000..c00899b7 --- /dev/null +++ b/test/EndToEnd/Version06/TestCase/WithBeforeClassAnnotation/test.phpt @@ -0,0 +1,30 @@ +--TEST-- +With a test case that sleeps in a method with @beforeClass annotation +--FILE-- +sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @dataProvider provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration + */ + public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void + { + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @return \Generator + */ + public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable + { + $values = \range( + 200, + 300, + 100 + ); + + foreach ($values as $value) { + Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); + + yield $value => [ + $value, + ]; + } + } +} diff --git a/test/EndToEnd/Version06/TestCase/WithDataProvider/phpunit.xml b/test/EndToEnd/Version06/TestCase/WithDataProvider/phpunit.xml new file mode 100644 index 00000000..5c65fc97 --- /dev/null +++ b/test/EndToEnd/Version06/TestCase/WithDataProvider/phpunit.xml @@ -0,0 +1,34 @@ + + + + + + + 100 + + + + + + + + . + + + diff --git a/test/EndToEnd/Version06/TestCase/WithDataProvider/test.phpt b/test/EndToEnd/Version06/TestCase/WithDataProvider/test.phpt new file mode 100644 index 00000000..d8f2311e --- /dev/null +++ b/test/EndToEnd/Version06/TestCase/WithDataProvider/test.phpt @@ -0,0 +1,30 @@ +--TEST-- +With a test case that sleeps in a data provider +--FILE-- +sleep(); + } + + public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void + { + $milliseconds = 10; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @dataProvider provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration + */ + public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void + { + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @return \Generator + */ + public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable + { + $values = \range( + 200, + 300, + 100 + ); + + foreach ($values as $value) { + yield $value => [ + $value, + ]; + } + } +} diff --git a/test/EndToEnd/Version06/TestCase/WithSetUp/phpunit.xml b/test/EndToEnd/Version06/TestCase/WithSetUp/phpunit.xml new file mode 100644 index 00000000..5c65fc97 --- /dev/null +++ b/test/EndToEnd/Version06/TestCase/WithSetUp/phpunit.xml @@ -0,0 +1,34 @@ + + + + + + + 100 + + + + + + + + . + + + diff --git a/test/EndToEnd/Version06/TestCase/WithSetUp/test.phpt b/test/EndToEnd/Version06/TestCase/WithSetUp/test.phpt new file mode 100644 index 00000000..62e1dca9 --- /dev/null +++ b/test/EndToEnd/Version06/TestCase/WithSetUp/test.phpt @@ -0,0 +1,31 @@ +--TEST-- +With a test case that sleeps in a setUp() method +--FILE-- +sleep(); + } + + public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void + { + $milliseconds = 10; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @dataProvider provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration + */ + public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void + { + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @return \Generator + */ + public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable + { + $values = \range( + 200, + 300, + 100 + ); + + foreach ($values as $value) { + yield $value => [ + $value, + ]; + } + } +} diff --git a/test/EndToEnd/Version06/TestCase/WithSetUpBeforeClass/phpunit.xml b/test/EndToEnd/Version06/TestCase/WithSetUpBeforeClass/phpunit.xml new file mode 100644 index 00000000..5c65fc97 --- /dev/null +++ b/test/EndToEnd/Version06/TestCase/WithSetUpBeforeClass/phpunit.xml @@ -0,0 +1,34 @@ + + + + + + + 100 + + + + + + + + . + + + diff --git a/test/EndToEnd/Version06/TestCase/WithSetUpBeforeClass/test.phpt b/test/EndToEnd/Version06/TestCase/WithSetUpBeforeClass/test.phpt new file mode 100644 index 00000000..9bf55b9b --- /dev/null +++ b/test/EndToEnd/Version06/TestCase/WithSetUpBeforeClass/test.phpt @@ -0,0 +1,30 @@ +--TEST-- +With a test case that sleeps in a setUpBeforeClass() method +--FILE-- +sleep(); + } + + public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void + { + $milliseconds = 10; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @dataProvider provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration + */ + public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void + { + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @return \Generator + */ + public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable + { + $values = \range( + 200, + 300, + 100 + ); + + foreach ($values as $value) { + yield $value => [ + $value, + ]; + } + } +} diff --git a/test/EndToEnd/Version06/TestCase/WithTearDown/phpunit.xml b/test/EndToEnd/Version06/TestCase/WithTearDown/phpunit.xml new file mode 100644 index 00000000..5c65fc97 --- /dev/null +++ b/test/EndToEnd/Version06/TestCase/WithTearDown/phpunit.xml @@ -0,0 +1,34 @@ + + + + + + + 100 + + + + + + + + . + + + diff --git a/test/EndToEnd/Version06/TestCase/WithTearDown/test.phpt b/test/EndToEnd/Version06/TestCase/WithTearDown/test.phpt new file mode 100644 index 00000000..e218e54b --- /dev/null +++ b/test/EndToEnd/Version06/TestCase/WithTearDown/test.phpt @@ -0,0 +1,31 @@ +--TEST-- +With a test case that sleeps in a tearDown() method +--FILE-- +sleep(); + } + + public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void + { + $milliseconds = 10; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @dataProvider provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration + */ + public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void + { + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @return \Generator + */ + public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable + { + $values = \range( + 200, + 300, + 100 + ); + + foreach ($values as $value) { + yield $value => [ + $value, + ]; + } + } +} diff --git a/test/EndToEnd/Version06/TestCase/WithTearDownAfterClass/phpunit.xml b/test/EndToEnd/Version06/TestCase/WithTearDownAfterClass/phpunit.xml new file mode 100644 index 00000000..5c65fc97 --- /dev/null +++ b/test/EndToEnd/Version06/TestCase/WithTearDownAfterClass/phpunit.xml @@ -0,0 +1,34 @@ + + + + + + + 100 + + + + + + + + . + + + diff --git a/test/EndToEnd/Version06/TestCase/WithTearDownAfterClass/test.phpt b/test/EndToEnd/Version06/TestCase/WithTearDownAfterClass/test.phpt new file mode 100644 index 00000000..02304aaa --- /dev/null +++ b/test/EndToEnd/Version06/TestCase/WithTearDownAfterClass/test.phpt @@ -0,0 +1,30 @@ +--TEST-- +With a test case that sleeps in a tearDownAfterClass() method +--FILE-- +sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @maximumDuration 200 + * + * @slowThreshold 400 + */ + public function testSleeperSleepsLongerThanMaximumDurationFromAnnotationWhenTestMethodHasMaximumDurationAndSlowThresholdAnnotations(): void + { + $milliseconds = 300; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } +} diff --git a/test/EndToEnd/Version06/TestMethod/WithMaximumDurationAndSlowThresholdAnnotations/phpunit.xml b/test/EndToEnd/Version06/TestMethod/WithMaximumDurationAndSlowThresholdAnnotations/phpunit.xml new file mode 100644 index 00000000..5c65fc97 --- /dev/null +++ b/test/EndToEnd/Version06/TestMethod/WithMaximumDurationAndSlowThresholdAnnotations/phpunit.xml @@ -0,0 +1,34 @@ + + + + + + + 100 + + + + + + + + . + + + diff --git a/test/EndToEnd/Version06/TestMethod/WithMaximumDurationAndSlowThresholdAnnotations/test.phpt b/test/EndToEnd/Version06/TestMethod/WithMaximumDurationAndSlowThresholdAnnotations/test.phpt new file mode 100644 index 00000000..ef9c3f99 --- /dev/null +++ b/test/EndToEnd/Version06/TestMethod/WithMaximumDurationAndSlowThresholdAnnotations/test.phpt @@ -0,0 +1,29 @@ +--TEST-- +With @maximumDuration and @slowThreshold annotations +--FILE-- +sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @maximumDuration 3.14 + */ + public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWhenTestMethodHasInvalidMaximumDurationAnnotation(): void + { + $milliseconds = 200; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @maximumDuration 200 + */ + public function testSleeperSleepsShorterThanMaximumDurationFromAnnotationWhenTestMethodHasValidMaximumDurationAnnotation(): void + { + $milliseconds = 10; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @maximumDuration 200 + */ + public function testSleeperSleepsLongerThanMaximumDurationFromAnnotationWhenTestMethodHasValidMaximumDurationAnnotation(): void + { + $milliseconds = 300; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } +} diff --git a/test/EndToEnd/Version06/TestMethod/WithMaximumDurationAnnotation/phpunit.xml b/test/EndToEnd/Version06/TestMethod/WithMaximumDurationAnnotation/phpunit.xml new file mode 100644 index 00000000..5c65fc97 --- /dev/null +++ b/test/EndToEnd/Version06/TestMethod/WithMaximumDurationAnnotation/phpunit.xml @@ -0,0 +1,34 @@ + + + + + + + 100 + + + + + + + + . + + + diff --git a/test/EndToEnd/Version06/TestMethod/WithMaximumDurationAnnotation/test.phpt b/test/EndToEnd/Version06/TestMethod/WithMaximumDurationAnnotation/test.phpt new file mode 100644 index 00000000..92473a65 --- /dev/null +++ b/test/EndToEnd/Version06/TestMethod/WithMaximumDurationAnnotation/test.phpt @@ -0,0 +1,30 @@ +--TEST-- +With test methods with @maximumDuration annotations +--FILE-- +sleep(); + } + + public static function tearDownAfterClass(): void + { + Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); + } + + protected function setUp(): void + { + Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); + } + + protected function assertPreConditions(): void + { + Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); + } + + protected function assertPostConditions(): void + { + Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); + } + + protected function tearDown(): void + { + Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); + } + + /** + * @before + */ + public function sleepWithBeforeAnnotation(): void + { + Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); + } + + /** + * @beforeClass + */ + public static function sleepWithBeforeClassAnnotation(): void + { + Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); + } + + /** + * @after + */ + public function sleepWithAfterAnnotation(): void + { + Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); + } + + /** + * @afterClass + */ + public static function sleepWithAfterClassAnnotation(): void + { + Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); + } + + public function testSleeperSleepsShorterThanMaximumDurationFromXmlConfiguration(): void + { + $milliseconds = 10; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @runInSeparateProcess + */ + public function testSleeperSleepsShorterThanMaximumDurationFromXmlConfigurationWhenMethodHasRunInSeparateProcessAnnotation(): void + { + $milliseconds = 50; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfiguration(): void + { + $milliseconds = 200; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @runInSeparateProcess + */ + public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWhenMethodHasRunInSeparateProcessAnnotation(): void + { + $milliseconds = 300; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } +} diff --git a/test/EndToEnd/Version06/TestMethod/WithRunInSeparateProcessAnnotation/phpunit.xml b/test/EndToEnd/Version06/TestMethod/WithRunInSeparateProcessAnnotation/phpunit.xml new file mode 100644 index 00000000..5c65fc97 --- /dev/null +++ b/test/EndToEnd/Version06/TestMethod/WithRunInSeparateProcessAnnotation/phpunit.xml @@ -0,0 +1,34 @@ + + + + + + + 100 + + + + + + + + . + + + diff --git a/test/EndToEnd/Version06/TestMethod/WithRunInSeparateProcessAnnotation/test.phpt b/test/EndToEnd/Version06/TestMethod/WithRunInSeparateProcessAnnotation/test.phpt new file mode 100644 index 00000000..5ac402be --- /dev/null +++ b/test/EndToEnd/Version06/TestMethod/WithRunInSeparateProcessAnnotation/test.phpt @@ -0,0 +1,37 @@ +--TEST-- +With a test case that sleeps in data provider, hook, and test methods and has test methods with @runInSeparateProcess annotation +--FILE-- +sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @slowThreshold 400 + * + * @maximumDuration 200 + */ + public function testSleeperSleepsLongerThanMaximumDurationFromAnnotationWhenTestMethodHasMaximumDurationAndSlowThresholdAnnotations(): void + { + $milliseconds = 300; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } +} diff --git a/test/EndToEnd/Version06/TestMethod/WithSlowThresholdAndMaximumDurationAnnotations/phpunit.xml b/test/EndToEnd/Version06/TestMethod/WithSlowThresholdAndMaximumDurationAnnotations/phpunit.xml new file mode 100644 index 00000000..5c65fc97 --- /dev/null +++ b/test/EndToEnd/Version06/TestMethod/WithSlowThresholdAndMaximumDurationAnnotations/phpunit.xml @@ -0,0 +1,34 @@ + + + + + + + 100 + + + + + + + + . + + + diff --git a/test/EndToEnd/Version06/TestMethod/WithSlowThresholdAndMaximumDurationAnnotations/test.phpt b/test/EndToEnd/Version06/TestMethod/WithSlowThresholdAndMaximumDurationAnnotations/test.phpt new file mode 100644 index 00000000..ef398847 --- /dev/null +++ b/test/EndToEnd/Version06/TestMethod/WithSlowThresholdAndMaximumDurationAnnotations/test.phpt @@ -0,0 +1,29 @@ +--TEST-- +With @maximumDuration and @slowThreshold annotations +--FILE-- +sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @slowThreshold 3.14 + * + * @see https://github.com/johnkary/phpunit-speedtrap/blob/1.0/src/JohnKary/PHPUnit/Listener/SpeedTrapListener.php#L309-L331 + */ + public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWhenTestMethodHasInvalidSlowThresholdAnnotation(): void + { + $milliseconds = 200; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @slowThreshold 200 + * + * @see https://github.com/johnkary/phpunit-speedtrap/blob/1.0/src/JohnKary/PHPUnit/Listener/SpeedTrapListener.php#L309-L331 + */ + public function testSleeperSleepsShorterThanSlowThresholdFromAnnotationWhenTestMethodHasValidSlowThresholdAnnotation(): void + { + $milliseconds = 10; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @slowThreshold 200 + * + * @see https://github.com/johnkary/phpunit-speedtrap/blob/1.0/src/JohnKary/PHPUnit/Listener/SpeedTrapListener.php#L309-L331 + */ + public function testSleeperSleepsLongerThanSlowThresholdFromAnnotationWhenTestMethodHasValidSlowThresholdAnnotation(): void + { + $milliseconds = 300; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } +} diff --git a/test/EndToEnd/Version06/TestMethod/WithSlowThresholdAnnotation/phpunit.xml b/test/EndToEnd/Version06/TestMethod/WithSlowThresholdAnnotation/phpunit.xml new file mode 100644 index 00000000..5c65fc97 --- /dev/null +++ b/test/EndToEnd/Version06/TestMethod/WithSlowThresholdAnnotation/phpunit.xml @@ -0,0 +1,34 @@ + + + + + + + 100 + + + + + + + + . + + + diff --git a/test/EndToEnd/Version06/TestMethod/WithSlowThresholdAnnotation/test.phpt b/test/EndToEnd/Version06/TestMethod/WithSlowThresholdAnnotation/test.phpt new file mode 100644 index 00000000..0ffa695b --- /dev/null +++ b/test/EndToEnd/Version06/TestMethod/WithSlowThresholdAnnotation/test.phpt @@ -0,0 +1,30 @@ +--TEST-- +With test methods with @slowThreshold annotations +--FILE-- + + + + . + + +