Skip to content

Commit 3a3b102

Browse files
Refactor
1 parent 191477f commit 3a3b102

File tree

9 files changed

+75
-48
lines changed

9 files changed

+75
-48
lines changed

.psalm/baseline.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@
10111011
<code><![CDATA[self::$directories]]></code>
10121012
</InvalidPropertyAssignmentValue>
10131013
</file>
1014-
<file src="src/Util/PHP/DefaultPhpJobRunner.php">
1014+
<file src="src/Util/PHP/DefaultJobRunner.php">
10151015
<DocblockTypeContradiction>
10161016
<code><![CDATA[is_array($value)]]></code>
10171017
</DocblockTypeContradiction>

src/Framework/TestRunner.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
use PHPUnit\TextUI\Configuration\Configuration;
4343
use PHPUnit\TextUI\Configuration\Registry as ConfigurationRegistry;
4444
use PHPUnit\Util\GlobalState;
45-
use PHPUnit\Util\PHP\PhpJob;
46-
use PHPUnit\Util\PHP\PhpJobRunnerRegistry;
45+
use PHPUnit\Util\PHP\Job;
46+
use PHPUnit\Util\PHP\JobRunnerRegistry;
4747
use PHPUnit\Util\PHP\PhpProcessException;
4848
use ReflectionClass;
4949
use SebastianBergmann\CodeCoverage\Exception as OriginalCodeCoverageException;
@@ -497,7 +497,7 @@ private function shouldErrorHandlerBeUsed(TestCase $test): bool
497497
*/
498498
private function runTestJob(string $code, Test $test, string $processResultFile): void
499499
{
500-
$_result = PhpJobRunnerRegistry::run(new PhpJob($code));
500+
$result = JobRunnerRegistry::run(new Job($code));
501501

502502
$processResult = '';
503503

@@ -510,7 +510,7 @@ private function runTestJob(string $code, Test $test, string $processResultFile)
510510
$this->processChildResult(
511511
$test,
512512
$processResult,
513-
$_result['stderr'],
513+
$result->stderr(),
514514
);
515515
}
516516

src/Runner/PhptTestCase.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
use PHPUnit\Framework\SelfDescribing;
5656
use PHPUnit\Framework\Test;
5757
use PHPUnit\TextUI\Configuration\Registry as ConfigurationRegistry;
58-
use PHPUnit\Util\PHP\PhpJob;
59-
use PHPUnit\Util\PHP\PhpJobRunnerRegistry;
58+
use PHPUnit\Util\PHP\Job;
59+
use PHPUnit\Util\PHP\JobRunnerRegistry;
6060
use SebastianBergmann\CodeCoverage\Data\RawCodeCoverageData;
6161
use SebastianBergmann\CodeCoverage\InvalidArgumentException;
6262
use SebastianBergmann\CodeCoverage\ReflectionException;
@@ -183,8 +183,8 @@ public function run(): void
183183
);
184184
}
185185

