1 <?php declare(strict_types=1);
3 namespace Tests\Commands;
7 class InitCommandTest extends TestCase
9 public function test_command_creates_an_instance_in_cwd()
11 $dir = $this->getEmptyTestDir();
14 $result = $this->runCommand('init');
15 $result->assertSuccessfulExit();
17 $this->assertFileExists($dir . '/vendor/autoload.php');
18 $this->assertFileExists($dir . '/.env');
20 $envData = file_get_contents($dir . '/.env');
21 $this->assertMatchesRegularExpression('/^APP_KEY=base64:.{30,60}$/m', $envData);
23 $result->assertStdoutContains("A BookStack install has been initialized at: " . $dir);
25 $this->deleteDirectory($dir);
28 public function test_command_custom_path_validation()
30 $dir = $this->getEmptyTestDir();
31 $file = $dir . '/out.txt';
32 file_put_contents($file, 'hello');
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.");
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.");
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.");
46 $this->deleteDirectory($dir);