From 070c101a550852fcfcd90259546580c850acd6db Mon Sep 17 00:00:00 2001 From: lguichard Date: Wed, 1 Jan 2025 13:47:09 +0100 Subject: [PATCH 1/5] Chore: Cleaning & update dependencies --- .github/workflows/tests.yml | 4 +- composer.json | 3 +- src/PendingProcess.php | 6 +- src/Providers/ProcessSshServiceProvider.php | 4 +- tests/ProcessSshTest.php | 64 +++++++++------------ tests/Providers/ProviderTest.php | 4 +- 6 files changed, 37 insertions(+), 48 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3d20ec9..feeb0b0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,8 +9,8 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest] - php: ['8.3'] - dependency-version: [prefer-lowest, prefer-stable] + php: ['8.3', '8.4'] + dependency-version: [prefer-stable] name: Tests P${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }} diff --git a/composer.json b/composer.json index 4107933..d52131c 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/PendingProcess.php b/src/PendingProcess.php index f36f8da..0f9781c 100644 --- a/src/PendingProcess.php +++ b/src/PendingProcess.php @@ -24,11 +24,11 @@ class PendingProcess extends BasePendingProcess /** * 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; } @@ -125,7 +125,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; } diff --git a/src/Providers/ProcessSshServiceProvider.php b/src/Providers/ProcessSshServiceProvider.php index 89a3edb..f8b0937 100644 --- a/src/Providers/ProcessSshServiceProvider.php +++ b/src/Providers/ProcessSshServiceProvider.php @@ -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); } } diff --git a/tests/ProcessSshTest.php b/tests/ProcessSshTest.php index b8e5dae..fdb432e 100644 --- a/tests/ProcessSshTest.php +++ b/tests/ProcessSshTest.php @@ -6,11 +6,11 @@ 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); }); -it('process config set', function () { +it('process config set', function (): void { $process = Process::ssh([ 'host' => 'example.com', 'user' => 'ubuntu', @@ -32,7 +32,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' => 'example.com', 'user' => 'ubuntu', @@ -44,7 +44,7 @@ ]); }); -it('process disableStrictHostKeyChecking', function () { +it('process disableStrictHostKeyChecking', function (): void { $process = Process::ssh([ 'host' => 'example.com', 'user' => 'ubuntu', @@ -56,11 +56,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([ @@ -74,7 +74,7 @@ Process::assertRan('ls -al'); }); -it('Process run all parameters', function () { +it('Process run all parameters', function (): void { Process::fake(); $process = Process::ssh([ @@ -95,7 +95,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([ @@ -112,7 +112,7 @@ Process::assertRan('ls -al'); }); -it('exception thrown process run with array', function () { +it('exception thrown process run with array', function (): void { Process::fake(); Process::ssh([ @@ -121,7 +121,7 @@ })->throws(InvalidArgumentException::class, 'Array commands are not supported for SSH connections'); -it('exception thrown process start with array', function () { +it('exception thrown process start with array', function (): void { Process::fake(); Process::ssh([ @@ -130,33 +130,29 @@ })->throws(InvalidArgumentException::class, 'Array commands are not supported for SSH connections'); -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([ @@ -169,13 +165,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([ @@ -188,13 +182,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('can\'t pool processes with SSH enabled', function () { +it('can\'t pool processes with SSH enabled', function (): void { Process::fake(); Process::ssh([ @@ -202,13 +194,13 @@ 'user' => 'ubuntu', 'password' => 'password', 'port' => 22, - ])->pool(function () { + ])->pool(function (): void { // }); })->throws(InvalidArgumentException::class, 'Cannot pool processes with SSH enabled.'); -it('can\'t pipe processes with SSH enabled', function () { +it('can\'t pipe processes with SSH enabled', function (): void { Process::fake(); Process::ssh([ @@ -216,13 +208,13 @@ 'user' => 'ubuntu', 'password' => 'password', 'port' => 22, - ])->pipe(function () { + ])->pipe(function (): void { // }); })->throws(InvalidArgumentException::class, 'Cannot pipe processes with SSH enabled.'); -it('can\'t concurrently processes with SSH enabled', function () { +it('can\'t concurrently processes with SSH enabled', function (): void { Process::fake(); Process::ssh([ @@ -230,7 +222,7 @@ 'user' => 'ubuntu', 'password' => 'password', 'port' => 22, - ])->concurrently(function () { + ])->concurrently(function (): void { // }); diff --git a/tests/Providers/ProviderTest.php b/tests/Providers/ProviderTest.php index 5572c3c..46dc388 100644 --- a/tests/Providers/ProviderTest.php +++ b/tests/Providers/ProviderTest.php @@ -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); From e61ba199720d116cdc9078676eb398dfdac9b465 Mon Sep 17 00:00:00 2001 From: lguichard Date: Wed, 1 Jan 2025 13:55:55 +0100 Subject: [PATCH 2/5] Wip --- .github/workflows/tests.yml | 2 +- composer.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index feeb0b0..9be15dd 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,7 +9,7 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest] - php: ['8.3', '8.4'] + php: ['8.1', '8.2', '8.3', '8.4'] dependency-version: [prefer-stable] name: Tests P${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }} diff --git a/composer.json b/composer.json index d52131c..8c4da15 100644 --- a/composer.json +++ b/composer.json @@ -57,6 +57,7 @@ "test:types": "phpstan analyse --ansi", "test:unit": "pest --colors=always --parallel", "test": [ + "rector", "composer lint", "@test:types", "@test:unit" From dadcf51d979d07f518b2ecab1fd5010c4e38e8dd Mon Sep 17 00:00:00 2001 From: lguichard Date: Wed, 1 Jan 2025 13:58:30 +0100 Subject: [PATCH 3/5] Wip --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 93784d1..9dda832 100644 --- a/README.md +++ b/README.md @@ -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', From c760d737d5f95b9ad6529afb65569b8ae553ff57 Mon Sep 17 00:00:00 2001 From: lguichard Date: Wed, 1 Jan 2025 14:00:21 +0100 Subject: [PATCH 4/5] Update tests.yml --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9be15dd..89e89c6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,7 +9,7 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest] - php: ['8.1', '8.2', '8.3', '8.4'] + php: ['8.2', '8.3', '8.4'] dependency-version: [prefer-stable] name: Tests P${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }} From be1272aabaeb94d96eec52a271bd22b9a66e8cfd Mon Sep 17 00:00:00 2001 From: lguichard Date: Sat, 4 Jan 2025 18:15:56 +0100 Subject: [PATCH 5/5] Update PendingProcess.php --- src/PendingProcess.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/PendingProcess.php b/src/PendingProcess.php index 2029912..5a43226 100644 --- a/src/PendingProcess.php +++ b/src/PendingProcess.php @@ -72,7 +72,7 @@ public function setConfig(array $config, bool $handleSsh): static */ public function buildCommand(array|string|null $command): array|string|null { - if (! $command) { + if ($command === '' || $command === '0' || $command === [] || $command === null) { return $command; } @@ -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); } }