]> BookStack Code Mirror - system-cli/blob - tests/Commands/UpdateCommandTest.php
Added testing for the update command
[system-cli] / tests / Commands / UpdateCommandTest.php
1 <?php declare(strict_types=1);
2
3 namespace Tests\Commands;
4
5 use Tests\TestCase;
6
7 class UpdateCommandTest extends TestCase
8 {
9     public function test_command_updates_instance_in_cwd()
10     {
11         chdir('/var/www/bookstack');
12
13         $result = $this->runCommand('update');
14         $result->assertSuccessfulExit();
15         $result->assertStdoutContains("Your BookStack instance at [/var/www/bookstack] has been updated!");
16     }
17
18     public function test_composer_gets_downloaded_locally_if_not_found()
19     {
20         chdir('/var/www/bookstack');
21
22         rename('/usr/local/bin/composer', '/usr/local/bin/hiddencomposer');
23
24         $this->assertFileDoesNotExist('/var/www/bookstack/composer');
25
26         $result = $this->runCommand('update');
27         $result->assertSuccessfulExit();
28         $result->assertStdoutContains("Composer does not exist, downloading a local copy...");
29         $result->assertStdoutContains("Your BookStack instance at [/var/www/bookstack] has been updated!");
30
31         $this->assertFileExists('/var/www/bookstack/composer');
32         unlink('/var/www/bookstack/composer');
33
34         rename('/usr/local/bin/hiddencomposer', '/usr/local/bin/composer');
35     }
36
37     public function test_command_rejects_on_no_instance_found()
38     {
39         chdir('/home');
40
41         $result = $this->runCommand('update');
42         $result->assertErrorExit();
43         $result->assertStderrContains('Could not find a valid BookStack installation');
44     }
45
46     public function test_command_can_be_provided_app_directory_option()
47     {
48         chdir('/home');
49
50         $result = $this->runCommand('update', ['--app-directory' => '/var/www/bookstack']);
51         $result->assertSuccessfulExit();
52         $result->assertStdoutContains("Your BookStack instance at [/var/www/bookstack] has been updated!");
53     }
54 }