]> BookStack Code Mirror - system-cli/commitdiff
Added testing for the update command
authorDan Brown <redacted>
Mon, 3 Apr 2023 15:16:38 +0000 (16:16 +0100)
committerDan Brown <redacted>
Mon, 3 Apr 2023 15:16:38 +0000 (16:16 +0100)
src/Commands/UpdateCommand.php
tests/CommandResult.php
tests/Commands/UpdateCommandTest.php [new file with mode: 0644]

index e1b7070181c57df8af67f9aaf870d1e2d9ba6d8c..c8c6138d14d5a84fdd837f0084e7d864299c52ff 100644 (file)
@@ -53,6 +53,8 @@ class UpdateCommand extends Command
         $artisan->run(['config:clear']);
         $artisan->run(['view:clear']);
 
+        $output->writeln("<info>Your BookStack instance at [{$appDir}] has been updated!</info>");
+
         return Command::SUCCESS;
     }
 
index b8ee3b01d2a85db87dce862a46106a8936b170f4..492e216e3022dcbf054eb4a57f768502e4613933 100644 (file)
@@ -13,6 +13,11 @@ class CommandResult
         protected ?\Exception $error
     ) { }
 
+    public function getStderr(): string
+    {
+        return $this->error?->getMessage() ?? '';
+    }
+
     public function assertSuccessfulExit(): void
     {
         Assert::assertEquals(0, $this->tester->getStatusCode());
@@ -30,7 +35,7 @@ class CommandResult
 
     public function assertStderrContains(string $needle): void
     {
-        Assert::assertStringContainsString($needle, $this->error->getMessage() ?? '');
+        Assert::assertStringContainsString($needle, $this->getStderr());
     }
 
 
diff --git a/tests/Commands/UpdateCommandTest.php b/tests/Commands/UpdateCommandTest.php
new file mode 100644 (file)
index 0000000..f60398c
--- /dev/null
@@ -0,0 +1,54 @@
+<?php declare(strict_types=1);
+
+namespace Tests\Commands;
+
+use Tests\TestCase;
+
+class UpdateCommandTest extends TestCase
+{
+    public function test_command_updates_instance_in_cwd()
+    {
+        chdir('/var/www/bookstack');
+
+        $result = $this->runCommand('update');
+        $result->assertSuccessfulExit();
+        $result->assertStdoutContains("Your BookStack instance at [/var/www/bookstack] has been updated!");
+    }
+
+    public function test_composer_gets_downloaded_locally_if_not_found()
+    {
+        chdir('/var/www/bookstack');
+
+        rename('/usr/local/bin/composer', '/usr/local/bin/hiddencomposer');
+
+        $this->assertFileDoesNotExist('/var/www/bookstack/composer');
+
+        $result = $this->runCommand('update');
+        $result->assertSuccessfulExit();
+        $result->assertStdoutContains("Composer does not exist, downloading a local copy...");
+        $result->assertStdoutContains("Your BookStack instance at [/var/www/bookstack] has been updated!");
+
+        $this->assertFileExists('/var/www/bookstack/composer');
+        unlink('/var/www/bookstack/composer');
+
+        rename('/usr/local/bin/hiddencomposer', '/usr/local/bin/composer');
+    }
+
+    public function test_command_rejects_on_no_instance_found()
+    {
+        chdir('/home');
+
+        $result = $this->runCommand('update');
+        $result->assertErrorExit();
+        $result->assertStderrContains('Could not find a valid BookStack installation');
+    }
+
+    public function test_command_can_be_provided_app_directory_option()
+    {
+        chdir('/home');
+
+        $result = $this->runCommand('update', ['--app-directory' => '/var/www/bookstack']);
+        $result->assertSuccessfulExit();
+        $result->assertStdoutContains("Your BookStack instance at [/var/www/bookstack] has been updated!");
+    }
+}
\ No newline at end of file