Skip to content

Commit b0ac458

Browse files
committed
refactor: rename mock method
1 parent 3837f44 commit b0ac458

File tree

8 files changed

+31
-31
lines changed

8 files changed

+31
-31
lines changed

packages/process/src/Testing/ProcessTester.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public function recordProcessExecutions(): void
3939
}
4040

4141
/**
42-
* Sets up the specified command or pattern to return the specified result.
42+
* Sets up the specified command or pattern to return the specified result. The command accepts `*` as a placeholder.
4343
*/
44-
public function mockProcess(string $command, string|ProcessResult $result): self
44+
public function mock(string $command = '*', string|ProcessResult $result = ''): self
4545
{
4646
$this->recordProcessExecutions();
4747

@@ -55,7 +55,7 @@ public function mockProcess(string $command, string|ProcessResult $result): self
5555
*
5656
* @var array<string,string|ProcessResult> $results
5757
*/
58-
public function mockProcesses(array $results): self
58+
public function mockProcessResults(array $results): self
5959
{
6060
$this->recordProcessExecutions();
6161

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->mockProcess('*', '');
32+
$this->process->mock();
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->mockProcess('*', '');
40+
$this->process->mock();
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->mockProcess('*', '');
61+
$this->process->mock();
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->mockProcess('*', '');
82+
$this->process->mock();
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->mockProcess('*', '');
17+
$this->process->mock();
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
@@ -15,7 +15,7 @@ final class ProcessExecutorTest extends FrameworkIntegrationTestCase
1515

1616
public function test_run(): void
1717
{
18-
$this->process->mockProcess('echo *', "Hello\n");
18+
$this->process->mock('echo *', "Hello\n");
1919

2020
$result = $this->executor->run('echo "Hello"');
2121

@@ -26,7 +26,7 @@ public function test_run(): void
2626

2727
public function test_describe_and_assert_async_process(): void
2828
{
29-
$this->process->mockProcesses([
29+
$this->process->mockProcessResults([
3030
'echo *' => $this->process
3131
->describe()
3232
->output('hello')
@@ -57,7 +57,7 @@ public function test_describe_and_assert_async_process(): void
5757

5858
public function test_concurrently(): void
5959
{
60-
$this->process->mockProcesses([
60+
$this->process->mockProcessResults([
6161
'echo "hello"' => $this->process->describe()->output('hello'),
6262
'echo "world"' => $this->process->describe()->output('world'),
6363
]);
@@ -77,7 +77,7 @@ public function test_concurrently(): void
7777

7878
public function test_pool(): void
7979
{
80-
$this->process->mockProcesses([
80+
$this->process->mockProcessResults([
8181
'echo "hello"' => $this->process->describe()->output('hello'),
8282
'echo "world"' => $this->process->describe()->output('world'),
8383
]);

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->mockProcess('echo *', 'hello');
30+
$this->process->mock('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->mockProcess('echo *', 'hello');
44+
$this->process->mock('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->mockProcess('echo *', "hello\n");
23+
$this->process->mock('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->mockProcess('echo *', "hello\n");
30+
$this->process->mock('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->mockProcess('echo *', "hello\n");
42+
$this->process->mock('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->mockProcess('echo *', "hello\n");
52+
$this->process->mock('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->mockProcess('echo *', "hello\n");
61+
$this->process->mock('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->mockProcess('echo *', "hello\n");
68+
$this->process->mock('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->mockProcess('echo *', "hello\n");
81+
$this->process->mock('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->mockProcess('echo *', "hello\n");
91+
$this->process->mock('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->mockProcess('echo *', "hello\n");
109+
$this->process->mock('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->mockProcess('echo *', 'Hello');
44+
$this->process->mock('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->mockProcess('echo *', 'hello');
77+
$this->process->mock('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->mockProcess('echo *', 'hello');
84+
$this->process->mock('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->mockProcess('echo *', 'hello');
93+
$this->process->mock('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->mockProcess('echo *', 'hello');
105+
$this->process->mock('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->mockProcess('echo *', 'hello');
117+
$this->process->mock('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->mockProcess('echo *', 'hello');
126+
$this->process->mock('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->mockProcesses([
136+
$this->process->mockProcessResults([
137137
'echo "hello"' => 'Hello',
138138
'echo "world"' => new ProcessResult(exitCode: 0, output: 'World', errorOutput: ''),
139139
]);

0 commit comments

Comments
 (0)