diff --git a/src/Ssh.php b/src/Ssh.php index c399ddd..b3da00a 100755 --- a/src/Ssh.php +++ b/src/Ssh.php @@ -20,6 +20,8 @@ class Ssh protected Closure $onOutput; + private int $timeout = 0; + public function __construct(string $user, string $host, int $port = null) { $this->user = $user; @@ -96,7 +98,7 @@ public function enableStrictHostKeyChecking(): self public function setTimeout(int $timeout): self { - $this->extraOptions['timeout'] = $timeout; + $this->timeout = $timeout; return $this; } @@ -241,10 +243,7 @@ protected function getExtraScpOptions(): string protected function getExtraOptions(): array { - // Removed timeout from extra options; it's only used as a value for Symfony\Process, not as an SSH option - $extraOptions = array_filter($this->extraOptions, fn ($key) => $key !== 'timeout', ARRAY_FILTER_USE_KEY); - - return array_values($extraOptions); + return array_values($this->extraOptions); } protected function wrapArray($arrayOrString): array @@ -256,7 +255,7 @@ protected function run(string $command, string $method = 'run'): Process { $process = Process::fromShellCommandline($command); - $process->setTimeout($this->extraOptions['timeout'] ?? 0); + $process->setTimeout($this->timeout); ($this->processConfigurationClosure)($process); diff --git a/tests/SshTest.php b/tests/SshTest.php index 2dcb937..c635909 100644 --- a/tests/SshTest.php +++ b/tests/SshTest.php @@ -151,3 +151,9 @@ assertMatchesSnapshot($command); }); + +it('does not alter scp command when setting timeout', function () { + $command = $this->ssh->setTimeout(10)->getUploadCommand('.env', 'spatie.be/current/.env'); + + assertMatchesSnapshot($command); +}); diff --git a/tests/__snapshots__/SshTest__it_does_not_alter_scp_command_when_setting_timeout__1.txt b/tests/__snapshots__/SshTest__it_does_not_alter_scp_command_when_setting_timeout__1.txt new file mode 100644 index 0000000..150ff63 --- /dev/null +++ b/tests/__snapshots__/SshTest__it_does_not_alter_scp_command_when_setting_timeout__1.txt @@ -0,0 +1 @@ +scp -r .env user@example.com:spatie.be/current/.env \ No newline at end of file