Skip to content

Commit fbf30fd

Browse files
Fix: discovery of maximumDuration annotation when test-cases have no test methods
1 parent 8ff9c0b commit fbf30fd

File tree

23 files changed

+561
-0
lines changed

23 files changed

+561
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
88

99
For a full diff see [`2.19.1...main`][2.19.1...main].
1010

11+
### Fixed
12+
13+
- Fixed discovery of `@maximumDuration` annotation when a test case does not have any test methods ([#687]), by [@courtney-miles]
14+
1115
## [`2.19.1`][2.19.1]
1216

1317
For a full diff see [`2.19.0...2.19.1`][2.19.0...2.19.1].
@@ -413,6 +417,7 @@ For a full diff see [`7afa59c...1.0.0`][7afa59c...1.0.0].
413417
[#664]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/664
414418

415419
[@dantleech]: https://github.com/dantleech
420+
[@courtney-miles]: https://github.com/courtney-miles
416421
[@HypeMC]: https://github.com/HypeMC
417422
[@localheinz]: https://github.com/localheinz
418423
[@morgan-atproperties]: https://github.com/morgan-atproperties

src/Extension.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,10 @@ private function resolveMaximumDuration(string $test): MaximumDuration
371371
);
372372
}
373373

374+
if (\strpos($test, '::') === false) {
375+
return $this->maximumDuration;
376+
}
377+
374378
list($testClassName, $testMethodName) = \explode(
375379
'::',
376380
$test
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* Copyright (c) 2021-2025 Andreas Möller
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE.md file that was distributed with this source code.
10+
*
11+
* @see https://github.com/ergebnis/phpunit-slow-test-detector
12+
*/
13+
14+
namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version06\TestCase\WithoutTestMethods;
15+
16+
use PHPUnit\Framework;
17+
18+
/**
19+
* @covers \Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\Sleeper
20+
*/
21+
final class SleeperTest extends Framework\TestCase
22+
{
23+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<phpunit
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.5/phpunit.xsd"
4+
beStrictAboutChangesToGlobalState="true"
5+
beStrictAboutOutputDuringTests="true"
6+
beStrictAboutTestsThatDoNotTestAnything="true"
7+
beStrictAboutTodoAnnotatedTests="true"
8+
bootstrap="../../../../../vendor/autoload.php"
9+
colors="true"
10+
columns="max"
11+
forceCoversAnnotation="true"
12+
stopOnError="false"
13+
stopOnFailure="false"
14+
stopOnIncomplete="false"
15+
stopOnSkipped="false"
16+
verbose="true"
17+
>
18+
<listeners>
19+
<listener class="Ergebnis\PHPUnit\SlowTestDetector\Extension">
20+
<arguments>
21+
<array>
22+
<element key="maximum-duration">
23+
<integer>100</integer>
24+
</element>
25+
</array>
26+
</arguments>
27+
</listener>
28+
</listeners>
29+
<testsuites>
30+
<testsuite name="Unit Tests">
31+
<directory>.</directory>
32+
</testsuite>
33+
</testsuites>
34+
</phpunit>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
With a test case that has no test methods
3+
--FILE--
4+
<?php
5+
6+
declare(strict_types=1);
7+
8+
use PHPUnit\TextUI;
9+
10+
$_SERVER['argv'][] = '--configuration=test/EndToEnd/Version06/TestCase/WithoutTestMethods/phpunit.xml';
11+
12+
require_once __DIR__ . '/../../../../../vendor/autoload.php';
13+
14+
PHPUnit\TextUI\Command::main();
15+
--EXPECTF--
16+
%a
17+
18+
W 1 / 1 (100%)
19+
20+
%a
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* Copyright (c) 2021-2025 Andreas Möller
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE.md file that was distributed with this source code.
10+
*
11+
* @see https://github.com/ergebnis/phpunit-slow-test-detector
12+
*/
13+
14+
namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version07\TestCase\WithoutTestMethods;
15+
16+
use PHPUnit\Framework;
17+
18+
/**
19+
* @covers \Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\Sleeper
20+
*/
21+
final class SleeperTest extends Framework\TestCase
22+
{
23+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<phpunit
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
4+
beStrictAboutChangesToGlobalState="true"
5+
beStrictAboutOutputDuringTests="true"
6+
beStrictAboutTestsThatDoNotTestAnything="true"
7+
beStrictAboutTodoAnnotatedTests="true"
8+
bootstrap="../../../../../vendor/autoload.php"
9+
colors="true"
10+
columns="max"
11+
forceCoversAnnotation="true"
12+
stopOnError="false"
13+
stopOnFailure="false"
14+
stopOnIncomplete="false"
15+
stopOnSkipped="false"
16+
verbose="true"
17+
>
18+
<extensions>
19+
<extension class="Ergebnis\PHPUnit\SlowTestDetector\Extension">
20+
<arguments>
21+
<array>
22+
<element key="maximum-duration">
23+
<integer>100</integer>
24+
</element>
25+
</array>
26+
</arguments>
27+
</extension>
28+
</extensions>
29+
<testsuites>
30+
<testsuite name="Unit Tests">
31+
<directory>.</directory>
32+
</testsuite>
33+
</testsuites>
34+
</phpunit>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
With a test case that has no test methods
3+
--FILE--
4+
<?php
5+
6+
declare(strict_types=1);
7+
8+
use PHPUnit\TextUI;
9+
10+
$_SERVER['argv'][] = '--configuration=test/EndToEnd/Version07/TestCase/WithoutTestMethods/phpunit.xml';
11+
12+
require_once __DIR__ . '/../../../../../vendor/autoload.php';
13+
14+
PHPUnit\TextUI\Command::main();
15+
--EXPECTF--
16+
%a
17+
18+
W 1 / 1 (100%)
19+
20+
%a
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* Copyright (c) 2021-2025 Andreas Möller
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE.md file that was distributed with this source code.
10+
*
11+
* @see https://github.com/ergebnis/phpunit-slow-test-detector
12+
*/
13+
14+
namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version08\TestCase\WithoutTestMethods;
15+
16+
use PHPUnit\Framework;
17+
18+
/**
19+
* @covers \Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\Sleeper
20+
*/
21+
final class SleeperTest extends Framework\TestCase
22+
{
23+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<phpunit
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
4+
beStrictAboutChangesToGlobalState="true"
5+
beStrictAboutOutputDuringTests="true"
6+
beStrictAboutTestsThatDoNotTestAnything="true"
7+
beStrictAboutTodoAnnotatedTests="true"
8+
bootstrap="../../../../../vendor/autoload.php"
9+
cacheResult="false"
10+
colors="true"
11+
columns="max"
12+
executionOrder="default"
13+
forceCoversAnnotation="true"
14+
stopOnError="false"
15+
stopOnFailure="false"
16+
stopOnIncomplete="false"
17+
stopOnSkipped="false"
18+
verbose="true"
19+
>
20+
<extensions>
21+
<extension class="Ergebnis\PHPUnit\SlowTestDetector\Extension">
22+
<arguments>
23+
<array>
24+
<element key="maximum-duration">
25+
<integer>100</integer>
26+
</element>
27+
</array>
28+
</arguments>
29+
</extension>
30+
</extensions>
31+
<testsuites>
32+
<testsuite name="Unit Tests">
33+
<directory>.</directory>
34+
</testsuite>
35+
</testsuites>
36+
</phpunit>

0 commit comments

Comments
 (0)