Skip to content

Commit 1404b36

Browse files
Refactor
1 parent b9dd1c6 commit 1404b36

File tree

1 file changed

+16
-27
lines changed

1 file changed

+16
-27
lines changed

src/Framework/TestCase.php

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ abstract class TestCase extends Assert implements Reorderable, SelfDescribing, T
160160
/**
161161
* @psalm-var non-empty-string
162162
*/
163-
private string $name;
163+
private string $methodName;
164164

165165
/**
166166
* @psalm-var list<string>
@@ -225,9 +225,12 @@ abstract class TestCase extends Assert implements Reorderable, SelfDescribing, T
225225
*/
226226
public function __construct(string $name)
227227
{
228-
$this->setName($name);
228+
$this->methodName = $name;
229+
$this->status = TestStatus::unknown();
229230

230-
$this->status = TestStatus::unknown();
231+
if (is_callable($this->sortId(), true)) {
232+
$this->providedTests = [new ExecutionOrderDependency($this->sortId())];
233+
}
231234
}
232235

233236
/**
@@ -288,7 +291,7 @@ public function toString(): string
288291
$buffer = sprintf(
289292
'%s::%s',
290293
(new ReflectionClass($this))->getName(),
291-
$this->name,
294+
$this->methodName,
292295
);
293296

294297
return $buffer . $this->dataSetAsStringWithData();
@@ -362,7 +365,7 @@ final public function setGroups(array $groups): void
362365
*/
363366
final public function nameWithDataSet(): string
364367
{
365-
return $this->name . $this->dataSetAsString();
368+
return $this->methodName . $this->dataSetAsString();
366369
}
367370

368371
/**
@@ -372,7 +375,7 @@ final public function nameWithDataSet(): string
372375
*/
373376
final public function name(): string
374377
{
375-
return $this->name;
378+
return $this->methodName;
376379
}
377380

378381
/**
@@ -382,7 +385,7 @@ final public function size(): TestSize
382385
{
383386
return (new Groups)->size(
384387
static::class,
385-
$this->name,
388+
$this->methodName,
386389
);
387390
}
388391

@@ -463,8 +466,8 @@ final public function runBare(): void
463466
$this->invokeBeforeClassHookMethods($hookMethods, $emitter);
464467
}
465468

466-
if (method_exists(static::class, $this->name) &&
467-
MetadataRegistry::parser()->forClassAndMethod(static::class, $this->name)->isDoesNotPerformAssertions()->isNotEmpty()) {
469+
if (method_exists(static::class, $this->methodName) &&
470+
MetadataRegistry::parser()->forClassAndMethod(static::class, $this->methodName)->isDoesNotPerformAssertions()->isNotEmpty()) {
468471
$this->doesNotPerformAssertions = true;
469472
}
470473

@@ -622,20 +625,6 @@ final public function runBare(): void
622625
}
623626
}
624627

625-
/**
626-
* @psalm-param non-empty-string $name
627-
*
628-
* @internal This method is not covered by the backward compatibility promise for PHPUnit
629-
*/
630-
final public function setName(string $name): void
631-
{
632-
$this->name = $name;
633-
634-
if (is_callable($this->sortId(), true)) {
635-
$this->providedTests = [new ExecutionOrderDependency($this->sortId())];
636-
}
637-
}
638-
639628
/**
640629
* @psalm-param list<ExecutionOrderDependency> $dependencies
641630
*
@@ -848,7 +837,7 @@ final public function providedData(): array
848837
*/
849838
final public function sortId(): string
850839
{
851-
$id = $this->name;
840+
$id = $this->methodName;
852841

853842
if (!str_contains($id, '::')) {
854843
$id = static::class . '::' . $id;
@@ -1181,7 +1170,7 @@ final protected function runTest(): mixed
11811170
$testArguments = array_merge($this->data, array_values($this->dependencyInput));
11821171

11831172
try {
1184-
$testResult = $this->{$this->name}(...$testArguments);
1173+
$testResult = $this->{$this->methodName}(...$testArguments);
11851174
} catch (Throwable $exception) {
11861175
if (!$this->shouldExceptionExpectationsBeVerified($exception)) {
11871176
throw $exception;
@@ -1665,13 +1654,13 @@ private function verifyMockObjects(): void
16651654
*/
16661655
private function checkRequirements(): void
16671656
{
1668-
if (!$this->name || !method_exists($this, $this->name)) {
1657+
if (!$this->methodName || !method_exists($this, $this->methodName)) {
16691658
return;
16701659
}
16711660

16721661
$missingRequirements = (new Requirements)->requirementsNotSatisfiedFor(
16731662
static::class,
1674-
$this->name,
1663+
$this->methodName,
16751664
);
16761665

16771666
if (!empty($missingRequirements)) {

0 commit comments

Comments
 (0)