Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Clean up tests #402

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 14 additions & 175 deletions test/EndToEnd/Version10/CustomConfiguration/SleeperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,179 +13,15 @@

namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\CustomConfiguration;

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

#[Framework\Attributes\CoversClass(Test\Fixture\Sleeper::class)]
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());
}

/**
* This DocBlock is intentionally left without a useful comment or annotation.
*/
public function testSleeperSleepsWithDocBlockWithoutSlowThresholdAnnotation(): void
{
$milliseconds = 90;

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

$sleeper->sleep();

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

/**
* @maximumDuration 3.14
*/
public function testSleeperSleepsWithDocBlockWithMaximumDurationAnnotationWhereValueIsNotAnInt(): void
{
$milliseconds = 110;

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

$sleeper->sleep();

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

/**
* @maximumDuration 140
*/
public function testSleeperSleepsShorterThanMaximumDurationFromMaximumDurationAnnotation(): void
{
$milliseconds = 130;

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

$sleeper->sleep();

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

/**
* @maximumDuration 150
*/
public function testSleeperSleepsLongerThanMaximumDurationFromMaximumDurationAnnotation(): void
{
$milliseconds = 150;

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

$sleeper->sleep();

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

/**
* @maximumDuration 160
*
* @slowThreshold 120
*/
public function testSleeperSleepsLongerThanMaximumDurationFromMaximumDurationAnnotationWhenSlowThresholdAnnotationIsPresentAfterMaximumDuration(): void
{
$milliseconds = 170;

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

$sleeper->sleep();

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

/**
* @slowThreshold 120
*
* @maximumDuration 180
*/
public function testSleeperSleepsLongerThanMaximumDurationFromMaximumDurationAnnotationWhenSlowThresholdAnnotationIsPresentBeforeMaximumDuration(): void
{
$milliseconds = 200;

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

$sleeper->sleep();

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

/**
* @see https://github.com/johnkary/phpunit-speedtrap/blob/1.0/src/JohnKary/PHPUnit/Listener/SpeedTrapListener.php#L309-L331
*
* @slowThreshold 3.14
*/
public function testSleeperSleepsWithDocBlockWithSlowThresholdAnnotationWhereValueIsNotAnInt(): void
{
$milliseconds = 40;

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

$sleeper->sleep();

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

/**
* @see https://github.com/johnkary/phpunit-speedtrap/blob/1.0/src/JohnKary/PHPUnit/Listener/SpeedTrapListener.php#L309-L331
*
* @slowThreshold 100
*/
public function testSleeperSleepsShorterThanMaximumDurationFromSlowThresholdAnnotation(): void
{
$milliseconds = 80;

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

$sleeper->sleep();

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

/**
* @see https://github.com/johnkary/phpunit-speedtrap/blob/1.0/src/JohnKary/PHPUnit/Listener/SpeedTrapListener.php#L309-L331
*
* @slowThreshold 200
*/
public function testSleeperSleepsLongerThanMaximumDurationFromSlowThresholdAnnotation(): void
#[Framework\Attributes\DataProvider('provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration')]
public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void
{
$milliseconds = 220;

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

$sleeper->sleep();

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

#[Attribute\MaximumDuration(140)]
public function testSleeperSleepsShorterThanMaximumDurationFromMaximumDurationAttribute(): void
{
$milliseconds = 130;

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

$sleeper->sleep();

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

#[Attribute\MaximumDuration(160)]
public function testSleeperSleepsLongerThanMaximumDurationFromMaximumDurationAttribute(): void
{
$milliseconds = 160;

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

$sleeper->sleep();
Expand All @@ -194,17 +30,20 @@
}

/**
* @maximumDuration 20
* @return \Generator<int, array{0: int}>
*/
#[Attribute\MaximumDuration(50)]
public function testSleeperSleepsShorterThanMaximumDurationFromMaximumDurationAttributeWhenMaximumDurationAnnotationIsPresent(): void
public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable

Check failure on line 35 in test/EndToEnd/Version10/CustomConfiguration/SleeperTest.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (7.4, locked)

PossiblyUnusedMethod

test/EndToEnd/Version10/CustomConfiguration/SleeperTest.php:35:28: PossiblyUnusedMethod: Cannot find any calls to method Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\CustomConfiguration\SleeperTest::provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration (see https://psalm.dev/087)
{
$milliseconds = 40;

$sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds);
$values = \range(
300,
500,
50,
);

$sleeper->sleep();

self::assertSame($milliseconds, $sleeper->milliseconds());
foreach ($values as $value) {
yield $value => [
$value,
];
}
}
}
2 changes: 1 addition & 1 deletion test/EndToEnd/Version10/CustomConfiguration/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<extensions>
<bootstrap class="Ergebnis\PHPUnit\SlowTestDetector\Extension">
<parameter name="maximum-count" value="3"/>
<parameter name="maximum-duration" value="50"/>
<parameter name="maximum-duration" value="300"/>
</bootstrap>
</extensions>
<testsuites>
Expand Down
16 changes: 8 additions & 8 deletions test/EndToEnd/Version10/CustomConfiguration/test.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
Configuring "maximum-count" parameter to 3 and "maximum-duration" parameter to 50 milliseconds
Configuring "maximum-count" parameter to 3 and "maximum-duration" parameter to 300 milliseconds
--FILE--
<?php

Expand All @@ -21,16 +21,16 @@ Runtime: %s
Configuration: %Stest/EndToEnd/Version10/CustomConfiguration/phpunit.xml
Random %seed: %s

............. 13 / 13 (100%)
..... 5 / 5 (100%)

Detected 7 tests that took longer than expected.
Detected 5 tests that took longer than expected.

1. 0.2%s (0.200) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\CustomConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromSlowThresholdAnnotation
2. 0.2%s (0.180) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\CustomConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromMaximumDurationAnnotationWhenSlowThresholdAnnotationIsPresentBeforeMaximumDuration
3. 0.1%s (0.160) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\CustomConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromMaximumDurationAnnotationWhenSlowThresholdAnnotationIsPresentAfterMaximumDuration
1. 0.5%s (0.300) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\CustomConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider#4
2. 0.4%s (0.300) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\CustomConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider#3
3. 0.4%s (0.300) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\CustomConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider#2

There are 4 additional slow tests that are not listed here.
There are 2 additional slow tests that are not listed here.

Time: %s, Memory: %s

OK (13 tests, 13 assertions)
OK (5 tests, 5 assertions)
Loading
Loading