]> BookStack Code Mirror - system-cli/blob - tests/Commands/InitCommandTest.php
Bumped version
[system-cli] / tests / Commands / InitCommandTest.php
1 <?php declare(strict_types=1);
2
3 namespace Tests\Commands;
4
5 use Tests\TestCase;
6
7 class InitCommandTest extends TestCase
8 {
9     public function test_command_creates_an_instance_in_cwd()
10     {
11         $dir = $this->getEmptyTestDir();
12         chdir($dir);
13
14         $result = $this->runCommand('init');
15         $result->assertSuccessfulExit();
16
17         $this->assertFileExists($dir . '/vendor/autoload.php');
18         $this->assertFileExists($dir . '/.env');
19
20         $envData = file_get_contents($dir . '/.env');
21         $this->assertMatchesRegularExpression('/^APP_KEY=base64:.{30,60}$/m', $envData);
22
23         $result->assertStdoutContains("A BookStack install has been initialized at: " . $dir);
24
25         $this->deleteDirectory($dir);
26     }
27
28     public function test_command_custom_path_validation()
29     {
30         $dir = $this->getEmptyTestDir();
31         $file = $dir . '/out.txt';
32         file_put_contents($file, 'hello');
33
34         $result = $this->runCommand('init', ['target-directory' => $file]);
35         $result->assertErrorExit();
36         $result->assertStderrContains("Was provided [{$file}] as an install path but existing file provided.");
37
38         $result = $this->runCommand('init', ['target-directory' => $dir]);
39         $result->assertErrorExit();
40         $result->assertStderrContains("Expected install directory to be empty but existing files found in [{$dir}] target location.");
41
42         $result = $this->runCommand('init', ['target-directory' => '/my/duck/says/hello']);
43         $result->assertErrorExit();
44         $result->assertStderrContains("Could not resolve provided [/my/duck/says/hello] path to an existing folder.");
45
46         $this->deleteDirectory($dir);
47     }
48 }