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
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: ['8.3']
dependency-version: [prefer-lowest, prefer-stable]
php: ['8.2', '8.3', '8.4']
dependency-version: [prefer-stable]

name: Tests P${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ To execute a command over SSH, use the `Process` facade:
### Basic Usage

```php
use Illuminate\Support\Facades\Process;

$result = Process::ssh([
'host' => '192.168.1.10',
'user' => 'username',
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
}
],
"require": {
"php": "^8.0",
"php": "^8.1",
"illuminate/support": "^10.0 || ^11.0"
},
"require-dev": {
"laravel/pint": "^1.18.1",
"orchestra/testbench": "^9.9",
"pestphp/pest": "^3.5.1",
"pestphp/pest-plugin-type-coverage": "^3.1",
"pestphp/pest-plugin-watch": "^3.0",
"phpstan/phpstan": "^1.12.7",
"rector/rector": "^1.2.8",
Expand Down Expand Up @@ -58,6 +57,7 @@
"test:types": "phpstan analyse --ansi",
"test:unit": "pest --colors=always --parallel",
"test": [
"rector",
"composer lint",
"@test:types",
"@test:unit"
Expand Down
12 changes: 5 additions & 7 deletions src/PendingProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public function command(array|string $command)
/**
* Set configuration for the SSH connection.
*/
public function setConfig(array $config, bool $handleSsh)
public function setConfig(array $config, bool $handleSsh): static
{
$this->handleSsh = $handleSsh;

if (! $this->handleSsh && empty($config)) {
if (! $this->handleSsh && $config === []) {
return $this;
}

Expand Down Expand Up @@ -72,7 +72,7 @@ public function setConfig(array $config, bool $handleSsh)
*/
public function buildCommand(array|string|null $command): array|string|null
{
if (! $command) {
if ($command === '' || $command === '0' || $command === [] || $command === null) {
return $command;
}

Expand Down Expand Up @@ -141,7 +141,7 @@ protected function buildTarget(): string
* @param mixed $command The command to check.
* @return bool True if the command is invalid, otherwise false.
*/
protected function exceptionCondition($command): bool
protected function exceptionCondition(mixed $command): bool
{
return is_array($command) && $this->handleSsh;
}
Expand Down Expand Up @@ -177,8 +177,6 @@ protected function toSymfonyProcess(array|string|null $command)
{
$command = $this->buildCommand($command);

$process = parent::toSymfonyProcess($command);

return $process;
return parent::toSymfonyProcess($command);
}
}
4 changes: 1 addition & 3 deletions src/Providers/ProcessSshServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ class ProcessSshServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->bind(Factory::class, function () {
return new ProcessSsh;
});
$this->app->bind(Factory::class, fn (): \Bagel\ProcessSsh\ProcessSsh => new ProcessSsh);
}
}
86 changes: 45 additions & 41 deletions tests/ProcessSshTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Illuminate\Support\Facades\Process;
use Orchestra\Testbench\TestCase;

uses(TestCase::class)->beforeEach(function () {
uses(TestCase::class)->beforeEach(function (): void {
$this->app->register(ProcessSshServiceProvider::class);

$this->basicSshConfig = [
Expand All @@ -17,7 +17,7 @@
];
});

it('process config set', function () {
it('process config set', function (): void {
$process = Process::ssh([
'host' => '192.178.0.1',
'user' => 'ubuntu',
Expand All @@ -39,7 +39,7 @@
expect($process->sshConfig()['private_key'])->toBe('/path/to/key');
});

it('process add extra options', function () {
it('process add extra options', function (): void {
$process = Process::ssh([
'host' => '192.178.0.1',
'user' => 'ubuntu',
Expand All @@ -51,7 +51,7 @@
]);
});

it('process disableStrictHostKeyChecking', function () {
it('process disableStrictHostKeyChecking', function (): void {
$process = Process::ssh([
'host' => '192.178.0.1',
'user' => 'ubuntu',
Expand All @@ -63,7 +63,7 @@
]);
});

it('process useMultiplexing', function () {
it('process useMultiplexing', function (): void {
$process = Process::ssh([
'host' => '192.168.85.5',
'user' => 'ubuntu',
Expand All @@ -86,11 +86,11 @@
]);
});

it('exception thrown when host is not set', function () {
it('exception thrown when host is not set', function (): void {
Process::ssh([])->run('ls');
})->throws(InvalidArgumentException::class, 'Host is required for SSH connections.');

it('Process run without user / password not set', function () {
it('Process run without user / password not set', function (): void {
Process::fake();

$process = Process::ssh([
Expand All @@ -104,7 +104,7 @@
Process::assertRan('ls -al');
});

it('Process run all parameters', function () {
it('Process run all parameters', function (): void {
Process::fake();

$process = Process::ssh([
Expand All @@ -125,7 +125,7 @@
Process::assertRan('ls -al');
});

it('Process run with private key', function () {
it('Process run with private key', function (): void {
Process::fake();

$process = Process::ssh([
Expand All @@ -142,33 +142,29 @@
Process::assertRan('ls -al');
});

it('Process can run normaly', function () {
it('Process can run normaly', function (): void {
Process::fake();

Process::run('ls');

Process::assertRan('ls');

Process::assertRan(function (PendingProcess $process, FakeProcessResult $result) {
return $process->command === 'ls' &&
$process->timeout === 60;
});
Process::assertRan(fn (PendingProcess $process, FakeProcessResult $result): bool => $process->command === 'ls' &&
$process->timeout === 60);
});

it('Process can start normaly', function () {
it('Process can start normaly', function (): void {
Process::fake();

Process::start('ls');

Process::assertRan('ls');

Process::assertRan(function (PendingProcess $process, FakeProcessResult $result) {
return $process->command === 'ls' &&
$process->timeout === 60;
});
Process::assertRan(fn (PendingProcess $process, FakeProcessResult $result): bool => $process->command === 'ls' &&
$process->timeout === 60);
});

it('Process ssh can run', function () {
it('Process ssh can run', function (): void {
Process::fake();

Process::ssh([
Expand All @@ -181,13 +177,11 @@

Process::assertRan('ls');

Process::assertRan(function (PendingProcess $process, FakeProcessResult $result) {
return $process->command === 'ls' &&
$process->timeout === 60;
});
Process::assertRan(fn (PendingProcess $process, FakeProcessResult $result): bool => $process->command === 'ls' &&
$process->timeout === 60);
});

it('Process ssh can start', function () {
it('Process ssh can start', function (): void {
Process::fake();

Process::ssh([
Expand All @@ -200,16 +194,14 @@

Process::assertRan('ls');

Process::assertRan(function (PendingProcess $process, FakeProcessResult $result) {
return $process->command === 'ls' &&
$process->timeout === 60;
});
Process::assertRan(fn (PendingProcess $process, FakeProcessResult $result): bool => $process->command === 'ls' &&
$process->timeout === 60);
});

it('invoke process::concurrently', function () {
it('invoke process::concurrently', function (): void {
Process::fake();

$process = Process::concurrently(function (Pool $pool) {
$process = Process::concurrently(function (Pool $pool): void {
$pool->command('ls -al');
$pool->command('whoami');
});
Expand All @@ -221,10 +213,10 @@
Process::assertRan('whoami');
});

it('invoke process::concurrently ssh', function () {
it('invoke process::concurrently ssh', function (): void {
Process::fake();

$process = Process::ssh($this->basicSshConfig)->concurrently(function (Pool $pool) {
$process = Process::ssh($this->basicSshConfig)->concurrently(function (Pool $pool): void {
$pool->command('ls -al');
$pool->command('whoami');
});
Expand All @@ -234,10 +226,10 @@

});

it('invoke process::pool', function () {
it('invoke process::pool', function (): void {
Process::fake();

$process = Process::pool(function (Pool $pool) {
$process = Process::pool(function (Pool $pool): void {
$pool->command('ls -al');
$pool->command('whoami');
});
Expand All @@ -250,10 +242,10 @@
Process::assertRan('whoami');
});

it('invoke process::pool ssh', function () {
it('invoke process::pool ssh', function (): void {
Process::fake();

$process = Process::ssh($this->basicSshConfig)->pool(function (Pool $pool) {
$process = Process::ssh($this->basicSshConfig)->pool(function (Pool $pool): void {
$pool->command('ls -al');
$pool->command('whoami');
});
Expand All @@ -264,16 +256,28 @@

});

it('exception thrown process run with array', function () {
it('exception thrown process run with array', function (): void {
Process::fake();

Process::ssh([
'host' => '127.0.0.1',
])->run(['ls', '-al']);

})->throws(InvalidArgumentException::class, 'Array commands are not supported for SSH connections.');

it('exception thrown process start with array', function () {
it('can\'t pipe processes with SSH enabled', function (): void {
Process::fake();

Process::ssh([
'host' => 'example.com',
'user' => 'ubuntu',
'password' => 'password',
'port' => 22,
])->pipe(function (): void {
//
});
})->throws(InvalidArgumentException::class, 'Cannot pipe processes with SSH enabled.');

it('exception thrown process start with array', function (): void {
Process::fake();

Process::ssh([
Expand All @@ -282,7 +286,7 @@

})->throws(InvalidArgumentException::class, 'Array commands are not supported for SSH connections.');

it('invoke process::pipe', function () {
it('invoke process::pipe', function (): void {
Process::fake();

$process = Process::ssh($this->basicSshConfig)->pipe([
Expand Down
4 changes: 2 additions & 2 deletions tests/Providers/ProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
use Illuminate\Process\Factory;
use Orchestra\Testbench\TestCase;

uses(TestCase::class)->beforeEach(function () {
uses(TestCase::class)->beforeEach(function (): void {
$this->app->register(ProcessSshServiceProvider::class);
});

it('binds ProcessSsh to Factory', function () {
it('binds ProcessSsh to Factory', function (): void {
$factory = app(Factory::class);

expect($factory)->toBeInstanceOf(ProcessSsh::class);
Expand Down
Loading