Skip to content

Commit 78e5cf2

Browse files
committed
refactor: rename mock methods
1 parent 44ff54b commit 78e5cf2

File tree

9 files changed

+39
-39
lines changed

9 files changed

+39
-39
lines changed

packages/process/src/Testing/ProcessTester.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function recordProcessExecutions(): void
3131
{
3232
$this->executor ??= new TestingProcessExecutor(
3333
executor: new GenericProcessExecutor(),
34-
registeredProcessResult: [],
34+
mocks: [],
3535
allowRunningActualProcesses: $this->allowRunningActualProcesses,
3636
);
3737

@@ -41,11 +41,11 @@ public function recordProcessExecutions(): void
4141
/**
4242
* Sets up the specified command or pattern to return the specified result.
4343
*/
44-
public function registerProcessResult(string $command, string|ProcessResult $result): self
44+
public function mockProcess(string $command, string|ProcessResult $result): self
4545
{
4646
$this->recordProcessExecutions();
4747

48-
$this->executor->registeredProcessResult[$command] = $result;
48+
$this->executor->mocks[$command] = $result;
4949

5050
return $this;
5151
}
@@ -55,12 +55,12 @@ public function registerProcessResult(string $command, string|ProcessResult $res
5555
*
5656
* @var array<string,string|ProcessResult> $results
5757
*/
58-
public function registerProcessResults(array $results): self
58+
public function mockProcesses(array $results): self
5959
{
6060
$this->recordProcessExecutions();
6161

6262
foreach ($results as $command => $result) {
63-
$this->executor->registeredProcessResult[$command] = $result;
63+
$this->executor->mocks[$command] = $result;
6464
}
6565

6666
return $this;

packages/process/src/Testing/TestingProcessExecutor.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ final class TestingProcessExecutor implements ProcessExecutor
2020
private(set) array $executions = [];
2121

2222
/**
23-
* @param array<string|ProcessResult> $registeredProcessResult
23+
* @param array<string|ProcessResult> $mocks
2424
*/
2525
public function __construct(
2626
private readonly GenericProcessExecutor $executor,
27-
public array $registeredProcessResult = [],
27+
public array $mocks = [],
2828
public bool $allowRunningActualProcesses = false,
2929
) {}
3030

3131
public function run(array|string|PendingProcess $command): ProcessResult
3232
{
33-
if ($result = $this->findRegisteredProcessResult($command)) {
33+
if ($result = $this->findMockedProcess($command)) {
3434
return $this->recordExecution($command, $result);
3535
}
3636

@@ -69,11 +69,11 @@ public function concurrently(iterable $pool): ProcessPoolResults
6969
return $this->pool($pool)->start()->wait();
7070
}
7171

72-
private function findRegisteredProcessResult(array|string|PendingProcess $command): ?ProcessResult
72+
private function findMockedProcess(array|string|PendingProcess $command): ?ProcessResult
7373
{
7474
$process = $this->createPendingProcess($command);
7575

76-
foreach ($this->registeredProcessResult as $command => $result) {
76+
foreach ($this->mocks as $command => $result) {
7777
if (! Regex\matches($process->command, $this->buildRegExpFromString($command))) {
7878
continue;
7979
}
@@ -96,7 +96,7 @@ private function findInvokedProcessDescription(array|string|PendingProcess $comm
9696
{
9797
$process = $this->createPendingProcess($command);
9898

99-
foreach ($this->registeredProcessResult as $command => $result) {
99+
foreach ($this->mocks as $command => $result) {
100100
if (! $this->commandMatchesPattern($process->command, $command)) {
101101
continue;
102102
}

src/Tempest/Framework/Testing/InstallerTester.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(
2929

3030
public function configure(string $root, Psr4Namespace $namespace): self
3131
{
32-
$this->process->registerProcessResult('*', '');
32+
$this->process->mockProcess('*', '');
3333

3434
$this->root = $root;
3535
$this->container->get(FrameworkKernel::class)->root = $root;

tests/Integration/Console/Scheduler/GenericSchedulerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected function setUp(): void
3737

3838
public function test_scheduler_executes_handlers(): void
3939
{
40-
$this->process->registerProcessResult('*', '');
40+
$this->process->mockProcess('*', '');
4141

4242
$config = new SchedulerConfig();
4343

@@ -58,7 +58,7 @@ public function test_scheduler_executes_handlers(): void
5858

5959
public function test_scheduler_executes_commands(): void
6060
{
61-
$this->process->registerProcessResult('*', '');
61+
$this->process->mockProcess('*', '');
6262

6363
$config = new SchedulerConfig();
6464

@@ -79,7 +79,7 @@ public function test_scheduler_executes_commands(): void
7979

8080
public function test_scheduler_only_dispatches_the_command_in_desired_times(): void
8181
{
82-
$this->process->registerProcessResult('*', '');
82+
$this->process->mockProcess('*', '');
8383
$at = new DateTime('2024-05-01 00:00:00');
8484

8585
$config = new SchedulerConfig();

tests/Integration/Console/Scheduler/ScheduleRunCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class ScheduleRunCommandTest extends FrameworkIntegrationTestCase
1414
{
1515
public function test_invoke(): void
1616
{
17-
$this->process->registerProcessResult('*', '');
17+
$this->process->mockProcess('*', '');
1818

1919
@unlink(GenericScheduler::getCachePath());
2020

tests/Integration/Process/ProcessExecutorTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ final class ProcessExecutorTest extends FrameworkIntegrationTestCase
1717

1818
public function test_run(): void
1919
{
20-
$this->process->registerProcessResult('echo *', "Hello\n");
20+
$this->process->mockProcess('echo *', "Hello\n");
2121

2222
$result = $this->executor->run('echo "Hello"');
2323

@@ -28,7 +28,7 @@ public function test_run(): void
2828

2929
public function test_describe_and_assert_async_process(): void
3030
{
31-
$this->process->registerProcessResults([
31+
$this->process->mockProcesses([
3232
'echo *' => $this->process
3333
->describe()
3434
->output('hello')
@@ -59,7 +59,7 @@ public function test_describe_and_assert_async_process(): void
5959

6060
public function test_concurrently(): void
6161
{
62-
$this->process->registerProcessResults([
62+
$this->process->mockProcesses([
6363
'echo "hello"' => $this->process->describe()->output('hello'),
6464
'echo "world"' => $this->process->describe()->output('world'),
6565
]);
@@ -79,7 +79,7 @@ public function test_concurrently(): void
7979

8080
public function test_pool(): void
8181
{
82-
$this->process->registerProcessResults([
82+
$this->process->mockProcesses([
8383
'echo "hello"' => $this->process->describe()->output('hello'),
8484
'echo "world"' => $this->process->describe()->output('world'),
8585
]);

tests/Integration/Process/ProcessTesterAssertNotRanTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function test_succeeds_with_callback_when_no_command_ran(): void
2727

2828
public function test_succeeds_with_callback_when_other_commands_ran(): void
2929
{
30-
$this->process->registerProcessResult('echo *', 'hello');
30+
$this->process->mockProcess('echo *', 'hello');
3131
$this->executor->run('echo "hello"');
3232

3333
$this->process->assertCommandDidNotRun(function (PendingProcess $process) {
@@ -41,7 +41,7 @@ public function test_fails_with_callback_when_returning_false(): void
4141
$this->expectException(ExpectationFailedException::class);
4242
$this->expectExceptionMessage('Callback for command "echo "hello"" returned true.');
4343

44-
$this->process->registerProcessResult('echo *', 'hello');
44+
$this->process->mockProcess('echo *', 'hello');
4545
$this->executor->run('echo "hello"');
4646

4747
$this->process->assertCommandDidNotRun(function (PendingProcess $process) {

tests/Integration/Process/ProcessTesterAssertRanTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ final class ProcessTesterAssertRanTest extends FrameworkIntegrationTestCase
2020
#[TestWith(['echo "hello"'])]
2121
public function test_expectation_succeeds_when_command_is_ran(string $pattern): void
2222
{
23-
$this->process->registerProcessResult('echo *', "hello\n");
23+
$this->process->mockProcess('echo *', "hello\n");
2424
$this->executor->run('echo "hello"');
2525
$this->process->assertCommandRan($pattern);
2626
}
2727

2828
public function test_expectation_succeeds_when_command_is_ran_and_callback_returns_true(): void
2929
{
30-
$this->process->registerProcessResult('echo *', "hello\n");
30+
$this->process->mockProcess('echo *', "hello\n");
3131
$this->executor->run('echo "hello"');
3232
$this->process->assertCommandRan('echo *', function (ProcessResult $result) {
3333
return $result->output === "hello\n";
@@ -39,7 +39,7 @@ public function test_expectation_fails_when_specified_command_is_not_ran(): void
3939
$this->expectException(ExpectationFailedException::class);
4040
$this->expectExceptionMessage('Expected process with command "not-ran" to be executed, but it was not.');
4141

42-
$this->process->registerProcessResult('echo *', "hello\n");
42+
$this->process->mockProcess('echo *', "hello\n");
4343
$this->executor->run('echo "hello"');
4444
$this->process->assertCommandRan('not-ran');
4545
}
@@ -49,7 +49,7 @@ public function test_expectation_fails_when_command_is_ran_and_callback_returns_
4949
$this->expectException(ExpectationFailedException::class);
5050
$this->expectExceptionMessage('Callback for command "echo "hello"" returned false.');
5151

52-
$this->process->registerProcessResult('echo *', "hello\n");
52+
$this->process->mockProcess('echo *', "hello\n");
5353
$this->executor->run('echo "hello"');
5454
$this->process->assertCommandRan('echo *', function (ProcessResult $result) {
5555
return $result->output !== "hello\n";
@@ -58,14 +58,14 @@ public function test_expectation_fails_when_command_is_ran_and_callback_returns_
5858

5959
public function test_expectation_succeeds_when_callback_returns_nothing(): void
6060
{
61-
$this->process->registerProcessResult('echo *', "hello\n");
61+
$this->process->mockProcess('echo *', "hello\n");
6262
$this->executor->run('echo "hello"');
6363
$this->process->assertCommandRan('echo *', function (): void {});
6464
}
6565

6666
public function test_expectation_succeeds_when_callback_returns_true(): void
6767
{
68-
$this->process->registerProcessResult('echo *', "hello\n");
68+
$this->process->mockProcess('echo *', "hello\n");
6969
$this->executor->run('echo "hello"');
7070

7171
$this->process->assertRan(function (PendingProcess $process): bool {
@@ -78,7 +78,7 @@ public function test_returning_false_from_callback_fails_expectation(): void
7878
$this->expectException(ExpectationFailedException::class);
7979
$this->expectExceptionMessage('Callback for command "echo "hello"" returned false.');
8080

81-
$this->process->registerProcessResult('echo *', "hello\n");
81+
$this->process->mockProcess('echo *', "hello\n");
8282
$this->executor->run('echo "hello"');
8383

8484
$this->process->assertRan(function (PendingProcess $_process): bool {
@@ -88,7 +88,7 @@ public function test_returning_false_from_callback_fails_expectation(): void
8888

8989
public function test_returning_true_from_callback_skips_other_iterations(): void
9090
{
91-
$this->process->registerProcessResult('echo *', "hello\n");
91+
$this->process->mockProcess('echo *', "hello\n");
9292
$this->executor->run('echo "hello"');
9393
$this->executor->run('echo "world"');
9494

@@ -106,7 +106,7 @@ public function test_never_returning_fails_expectation(): void
106106
$this->expectException(ExpectationFailedException::class);
107107
$this->expectExceptionMessage('Could not find a matching command for the provided callback.');
108108

109-
$this->process->registerProcessResult('echo *', "hello\n");
109+
$this->process->mockProcess('echo *', "hello\n");
110110
$this->executor->run('echo "hello"');
111111

112112
$this->process->assertRan(function (PendingProcess $_process): void {

tests/Integration/Process/ProcessTesterTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function test_that_recording_must_be_enabled_to_perform_assertions(): voi
4141

4242
public function test_registering_result_allows_assertions(): void
4343
{
44-
$this->process->registerProcessResult('echo *', 'Hello');
44+
$this->process->mockProcess('echo *', 'Hello');
4545
$this->process->assertCommandDidNotRun('echo *');
4646
}
4747

@@ -74,14 +74,14 @@ public function test_assert_nothing_ran_failure(): void
7474
$this->expectException(ExpectationFailedException::class);
7575
$this->expectExceptionMessage('Expected no processes to be executed, but some were.');
7676

77-
$this->process->registerProcessResult('echo *', 'hello');
77+
$this->process->mockProcess('echo *', 'hello');
7878
$this->executor->run('echo "hello"');
7979
$this->process->assertNothingRan();
8080
}
8181

8282
public function test_assert_ran_times_with_string(): void
8383
{
84-
$this->process->registerProcessResult('echo *', 'hello');
84+
$this->process->mockProcess('echo *', 'hello');
8585
$this->executor->run('echo "hello"');
8686
$this->executor->run('echo "hello"');
8787

@@ -90,7 +90,7 @@ public function test_assert_ran_times_with_string(): void
9090

9191
public function test_assert_ran_times_with_callback(): void
9292
{
93-
$this->process->registerProcessResult('echo *', 'hello');
93+
$this->process->mockProcess('echo *', 'hello');
9494
$this->executor->run('echo "hello"');
9595
$this->executor->run('echo "hello"');
9696

@@ -102,7 +102,7 @@ public function test_assert_ran_times_with_string_failure(): void
102102
$this->expectException(ExpectationFailedException::class);
103103
$this->expectExceptionMessage('Expected command "echo *" to be executed 1 times, but it was executed 2 times.');
104104

105-
$this->process->registerProcessResult('echo *', 'hello');
105+
$this->process->mockProcess('echo *', 'hello');
106106
$this->executor->run('echo "hello"');
107107
$this->executor->run('echo "hello"');
108108

@@ -114,7 +114,7 @@ public function test_assert_ran_times_with_callback_failure(): void
114114
$this->expectException(ExpectationFailedException::class);
115115
$this->expectExceptionMessage('Expected command matching callback to be executed 1 times, but it was executed 2 times.');
116116

117-
$this->process->registerProcessResult('echo *', 'hello');
117+
$this->process->mockProcess('echo *', 'hello');
118118
$this->executor->run('echo "hello"');
119119
$this->executor->run('echo "hello"');
120120

@@ -123,7 +123,7 @@ public function test_assert_ran_times_with_callback_failure(): void
123123

124124
public function test_assert_ran_times_with_unrelated_callback(): void
125125
{
126-
$this->process->registerProcessResult('echo *', 'hello');
126+
$this->process->mockProcess('echo *', 'hello');
127127
$this->executor->run('echo "hello"');
128128
$this->executor->run('echo "hello"');
129129

@@ -133,7 +133,7 @@ public function test_assert_ran_times_with_unrelated_callback(): void
133133

134134
public function test_register_multiple_process_results(): void
135135
{
136-
$this->process->registerProcessResults([
136+
$this->process->mockProcesses([
137137
'echo "hello"' => 'Hello',
138138
'echo "world"' => new ProcessResult(exitCode: 0, output: 'World', errorOutput: ''),
139139
]);

0 commit comments

Comments
 (0)