Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/PendingProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Bagel\ProcessSsh;

use Illuminate\Process\PendingProcess as BasePendingProcess;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;

/**
* PendingProcess handles the construction and execution of SSH commands.
Expand Down Expand Up @@ -170,6 +172,15 @@ public function start(array|string|null $command = null, ?callable $output = nul
return parent::start($command, $output);
}

/**
* Get the fake handler for the given command, if applicable.
*/
protected function fakeFor(string $command)
{
return (new Collection($this->fakeHandlers))
->first(fn ($handler, $pattern): bool => $pattern === '*' || Str::contains($command, $pattern));
}

/**
* Convert the command to a Symfony Process object.
*/
Expand Down
28 changes: 28 additions & 0 deletions tests/ProcessSshTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,31 @@
'whoami',
]);
})->throws(InvalidArgumentException::class, 'Cannot pipe processes with SSH enabled.');

it('fake result Process::run', function (): void {
Process::fake([
'ls -al' => Process::result(
output: 'test',
errorOutput: '',
exitCode: 1,
),
]);

$process = Process::ssh($this->basicSshConfig)->run('ls -al');

expect($process->output())->toBe("test\n");
});

it('fake result Process::start', function (): void {
Process::fake([
'ls -al' => Process::result(
output: 'test',
errorOutput: '',
exitCode: 1,
),
]);

$process = Process::ssh($this->basicSshConfig)->start('ls -al');

expect($process->wait()->output())->toBe("test\n");
});
Loading