186-
$jobResult = PhpJobRunnerRegistry::run(
187-
new PhpJob(
186+
$jobResult = JobRunnerRegistry::run(
187+
new Job(
188188
$code,
189189
$this->stringifyIni($phpSettings),
190190
$environmentVariables,
@@ -194,7 +194,7 @@ public function run(): void
194194
),
195195
);
196196

197-
$this->output = $jobResult['stdout'] ?? '';
197+
$this->output = $jobResult->stdout();
198198

199199
if (CodeCoverage::instance()->isActive()) {
200200
$coverage = $this->cleanupForCoverage();
@@ -399,17 +399,17 @@ private function shouldTestBeSkipped(array $sections, array $settings): bool
399399
return false;
400400
}
401401

402-
$jobResult = PhpJobRunnerRegistry::run(
403-
new PhpJob(
402+
$jobResult = JobRunnerRegistry::run(
403+
new Job(
404404
$this->render($sections['SKIPIF']),
405405
$this->stringifyIni($settings),
406406
),
407407
);
408408

409-
if (!strncasecmp('skip', ltrim($jobResult['stdout']), 4)) {
409+
if (!strncasecmp('skip', ltrim($jobResult->stdout()), 4)) {
410410
$message = '';
411411

412-
if (preg_match('/^\s*skip\s*(.+)\s*/i', $jobResult['stdout'], $skipMatch)) {
412+
if (preg_match('/^\s*skip\s*(.+)\s*/i', $jobResult->stdout(), $skipMatch)) {
413413
$message = substr($skipMatch[1], 2);
414414
}
415415

@@ -432,8 +432,8 @@ private function runClean(array $sections, bool $collectCoverage): void
432432
return;
433433
}
434434

435-
PhpJobRunnerRegistry::run(
436-
new PhpJob(
435+
JobRunnerRegistry::run(
436+
new Job(
437437
$this->render($sections['CLEAN']),
438438
$this->settings($collectCoverage),
439439
),

src/Util/PHP/DefaultPhpJobRunner.php renamed to src/Util/PHP/DefaultJobRunner.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,12 @@
3232
/**
3333
* @internal This class is not covered by the backward compatibility promise for PHPUnit
3434
*/
35-
final readonly class DefaultPhpJobRunner implements PhpJobRunner
35+
final readonly class DefaultJobRunner implements JobRunner
3636
{
3737
/**
38-
* @psalm-return array{stdout: string, stderr: string}
39-
*
4038
* @throws PhpProcessException
4139
*/
42-
public function run(PhpJob $job): array
40+
public function run(Job $job): Result
4341
{
4442
$temporaryFile = null;
4543

@@ -53,7 +51,7 @@ public function run(PhpJob $job): array
5351
);
5452
}
5553

56-
$job = new PhpJob(
54+
$job = new Job(
5755
$job->input(),
5856
$job->phpSettings(),
5957
$job->environmentVariables(),
@@ -71,11 +69,9 @@ public function run(PhpJob $job): array
7169
/**
7270
* @psalm-param ?non-empty-string $temporaryFile
7371
*
74-
* @psalm-return array{stdout: string, stderr: string}
75-
*
7672
* @throws PhpProcessException
7773
*/
78-
private function runProcess(PhpJob $job, ?string $temporaryFile): array
74+
private function runProcess(Job $job, ?string $temporaryFile): Result
7975
{
8076
$environmentVariables = null;
8177

@@ -144,13 +140,13 @@ private function runProcess(PhpJob $job, ?string $temporaryFile): array
144140
unlink($temporaryFile);
145141
}
146142

147-
return ['stdout' => $stdout, 'stderr' => $stderr];
143+
return new Result($stdout, $stderr);
148144
}
149145

150146
/**
151147
* @psalm-return non-empty-list<string>
152148
*/
153-
private function buildCommand(PhpJob $job, ?string $file): array
149+
private function buildCommand(Job $job, ?string $file): array
154150
{
155151
$runtime = new Runtime;
156152
$command = [PHP_BINARY];

src/Util/PHP/PhpJob.php renamed to src/Util/PHP/Job.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
* @internal This class is not covered by the backward compatibility promise for PHPUnit
1616
*/
17-
final readonly class PhpJob
17+
final readonly class Job
1818
{
1919
/**
2020
* @psalm-var non-empty-string

src/Util/PHP/PhpJobRunner.php renamed to src/Util/PHP/JobRunner.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
/**
1313
* @internal This interface is not covered by the backward compatibility promise for PHPUnit
1414
*/
15-
interface PhpJobRunner
15+
interface JobRunner
1616
{
17-
/**
18-
* @psalm-return array{stdout: string, stderr: string}
19-
*/
20-
public function run(PhpJob $job): array;
17+
public function run(Job $job): Result;
2118
}

src/Util/PHP/PhpJobRunnerRegistry.php renamed to src/Util/PHP/JobRunnerRegistry.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,20 @@
1212
/**
1313
* @internal This class is not covered by the backward compatibility promise for PHPUnit
1414
*/
15-
final class PhpJobRunnerRegistry
15+
final class JobRunnerRegistry
1616
{
17-
private static ?PhpJobRunner $runner = null;
17+
private static ?JobRunner $runner = null;
1818

19-
/**
20-
* @psalm-return array{stdout: string, stderr: string}
21-
*/
22-
public static function run(PhpJob $job): array
19+
public static function run(Job $job): Result
2320
{
2421
if (self::$runner === null) {
25-
self::$runner = new DefaultPhpJobRunner;
22+
self::$runner = new DefaultJobRunner;
2623
}
2724

2825
return self::$runner->run($job);
2926
}
3027

31-
public static function set(PhpJobRunner $runner): void
28+
public static function set(JobRunner $runner): void
3229
{
3330
self::$runner = $runner;
3431
}

src/Util/PHP/Result.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <sebastian@phpunit.de>
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\Util\PHP;
11+
12+
/**
13+
* @psalm-immutable
14+
*
15+
* @internal This class is not covered by the backward compatibility promise for PHPUnit
16+
*/
17+
final readonly class Result
18+
{
19+
private string $stdout;
20+
private string $stderr;
21+
22+
public function __construct(string $stdout, string $stderr)
23+
{
24+
$this->stdout = $stdout;
25+
$this->stderr = $stderr;
26+
}
27+
28+
public function stdout(): string
29+
{
30+
return $this->stdout;
31+
}
32+
33+
public function stderr(): string
34+
{
35+
return $this->stderr;
36+
}
37+
}

tests/unit/Util/PHP/PhpJobTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
use PHPUnit\Framework\Attributes\Small;
1414
use PHPUnit\Framework\TestCase;
1515

16-
#[CoversClass(PhpJob::class)]
16+
#[CoversClass(Job::class)]
1717
#[Small]
1818
final class PhpJobTest extends TestCase
1919
{
2020
public function testHasCode(): void
2121
{
2222
$code = 'the-code';
2323

24-
$job = new PhpJob(
24+
$job = new Job(
2525
$code,
2626
[],
2727
[],
@@ -41,7 +41,7 @@ public function testMayHavePhpSettings(): void
4141
{
4242
$phpSettings = ['foo' => 'bar'];
4343

44-
$job = new PhpJob(
44+
$job = new Job(
4545
'the-code',
4646
$phpSettings,
4747
[],
@@ -61,7 +61,7 @@ public function testMayHaveEnvironmentVariables(): void
6161
{
6262
$environmentVariables = ['foo' => 'bar'];
6363

64-
$job = new PhpJob(
64+
$job = new Job(
6565
'the-code',
6666
[],
6767
$environmentVariables,
@@ -81,7 +81,7 @@ public function testMayHaveArguments(): void
8181
{
8282
$arguments = ['foo', 'bar'];
8383

84-
$job = new PhpJob(
84+
$job = new Job(
8585
'the-code',
8686
[],
8787
[],
@@ -102,7 +102,7 @@ public function testMayHaveInput(): void
102102
{
103103
$input = 'the-input';
104104

105-
$job = new PhpJob(
105+
$job = new Job(
106106
'the-code',
107107
[],
108108
[],
@@ -120,7 +120,7 @@ public function testMayHaveInput(): void
120120

121121
public function testMayNotHaveInput(): void
122122
{
123-
$job = new PhpJob(
123+
$job = new Job(
124124
'the-code',
125125
[],
126126
[],
@@ -138,7 +138,7 @@ public function testMayNotHaveInput(): void
138138

139139
public function testMayRedirectErrors(): void
140140
{
141-
$job = new PhpJob(
141+
$job = new Job(
142142
'the-code',
143143
[],
144144
[],

0 commit comments

Comments
 (0)