Skip to content

Commit a561bbf

Browse files
Merge branch '12.3'
2 parents 4fd2c57 + edddb5e commit a561bbf

File tree

5 files changed

+65
-15
lines changed

5 files changed

+65
-15
lines changed

src/Framework/TestBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function build(ReflectionClass $theClass, string $methodName, array $grou
4949

5050
if ($this->requirementsSatisfied($className, $methodName)) {
5151
try {
52-
ErrorHandler::instance()->enterTestCaseContext($methodName);
52+
ErrorHandler::instance()->enterTestCaseContext($className, $methodName);
5353

5454
$data = (new DataProvider)->providedData($className, $methodName);
5555
} finally {

src/Runner/ErrorHandler.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,9 @@ public function useDeprecationTriggers(array $deprecationTriggers): void
282282
$this->deprecationTriggers = $deprecationTriggers;
283283
}
284284

285-
public function enterTestCaseContext(string $methodName): void
285+
public function enterTestCaseContext(string $className, string $methodName): void
286286
{
287-
$this->testCaseContext = $methodName;
287+
$this->testCaseContext = $this->testCaseContext($className, $methodName);
288288
}
289289

290290
public function leaveTestCaseContext(): void
@@ -477,8 +477,15 @@ private function triggerGlobalDeprecations(TestCase $test): void
477477
$this->__invoke(...$d);
478478
}
479479

480-
foreach ($this->testCaseContextDeprecations[$test->name()] ?? [] as $d) {
480+
$testCaseContext = $this->testCaseContext($test::class, $test->name());
481+
482+
foreach ($this->testCaseContextDeprecations[$testCaseContext] ?? [] as $d) {
481483
$this->__invoke(...$d);
482484
}
483485
}
486+
487+
private function testCaseContext(string $className, string $methodName): string
488+
{
489+
return "{$className}::{$methodName}";
490+
}
484491
}

tests/end-to-end/regression/6279.phpt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ https://github.com/sebastianbergmann/phpunit/issues/6279
55
$_SERVER['argv'][] = '--do-not-cache-result';
66
$_SERVER['argv'][] = '--no-configuration';
77
$_SERVER['argv'][] = '--display-deprecations';
8-
$_SERVER['argv'][] = __DIR__ . '/6279/';
8+
$_SERVER['argv'][] = __DIR__ . '/6279';
99

1010
require_once __DIR__ . '/../../bootstrap.php';
1111
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
@@ -14,27 +14,27 @@ PHPUnit %s by Sebastian Bergmann and contributors.
1414

1515
Runtime: %s
1616

17-
.D.DD..DD. 10 / 10 (100%)
17+
.D.DD....DD. 12 / 12 (100%)
1818

1919
Time: %s, Memory: %s
2020

2121
5 tests triggered 5 deprecations:
2222

23-
1) %sTriggersDeprecationInDataProviderTest.php:26
23+
1) %sTriggersDeprecationInDataProvider1Test.php:26
2424
some deprecation
2525

2626
Triggered by:
2727

28-
* PHPUnit\TestFixture\Issue6279\TriggersDeprecationInDataProviderTest::method2#0
29-
%sTriggersDeprecationInDataProviderTest.php:48
28+
* PHPUnit\TestFixture\Issue6279\TriggersDeprecationInDataProvider1Test::method2#0
29+
%sTriggersDeprecationInDataProvider1Test.php:48
3030

31-
* PHPUnit\TestFixture\Issue6279\TriggersDeprecationInDataProviderTest::method4#0
32-
%sTriggersDeprecationInDataProviderTest.php:61
31+
* PHPUnit\TestFixture\Issue6279\TriggersDeprecationInDataProvider1Test::method4#0
32+
%sTriggersDeprecationInDataProvider1Test.php:61
3333

34-
2) %sTriggersDeprecationInDataProviderTest.php:33
34+
2) %sTriggersDeprecationInDataProvider1Test.php:33
3535
first
3636

37-
3) %sTriggersDeprecationInDataProviderTest.php:34
37+
3) %sTriggersDeprecationInDataProvider1Test.php:34
3838
second
3939

4040
4) %sTriggersDeprecationInDataProviderUsingIgnoreDeprecationsTest.php:32
@@ -44,4 +44,4 @@ some deprecation 2
4444
some deprecation 3
4545

4646
OK, but there were issues!
47-
Tests: 10, Assertions: 10, Deprecations: 5.
47+
Tests: 12, Assertions: 12, Deprecations: 5.

tests/end-to-end/regression/6279/TriggersDeprecationInDataProviderTest.php renamed to tests/end-to-end/regression/6279/TriggersDeprecationInDataProvider1Test.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use PHPUnit\Framework\Attributes\Test;
2020
use PHPUnit\Framework\TestCase;
2121

22-
class TriggersDeprecationInDataProviderTest extends TestCase
22+
class TriggersDeprecationInDataProvider1Test extends TestCase
2323
{
2424
public static function dataProvider(): iterable
2525
{
@@ -69,4 +69,10 @@ public function method5(bool $value): void
6969
{
7070
$this->assertTrue($value);
7171
}
72+
73+
#[Test]
74+
public function methodWithSameNameThanInAnotherTest(): void
75+
{
76+
$this->assertTrue(true);
77+
}
7278
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/*
5+
* This file is part of PHPUnit.
6+
*
7+
* (c) Sebastian Bergmann <[email protected]>
8+
*
9+
* For the full copyright and license information, please view the LICENSE
10+
* file that was distributed with this source code.
11+
*/
12+
namespace PHPUnit\TestFixture\Issue6279;
13+
14+
use const E_USER_DEPRECATED;
15+
use function trigger_error;
16+
use PHPUnit\Framework\Attributes\DataProvider;
17+
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
18+
use PHPUnit\Framework\Attributes\Test;
19+
use PHPUnit\Framework\TestCase;
20+
21+
class TriggersDeprecationInDataProvider2Test extends TestCase
22+
{
23+
public static function dataProvider(): iterable
24+
{
25+
@trigger_error('some deprecation 1', E_USER_DEPRECATED);
26+
27+
yield [true];
28+
}
29+
30+
#[Test]
31+
#[DataProvider('dataProvider')]
32+
#[IgnoreDeprecations]
33+
public function methodWithSameNameThanInAnotherTest(bool $value): void
34+
{
35+
$this->assertTrue($value);
36+
}
37+
}

0 commit comments

Comments
 (0)