Skip to content

Commit 6858204

Browse files
Refactor
1 parent abbb373 commit 6858204

File tree

6 files changed

+29
-19
lines changed

6 files changed

+29
-19
lines changed

.psalm/baseline.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@
11831183
<code>doesNotPerformAssertions</code>
11841184
<code>doesNotPerformAssertions</code>
11851185
<code>getActualOutput</code>
1186-
<code>getAnnotations</code>
1186+
<code>getName</code>
11871187
<code>getName</code>
11881188
<code>getNumAssertions</code>
11891189
<code>getNumAssertions</code>
@@ -2029,10 +2029,11 @@
20292029
<MissingReturnType occurrences="1">
20302030
<code>sanitizeVersionNumber</code>
20312031
</MissingReturnType>
2032-
<MissingThrowsDocblock occurrences="5">
2032+
<MissingThrowsDocblock occurrences="6">
20332033
<code>forClassName</code>
20342034
<code>forMethod</code>
20352035
<code>forMethod</code>
2036+
<code>getName</code>
20362037
<code>requirements</code>
20372038
<code>requirements</code>
20382039
</MissingThrowsDocblock>

src/Framework/TestCase.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -936,17 +936,6 @@ public function setGroups(array $groups): void
936936
$this->groups = $groups;
937937
}
938938

939-
/**
940-
* @internal This method is not covered by the backward compatibility promise for PHPUnit
941-
*/
942-
public function getAnnotations(): array
943-
{
944-
return TestUtil::parseTestMethodAnnotations(
945-
static::class,
946-
$this->name
947-
);
948-
}
949-
950939
/**
951940
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
952941
*
@@ -2449,7 +2438,10 @@ private function registerMockObjectsFromTestArguments(array $testArguments, arra
24492438

24502439
private function setDoesNotPerformAssertionsFromAnnotation(): void
24512440
{
2452-
$annotations = $this->getAnnotations();
2441+
$annotations = TestUtil::parseTestMethodAnnotations(
2442+
static::class,
2443+
$this->name
2444+
);
24532445

24542446
if (isset($annotations['method']['doesNotPerformAssertions'])) {
24552447
$this->doesNotPerformAssertions = true;

src/Framework/TestResult.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,10 @@ function_exists('xdebug_start_function_monitor');
811811
}
812812

813813
if ($this->forceCoversAnnotation && !$error && !$failure && !$warning && !$incomplete && !$skipped && !$risky) {
814-
$annotations = $test->getAnnotations();
814+
$annotations = TestUtil::parseTestMethodAnnotations(
815+
get_class($test),
816+
$test->getName(false)
817+
);
815818

816819
if (!isset($annotations['class']['covers']) &&
817820
!isset($annotations['method']['covers']) &&
@@ -957,7 +960,10 @@ function_exists('xdebug_start_function_monitor');
957960
$time
958961
);
959962
} elseif ($this->beStrictAboutTodoAnnotatedTests && $test instanceof TestCase) {
960-
$annotations = $test->getAnnotations();
963+
$annotations = TestUtil::parseTestMethodAnnotations(
964+
get_class($test),
965+
$test->getName(false)
966+
);
961967

962968
if (isset($annotations['method']['todo'])) {
963969
$this->addFailure(

src/Util/Test.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ public static function getLinesToBeUsed(string $className, string $methodName):
142142

143143
public static function requiresCodeCoverageDataCollection(TestCase $test): bool
144144
{
145-
$annotations = $test->getAnnotations();
145+
$annotations = self::parseTestMethodAnnotations(
146+
get_class($test),
147+
$test->getName(false)
148+
);
146149

147150
// If there is no @covers annotation but a @coversNothing annotation on
148151
// the test method then code coverage data does not need to be collected

src/Util/TestDox/NamePrettifier.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,11 @@ public function prettifyTestClass(string $className): string
140140
*/
141141
public function prettifyTestCase(TestCase $test): string
142142
{
143-
$annotations = $test->getAnnotations();
143+
$annotations = Test::parseTestMethodAnnotations(
144+
get_class($test),
145+
$test->getName(false)
146+
);
147+
144148
$annotationWithPlaceholders = false;
145149

146150
$callback = static function (string $variable): string {

src/Util/TestDox/XmlResultPrinter.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use PHPUnit\Framework\TestSuite;
2424
use PHPUnit\Framework\Warning;
2525
use PHPUnit\Util\Printer;
26+
use PHPUnit\Util\Test as TestUtil;
2627
use ReflectionClass;
2728
use ReflectionException;
2829
use Throwable;
@@ -183,7 +184,10 @@ static function ($group) {
183184
$testNode->appendChild($groupNode);
184185
}
185186

186-
$annotations = $test->getAnnotations();
187+
$annotations = TestUtil::parseTestMethodAnnotations(
188+
get_class($test),
189+
$test->getName(false)
190+
);
187191

188192
foreach (['class', 'method'] as $type) {
189193
foreach ($annotations[$type] as $annotation => $values) {

0 commit comments

Comments
 (0)