Skip to content

Commit 5bb5771

Browse files
courtney-mileslocalheinz
authored andcommitted
fix discovery of maximumDuration annotation when test-cases have no test methods
1 parent bf575ea commit 5bb5771

File tree

23 files changed

+631
-0
lines changed

23 files changed

+631
-0
lines changed

CHANGELOG.md

Lines changed: 4 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].

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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
PHPUnit %s
17+
18+
Runtime: %s
19+
Configuration: %s/EndToEnd/Version06/TestCase/WithoutTestMethods/phpunit.xml
20+
21+
W 1 / 1 (100%)
22+
23+
Time: %s, Memory: %s
24+
25+
There was 1 warning:
26+
27+
1) Warning
28+
No tests found in class "Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version06\TestCase\WithoutTestMethods\SleeperTest".
29+
30+
WARNINGS!
31+
Tests: 1, Assertions: 0, Warnings: 1.
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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
PHPUnit %s
17+
18+
Runtime: %s
19+
Configuration: %s/EndToEnd/Version07/TestCase/WithoutTestMethods/phpunit.xml
20+
21+
W 1 / 1 (100%)
22+
23+
Time: %s, Memory: %s
24+
25+
There was 1 warning:
26+
27+
1) Warning
28+
No tests found in class "Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version07\TestCase\WithoutTestMethods\SleeperTest".
29+
30+
WARNINGS!
31+
Tests: 1, Assertions: 0, Warnings: 1.
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)