From 5af6ba78db3bb34e443d5ace3fc6faf437b3e170 Mon Sep 17 00:00:00 2001 From: Joel Wurtz Date: Mon, 8 Apr 2024 23:51:04 +0200 Subject: [PATCH] chore(tests): make some tests less sensible to user environment --- examples/failure.php | 4 ++-- examples/ssh.php | 2 +- tests/Generated/FailureAllowFailureTest.php.err.txt | 2 +- tests/Generated/FailureFailureTest.php.err.txt | 4 ++-- tests/Generated/SshUploadTest.php.err.txt | 2 +- tests/Slow/CompileCommandTest.php | 8 ++++++++ tests/Slow/RepackCommandTest.php | 8 ++++++++ 7 files changed, 23 insertions(+), 7 deletions(-) diff --git a/examples/failure.php b/examples/failure.php index 464251ae..9df91696 100644 --- a/examples/failure.php +++ b/examples/failure.php @@ -9,11 +9,11 @@ #[AsTask(description: 'A failing task not authorized to fail')] function failure(): void { - run('i_do_not_exist', workingDirectory: '/tmp', pty: false); + run('bash -c i_do_not_exist', workingDirectory: '/tmp', pty: false); } #[AsTask(description: 'A failing task authorized to fail')] function allow_failure(): void { - run('i_do_not_exist', allowFailure: true, pty: false); + run('bash -c i_do_not_exist', allowFailure: true, pty: false); } diff --git a/examples/ssh.php b/examples/ssh.php index 8210eb3f..81302912 100644 --- a/examples/ssh.php +++ b/examples/ssh.php @@ -27,7 +27,7 @@ function whoami(): void #[AsTask(description: 'Uploads a file to the remote server')] function upload(): void { - ssh_upload('/tmp/test.html', '/var/www/index.html', host: 'server-1.example.com', user: 'debian'); + ssh_upload(__FILE__, '/var/www/index.html', host: 'server-1.example.com', user: 'debian'); } #[AsTask(description: 'Downloads a file from the remote server')] diff --git a/tests/Generated/FailureAllowFailureTest.php.err.txt b/tests/Generated/FailureAllowFailureTest.php.err.txt index e5b48ae6..2d3470f5 100644 --- a/tests/Generated/FailureAllowFailureTest.php.err.txt +++ b/tests/Generated/FailureAllowFailureTest.php.err.txt @@ -1 +1 @@ -sh: 1: i_do_not_exist: not found +bash: line 1: i_do_not_exist: command not found diff --git a/tests/Generated/FailureFailureTest.php.err.txt b/tests/Generated/FailureFailureTest.php.err.txt index dba37145..a34ef0e7 100644 --- a/tests/Generated/FailureFailureTest.php.err.txt +++ b/tests/Generated/FailureFailureTest.php.err.txt @@ -1,8 +1,8 @@ -sh: 1: i_do_not_exist: not found +bash: line 1: i_do_not_exist: command not found In failure.php line 12: - The command "i_do_not_exist" failed. + The command "bash -c i_do_not_exist" failed. failure:failure diff --git a/tests/Generated/SshUploadTest.php.err.txt b/tests/Generated/SshUploadTest.php.err.txt index ea32c86b..4adfcac3 100644 --- a/tests/Generated/SshUploadTest.php.err.txt +++ b/tests/Generated/SshUploadTest.php.err.txt @@ -2,7 +2,7 @@ ssh: Could not resolve hostname server-1.example.com: Name or service not known In SshRunner.php line XXXX: - The command "scp -r /tmp/test.html debian@server-1.example.com:/var/www/index.html" failed. + The command "scp -r .../examples/ssh.php debian@server-1.example.com:/var/www/index.html" failed. ssh:upload diff --git a/tests/Slow/CompileCommandTest.php b/tests/Slow/CompileCommandTest.php index 628cd266..bc613bc3 100644 --- a/tests/Slow/CompileCommandTest.php +++ b/tests/Slow/CompileCommandTest.php @@ -3,12 +3,20 @@ namespace Castor\Tests\Slow; use PHPUnit\Framework\TestCase; +use Symfony\Component\Process\ExecutableFinder; use Symfony\Component\Process\Process; class CompileCommandTest extends TestCase { public function test() { + $finder = new ExecutableFinder(); + $box = $finder->find('box'); + + if (null === $box) { + $this->markTestSkipped('box is not installed.'); + } + $castorAppDirPath = RepackCommandTest::setupRepackedCastorApp('castor-test-compile'); (new Process( diff --git a/tests/Slow/RepackCommandTest.php b/tests/Slow/RepackCommandTest.php index f7921adb..bcfb8b3e 100644 --- a/tests/Slow/RepackCommandTest.php +++ b/tests/Slow/RepackCommandTest.php @@ -4,12 +4,20 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\Process\ExecutableFinder; use Symfony\Component\Process\Process; class RepackCommandTest extends TestCase { public function test() { + $finder = new ExecutableFinder(); + $box = $finder->find('box'); + + if (null === $box) { + $this->markTestSkipped('box is not installed.'); + } + $castorAppDirPath = self::setupRepackedCastorApp('castor-test-repack'); (new Process([