Skip to content

Commit 8d3e14b

Browse files
authored
Merge pull request #675 from morgan-atproperties/fix-generated-tests
Fix discovery of `@maximumDuration` annotation when using data providers
2 parents 602a18a + c3c5592 commit 8d3e14b

File tree

14 files changed

+372
-13
lines changed

14 files changed

+372
-13
lines changed

CHANGELOG.md

+5
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.0...main`][2.19.0...main].
1010

11+
### Fixed
12+
13+
- Fixed discovery of `@maximumDuration` annotation when using data providers ([#675]), by [@morgan-atproperties]
14+
1115
## [`2.19.0`][2.19.0]
1216

1317
For a full diff see [`2.18.0...2.19.0`][2.18.0...2.19.0].
@@ -406,4 +410,5 @@ For a full diff see [`7afa59c...1.0.0`][7afa59c...1.0.0].
406410
[@dantleech]: https://github.com/dantleech
407411
[@HypeMC]: https://github.com/HypeMC
408412
[@localheinz]: https://github.com/localheinz
413+
[@morgan-atproperties]: https://github.com/morgan-atproperties
409414
[@mvorisek]: https://github.com/mvorisek

src/Extension.php

+17
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,23 @@ public function executeAfterLastTest(): void
354354

355355
private function resolveMaximumDuration(string $test): MaximumDuration
356356
{
357+
/**
358+
* @see https://github.com/sebastianbergmann/phpunit/blob/6.5.0/src/Framework/TestCase.php#L352-L368
359+
* @see https://github.com/sebastianbergmann/phpunit/blob/6.5.0/src/Framework/TestCase.php#L1966-L1992
360+
*/
361+
$dataSetPosition = \strpos(
362+
$test,
363+
' with data set'
364+
);
365+
366+
if (false !== $dataSetPosition) {
367+
$test = \substr(
368+
$test,
369+
0,
370+
$dataSetPosition
371+
);
372+
}
373+
357374
list($testClassName, $testMethodName) = \explode(
358375
'::',
359376
$test

test/EndToEnd/Version06/TestMethod/WithMaximumDurationAnnotation/SleeperTest.php

+56
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,62 @@ public function testSleeperSleepsShorterThanMaximumDurationFromAnnotationWhenTes
6363
self::assertSame($milliseconds, $sleeper->milliseconds());
6464
}
6565

66+
/**
67+
* @dataProvider provideDataWhereDataNameIsInteger
68+
*
69+
* @maximumDuration 200
70+
*/
71+
public function testSleeperSleepsShorterThanMaximumDurationFromAnnotationWithNumericDataProvider()
72+
{
73+
$milliseconds = 150;
74+
75+
$sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds);
76+
77+
$sleeper->sleep();
78+
79+
self::assertSame($milliseconds, $sleeper->milliseconds());
80+
}
81+
82+
/**
83+
* @return list<array{0: string}>
84+
*/
85+
public static function provideDataWhereDataNameIsInteger(): array
86+
{
87+
return [
88+
[
89+
'bar',
90+
],
91+
];
92+
}
93+
94+
/**
95+
* @dataProvider provideDataWhereDataNameIsString
96+
*
97+
* @maximumDuration 200
98+
*/
99+
public function testSleeperSleepsShorterThanMaximumDurationFromAnnotationWithNamedDataProvider()
100+
{
101+
$milliseconds = 150;
102+
103+
$sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds);
104+
105+
$sleeper->sleep();
106+
107+
self::assertSame($milliseconds, $sleeper->milliseconds());
108+
}
109+
110+
/**
111+
* @return array<string, array{0: string}>
112+
*/
113+
public static function provideDataWhereDataNameIsString(): array
114+
{
115+
return [
116+
'foo' => [
117+
'bar',
118+
],
119+
];
120+
}
121+
66122
/**
67123
* @maximumDuration 200
68124
*/

test/EndToEnd/Version06/TestMethod/WithMaximumDurationAnnotation/test.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ PHPUnit %s
1818
Runtime: %s
1919
Configuration: %s/EndToEnd/Version06/TestMethod/WithMaximumDurationAnnotation/phpunit.xml
2020

21-
.... 4 / 4 (100%)
21+
...... 6 / 6 (100%)
2222

2323
Detected 2 tests where the duration exceeded the maximum duration.
2424

@@ -27,4 +27,4 @@ Detected 2 tests where the duration exceeded the maximum duration.
2727

2828
Time: %s, Memory: %s
2929

30-
OK (4 tests, 4 assertions)
30+
OK (6 tests, 6 assertions)

test/EndToEnd/Version07/TestMethod/WithMaximumDurationAnnotation/SleeperTest.php

+56
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,62 @@ public function testSleeperSleepsShorterThanMaximumDurationFromAnnotationWhenTes
6363
self::assertSame($milliseconds, $sleeper->milliseconds());
6464
}
6565

66+
/**
67+
* @dataProvider provideDataWhereDataNameIsInteger
68+
*
69+
* @maximumDuration 200
70+
*/
71+
public function testSleeperSleepsShorterThanMaximumDurationFromAnnotationWithNumericDataProvider(): void
72+
{
73+
$milliseconds = 150;
74+
75+
$sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds);
76+
77+
$sleeper->sleep();
78+
79+
self::assertSame($milliseconds, $sleeper->milliseconds());
80+
}
81+
82+
/**
83+
* @return list<array{0: string}>
84+
*/
85+
public static function provideDataWhereDataNameIsInteger(): array
86+
{
87+
return [
88+
[
89+
'bar',
90+
],
91+
];
92+
}
93+
94+
/**
95+
* @dataProvider provideDataWhereDataNameIsString
96+
*
97+
* @maximumDuration 200
98+
*/
99+
public function testSleeperSleepsShorterThanMaximumDurationFromAnnotationWithNamedDataProvider(): void
100+
{
101+
$milliseconds = 150;
102+
103+
$sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds);
104+
105+
$sleeper->sleep();
106+
107+
self::assertSame($milliseconds, $sleeper->milliseconds());
108+
}
109+
110+
/**
111+
* @return array<string, array{0: string}>
112+
*/
113+
public static function provideDataWhereDataNameIsString(): array
114+
{
115+
return [
116+
'foo' => [
117+
'bar',
118+
],
119+
];
120+
}
121+
66122
/**
67123
* @maximumDuration 200
68124
*/

test/EndToEnd/Version07/TestMethod/WithMaximumDurationAnnotation/test.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ PHPUnit %s
1818
Runtime: %s
1919
Configuration: %s/EndToEnd/Version07/TestMethod/WithMaximumDurationAnnotation/phpunit.xml
2020

21-
.... 4 / 4 (100%)
21+
...... 6 / 6 (100%)
2222

2323
Detected 2 tests where the duration exceeded the maximum duration.
2424

@@ -27,4 +27,4 @@ Detected 2 tests where the duration exceeded the maximum duration.
2727

2828
Time: %s, Memory: %s
2929

30-
OK (4 tests, 4 assertions)
30+
OK (6 tests, 6 assertions)

test/EndToEnd/Version08/TestMethod/WithMaximumDurationAnnotation/SleeperTest.php

+56
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,62 @@ public function testSleeperSleepsShorterThanMaximumDurationFromAnnotationWhenTes
6363
self::assertSame($milliseconds, $sleeper->milliseconds());
6464
}
6565

66+
/**
67+
* @dataProvider provideDataWhereDataNameIsInteger
68+
*
69+
* @maximumDuration 200
70+
*/
71+
public function testSleeperSleepsShorterThanMaximumDurationFromAnnotationWithNumericDataProvider(): void
72+
{
73+
$milliseconds = 150;
74+
75+
$sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds);
76+
77+
$sleeper->sleep();
78+
79+
self::assertSame($milliseconds, $sleeper->milliseconds());
80+
}
81+
82+
/**
83+
* @return list<array{0: string}>
84+
*/
85+
public static function provideDataWhereDataNameIsInteger(): array
86+
{
87+
return [
88+
[
89+
'bar',
90+
],
91+
];
92+
}
93+
94+
/**
95+
* @dataProvider provideDataWhereDataNameIsString
96+
*
97+
* @maximumDuration 200
98+
*/
99+
public function testSleeperSleepsShorterThanMaximumDurationFromAnnotationWithNamedDataProvider(): void
100+
{
101+
$milliseconds = 150;
102+
103+
$sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds);
104+
105+
$sleeper->sleep();
106+
107+
self::assertSame($milliseconds, $sleeper->milliseconds());
108+
}
109+
110+
/**
111+
* @return array<string, array{0: string}>
112+
*/
113+
public static function provideDataWhereDataNameIsString(): array
114+
{
115+
return [
116+
'foo' => [
117+
'bar',
118+
],
119+
];
120+
}
121+
66122
/**
67123
* @maximumDuration 200
68124
*/

test/EndToEnd/Version08/TestMethod/WithMaximumDurationAnnotation/test.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ PHPUnit %s
1818
Runtime: %s
1919
Configuration: %s/EndToEnd/Version08/TestMethod/WithMaximumDurationAnnotation/phpunit.xml
2020

21-
.... 4 / 4 (100%)
21+
...... 6 / 6 (100%)
2222

2323
Detected 2 tests where the duration exceeded the maximum duration.
2424

@@ -27,4 +27,4 @@ Detected 2 tests where the duration exceeded the maximum duration.
2727

2828
Time: %s, Memory: %s
2929

30-
OK (4 tests, 4 assertions)
30+
OK (6 tests, 6 assertions)

test/EndToEnd/Version09/TestMethod/WithMaximumDurationAnnotation/SleeperTest.php

+56
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,62 @@ public function testSleeperSleepsShorterThanMaximumDurationFromAnnotationWhenTes
6363
self::assertSame($milliseconds, $sleeper->milliseconds());
6464
}
6565

66+
/**
67+
* @dataProvider provideDataWhereDataNameIsInteger
68+
*
69+
* @maximumDuration 200
70+
*/
71+
public function testSleeperSleepsShorterThanMaximumDurationFromAnnotationWithNumericDataProvider(): void
72+
{
73+
$milliseconds = 150;
74+
75+
$sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds);
76+
77+
$sleeper->sleep();
78+
79+
self::assertSame($milliseconds, $sleeper->milliseconds());
80+
}
81+
82+
/**
83+
* @return list<array{0: string}>
84+
*/
85+
public static function provideDataWhereDataNameIsInteger(): array
86+
{
87+
return [
88+
[
89+
'bar',
90+
],
91+
];
92+
}
93+
94+
/**
95+
* @dataProvider provideDataWhereDataNameIsString
96+
*
97+
* @maximumDuration 200
98+
*/
99+
public function testSleeperSleepsShorterThanMaximumDurationFromAnnotationWithNamedDataProvider(): void
100+
{
101+
$milliseconds = 150;
102+
103+
$sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds);
104+
105+
$sleeper->sleep();
106+
107+
self::assertSame($milliseconds, $sleeper->milliseconds());
108+
}
109+
110+
/**
111+
* @return array<string, array{0: string}>
112+
*/
113+
public static function provideDataWhereDataNameIsString(): array
114+
{
115+
return [
116+
'foo' => [
117+
'bar',
118+
],
119+
];
120+
}
121+
66122
/**
67123
* @maximumDuration 200
68124
*/

test/EndToEnd/Version09/TestMethod/WithMaximumDurationAnnotation/test.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ PHPUnit %s
1818
Runtime: %s
1919
Configuration: %s/EndToEnd/Version09/TestMethod/WithMaximumDurationAnnotation/phpunit.xml
2020

21-
.... 4 / 4 (100%)
21+
...... 6 / 6 (100%)
2222

2323
Detected 2 tests where the duration exceeded the maximum duration.
2424

@@ -27,4 +27,4 @@ Detected 2 tests where the duration exceeded the maximum duration.
2727

2828
Time: %s, Memory: %s
2929

30-
OK (4 tests, 4 assertions)
30+
OK (6 tests, 6 assertions)

0 commit comments

Comments
 (0)