Skip to content

Commit e05f65e

Browse files
Merge branch '12.4' into 12.5
* 12.4: Fix CS/WS issues Update ChangeLog Fix WS issue fix: test IgnorePhpunitWarnings pattern in Emitter fix: ClassMethod for DataProvider events should be passed the real test class
2 parents cfe3cf9 + ace7c78 commit e05f65e

File tree

6 files changed

+79
-48
lines changed

6 files changed

+79
-48
lines changed

src/Event/Emitter/DispatchingEmitter.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use function assert;
1313
use function memory_reset_peak_usage;
14+
use function preg_match;
1415
use PHPUnit\Event\Code\ClassMethod;
1516
use PHPUnit\Event\Code\ComparisonFailure;
1617
use PHPUnit\Event\Code\IssueTrigger\IssueTrigger;
@@ -1020,7 +1021,9 @@ public function testTriggeredPhpunitWarning(Code\Test $test, string $message): v
10201021
if (isset($metadata[0])) {
10211022
assert($metadata[0] instanceof IgnorePhpunitWarnings);
10221023

1023-
if ($metadata[0]->shouldIgnore($message)) {
1024+
$messagePattern = $metadata[0]->messagePattern();
1025+
1026+
if ($messagePattern === null || (bool) preg_match('{' . $messagePattern . '}', $message)) {
10241027
$ignoredByTest = true;
10251028
}
10261029
}

src/Metadata/Api/DataProvider.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,23 @@ public function providedData(string $className, string $methodName): ?array
6262
$this->triggerWarningForMixingOfDataProviderAndTestWith($testMethod);
6363
}
6464

65-
return $this->dataProvidedByMethods($testMethod, $dataProvider);
65+
return $this->dataProvidedByMethods($className, $testMethod, $dataProvider);
6666
}
6767

6868
return $this->dataProvidedByMetadata($testMethod, $testWith);
6969
}
7070

7171
/**
72+
* @param class-string<TestCase> $testClassName
73+
*
7274
* @throws InvalidDataProviderException
7375
*
7476
* @return array<ProvidedData>
7577
*/
76-
private function dataProvidedByMethods(ReflectionMethod $testMethod, MetadataCollection $dataProvider): array
78+
private function dataProvidedByMethods(string $testClassName, ReflectionMethod $testMethod, MetadataCollection $dataProvider): array
7779
{
7880
$testMethodValueObject = new Event\Code\ClassMethod(
79-
$testMethod->getDeclaringClass()->getName(),
81+
$testClassName,
8082
$testMethod->getName(),
8183
);
8284

src/Metadata/IgnorePhpunitWarnings.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
*/
1010
namespace PHPUnit\Metadata;
1111

12-
use function preg_match;
13-
1412
/**
1513
* @immutable
1614
*
@@ -37,9 +35,11 @@ public function isIgnorePhpunitWarnings(): true
3735
return true;
3836
}
3937

40-
public function shouldIgnore(string $message): bool
38+
/**
39+
* @return null|non-empty-string
40+
*/
41+
public function messagePattern(): ?string
4142
{
42-
return $this->messagePattern === null ||
43-
(bool) preg_match('{' . $this->messagePattern . '}', $message);
43+
return $this->messagePattern;
4444
}
4545
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TestFixture\Event;
11+
12+
use PHPUnit\Framework\Attributes\DataProvider;
13+
use PHPUnit\Framework\TestCase;
14+
15+
final class DataProviderInParentTest extends ParentTestCase
16+
{
17+
}
18+
19+
abstract class ParentTestCase extends TestCase
20+
{
21+
public static function data_provider(): iterable
22+
{
23+
yield [true];
24+
}
25+
26+
#[DataProvider('data_provider')]
27+
public function testSomething(bool $var): void
28+
{
29+
$this->assertTrue($var);
30+
}
31+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
The right events are emitted in the right order for a test that uses a data provider that provides no data
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = '--debug';
8+
$_SERVER['argv'][] = __DIR__ . '/_files/DataProviderInParentTest.php';
9+
10+
require __DIR__ . '/../../bootstrap.php';
11+
12+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
13+
--EXPECTF--
14+
PHPUnit Started (PHPUnit %s using %s)
15+
Test Runner Configured
16+
Event Facade Sealed
17+
Data Provider Method Called (PHPUnit\TestFixture\Event\DataProviderInParentTest::data_provider for test method PHPUnit\TestFixture\Event\DataProviderInParentTest::testSomething)
18+
Data Provider Method Finished for PHPUnit\TestFixture\Event\DataProviderInParentTest::testSomething:
19+
- PHPUnit\TestFixture\Event\DataProviderInParentTest::data_provider
20+
Test Suite Loaded (1 test)
21+
Test Runner Started
22+
Test Suite Sorted
23+
Test Runner Execution Started (1 test)
24+
Test Suite Started (PHPUnit\TestFixture\Event\DataProviderInParentTest, 1 test)
25+
Test Suite Started (PHPUnit\TestFixture\Event\DataProviderInParentTest::testSomething, 1 test)
26+
Test Preparation Started (PHPUnit\TestFixture\Event\DataProviderInParentTest::testSomething#0)
27+
Test Prepared (PHPUnit\TestFixture\Event\DataProviderInParentTest::testSomething#0)
28+
Test Passed (PHPUnit\TestFixture\Event\DataProviderInParentTest::testSomething#0)
29+
Test Finished (PHPUnit\TestFixture\Event\DataProviderInParentTest::testSomething#0)
30+
Test Suite Finished (PHPUnit\TestFixture\Event\DataProviderInParentTest::testSomething, 1 test)
31+
Test Suite Finished (PHPUnit\TestFixture\Event\DataProviderInParentTest, 1 test)
32+
Test Runner Execution Finished
33+
Test Runner Finished
34+
PHPUnit Finished (Shell Exit Code: 0)

tests/unit/Metadata/IgnorePhpunitWarningsTest.php

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)