Skip to content

Commit

Permalink
Merge pull request #243 from ergebnis/fix/no-output
Browse files Browse the repository at this point in the history
Fix: Do not register extension when running `phpunit` with the `--no-output` option
  • Loading branch information
localheinz authored Mar 18, 2023
2 parents 879a30a + 49237f3 commit 7a9edf4
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.1.0...main`][2.1.0...main].

### Fixed

- Stopped registering extension when running `phpunit` with the `--no-output` option ([#243]), by [@localheinz]

## [`2.1.0`][2.1.0]

For a full diff see [`2.0.0...2.1.0`][2.0.0...2.1.0].
Expand Down Expand Up @@ -107,5 +111,6 @@ For a full diff see [`7afa59c...1.0.0`][7afa59c...1.0.0].
[#221]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/221
[#222]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/222
[#224]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/224
[#243]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/243

[@localheinz]: https://github.com/localheinz
4 changes: 4 additions & 0 deletions src/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public function bootstrap(
Runner\Extension\Facade $facade,
Runner\Extension\ParameterCollection $parameters,
): void {
if ($configuration->noOutput()) {
return;
}

$maximumCount = MaximumCount::fromInt(10);

if ($parameters->has('maximum-count')) {
Expand Down
90 changes: 90 additions & 0 deletions test/EndToEnd/NoOutput/SleeperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2021-2023 Andreas Möller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/phpunit-slow-test-detector
*/

namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\NoOutput;

use Ergebnis\PHPUnit\SlowTestDetector\Test;
use PHPUnit\Framework;

/**
* @internal
*
* @covers \Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\Sleeper
*/
final class SleeperTest extends Framework\TestCase
{
use Test\Util\Helper;

public function testSleeperDoesNotSleepAtAll(): void
{
$milliseconds = 0;

$sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds);

$sleeper->sleep();

self::assertSame($milliseconds, $sleeper->milliseconds());
}

public function testSleeperSleepsJustBelowDefaultMaximumDuration(): void
{
$milliseconds = 400;

$sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds);

$sleeper->sleep();

self::assertSame($milliseconds, $sleeper->milliseconds());
}

public function testSleeperSleepsJustAboveDefaultMaximumDuration(): void
{
$milliseconds = 600;

$sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds);

$sleeper->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<int, array{0: int}>
*/
public static function provideMillisecondsGreaterThanDefaultMaximumDuration(): \Generator
{
$values = \range(
700,
1600,
100,
);

foreach ($values as $value) {
yield $value => [
$value,
];
}
}
}
32 changes: 32 additions & 0 deletions test/EndToEnd/NoOutput/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../vendor/phpunit/phpunit/phpunit.xsd"
beStrictAboutChangesToGlobalState="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutTodoAnnotatedTests="true"
bootstrap="../../../vendor/autoload.php"
cacheResult="false"
colors="true"
columns="max"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
executionOrder="random"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
>
<extensions>
<bootstrap class="Ergebnis\PHPUnit\SlowTestDetector\Extension"/>
</extensions>
<testsuites>
<testsuite name="unit">
<directory>.</directory>
</testsuite>
</testsuites>
</phpunit>
18 changes: 18 additions & 0 deletions test/EndToEnd/NoOutput/test.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
With default configuration of extension
--FILE--
<?php

declare(strict_types=1);

use PHPUnit\TextUI;

$_SERVER['argv'][] = '--configuration=test/EndToEnd/Default/phpunit.xml';
$_SERVER['argv'][] = '--no-output';

require_once __DIR__ . '/../../../vendor/autoload.php';

$application = new TextUI\Application();

$application->run($_SERVER['argv']);
--EXPECTF--

0 comments on commit 7a9edf4

Please sign in to comment.