diff --git a/src/Commands/InitCommand.php b/src/Commands/InitCommand.php index 0a116d0..a8ad020 100644 --- a/src/Commands/InitCommand.php +++ b/src/Commands/InitCommand.php @@ -104,6 +104,10 @@ public function handle(): void 'DB_PASSWORD' => '', ]); + if (!file_exists('.env.development')) { + copy('.env.example', '.env.development'); + } + $this->updateEnvFile('.env.development', [ 'APP_NAME' => $this->appName, 'APP_URL' => $this->appUrl, diff --git a/tests/InitCommandTest.php b/tests/InitCommandTest.php index d810670..f37e059 100644 --- a/tests/InitCommandTest.php +++ b/tests/InitCommandTest.php @@ -20,6 +20,11 @@ public function testRunWithoutAdminAndReadmeCreationConvertAppNameToPascalCaseTe $this->mockNativeFunction( 'RonasIT\ProjectInitializator\Commands', + $this->callFileExists('.env', false), + $this->callFileExists('.env.development', false), + + $this->callCopy('.env.example', '.env.development'), + $this->callClassExists('Laravel\Telescope\TelescopeServiceProvider'), $this->callFileGetContent(base_path('composer.json'), $this->getFixture('composer_with_pint_settings.json')), @@ -60,13 +65,16 @@ public function testRunWithoutAdminAndReadmeCreation() { $this->mockNativeFunction( '\Winter\LaravelConfigWriter', - $this->changeEnvFileCall('.env.example', 'env.example.yml', 'env.example_app_name_pascal_case.yml'), + $this->changeEnvFileCall('.env', 'env.example.yml', 'env.example_app_name_pascal_case.yml'), $this->changeEnvFileCall('.env.development', 'env.development.yml', 'env.development_app_name_pascal_case.yml'), $this->changeConfigFileCall(base_path('config/auto-doc.php'), 'auto_doc.php', 'auto_doc_after_changes.php'), ); $this->mockNativeFunction( 'RonasIT\ProjectInitializator\Commands', + $this->callFileExists('.env'), + $this->callFileExists('.env.development'), + $this->callFileGetContent(base_path('composer.json'), $this->getFixture('composer_with_pint_settings.json')), $this->callFilePutContent(base_path('/routes/web.php'), "\nAuth::routes();\n", FILE_APPEND), @@ -115,6 +123,9 @@ public function testRunWithAdminAndWithoutReadmeCreation() $this->mockNativeFunction( 'RonasIT\ProjectInitializator\Commands', + $this->callFileExists('.env', false), + $this->callFileExists('.env.development'), + $this->callFileGetContent(base_path('composer.json'), $this->getFixture('composer_with_pint_settings.json')), $this->callFilePutContent(base_path('/routes/web.php'), "\nAuth::routes();\n", FILE_APPEND), @@ -169,6 +180,9 @@ public function testRunWithAdminAndDefaultReadmeCreation() $this->mockNativeFunction( 'RonasIT\ProjectInitializator\Commands', + $this->callFileExists('.env', false), + $this->callFileExists('.env.development'), + $this->callFileGetContent($this->generateResourcePath('md/readme/README.md'), $this->getReadmeTemplateContent('README.md')), $this->callFileGetContent($this->generateResourcePath('md/readme/RESOURCES_AND_CONTACTS.md'), $this->getReadmeTemplateContent('RESOURCES_AND_CONTACTS.md')), $this->callFileGetContent($this->generateResourcePath('md/readme/RESOURCES.md'), $this->getReadmeTemplateContent('RESOURCES.md')), @@ -289,6 +303,9 @@ public function testRunWithAdminAndPartialReadmeCreation() $this->mockNativeFunction( 'RonasIT\ProjectInitializator\Commands', + $this->callFileExists('.env', false), + $this->callFileExists('.env.development'), + $this->callFileGetContent($this->generateResourcePath('md/readme/README.md'), $this->getReadmeTemplateContent('README.md')), $this->callFileGetContent($this->generateResourcePath('md/readme/RESOURCES_AND_CONTACTS.md'), $this->getReadmeTemplateContent('RESOURCES_AND_CONTACTS.md')), $this->callFileGetContent($this->generateResourcePath('md/readme/RESOURCES.md'), $this->getReadmeTemplateContent('RESOURCES.md')), @@ -387,6 +404,9 @@ public function testRunWithAdminAndFullReadmeCreationAndRemovingInitializatorIns $this->mockNativeFunction( 'RonasIT\ProjectInitializator\Commands', + $this->callFileExists('.env', false), + $this->callFileExists('.env.development'), + $this->callFileGetContent($this->generateResourcePath('md/readme/README.md'), $this->getReadmeTemplateContent('README.md')), $this->callFileGetContent($this->generateResourcePath('md/readme/RESOURCES_AND_CONTACTS.md'), $this->getReadmeTemplateContent('RESOURCES_AND_CONTACTS.md')), $this->callFileGetContent($this->generateResourcePath('md/readme/RESOURCES.md'), $this->getReadmeTemplateContent('RESOURCES.md')), @@ -501,6 +521,9 @@ public function testRunWithoutAdminAndUsingTelescope() $this->mockNativeFunction( 'RonasIT\ProjectInitializator\Commands', + $this->callFileExists('.env', false), + $this->callFileExists('.env.development'), + $this->callFileGetContent($this->generateResourcePath('md/readme/README.md'), $this->getReadmeTemplateContent('README.md')), $this->callFileGetContent($this->generateResourcePath('md/readme/RESOURCES_AND_CONTACTS.md'), $this->getReadmeTemplateContent('RESOURCES_AND_CONTACTS.md')), $this->callFileGetContent($this->generateResourcePath('md/readme/RESOURCES.md'), $this->getReadmeTemplateContent('RESOURCES.md')), @@ -605,6 +628,9 @@ public function testRunWithClerkMobileAppWithPintInstalled(): void $this->mockNativeFunction( 'RonasIT\ProjectInitializator\Commands', + $this->callFileExists('.env', false), + $this->callFileExists('.env.development'), + $this->callFileGetContent($this->generateResourcePath('md/readme/README.md'), $this->getReadmeTemplateContent('README.md')), $this->callFileGetContent($this->generateResourcePath('md/readme/RESOURCES_AND_CONTACTS.md'), $this->getReadmeTemplateContent('RESOURCES_AND_CONTACTS.md')), $this->callFileGetContent($this->generateResourcePath('md/readme/RESOURCES.md'), $this->getReadmeTemplateContent('RESOURCES.md')), diff --git a/tests/Support/Traits/InitCommandMockTrait.php b/tests/Support/Traits/InitCommandMockTrait.php index 8a34a8f..6ecd679 100644 --- a/tests/Support/Traits/InitCommandMockTrait.php +++ b/tests/Support/Traits/InitCommandMockTrait.php @@ -13,6 +13,16 @@ protected function callClassExists(string $class, bool $result = true): array return $this->functionCall('class_exists', [$class], $result); } + protected function callCopy(string $source, string $result): array + { + return $this->functionCall('copy', [$source, $result], true); + } + + protected function callFileExists(string $fileName, bool $result = true): array + { + return $this->functionCall('file_exists', [$fileName], $result); + } + protected function callFileGetContent(string $fileName, string $sourceFixture): array { return $this->functionCall('file_get_contents', [$fileName], $sourceFixture); @@ -40,7 +50,7 @@ protected function changeEnvFileCall(string $fileName, string $sourceFixture, st protected function changeConfigFileCall(string $fileName, string $sourceFixture, string $resultFixture): array { return [ - $this->functionCall('file_exists', [$fileName]), + $this->callFileExists($fileName), $this->callFileGetContent($fileName, $this->getFixture($sourceFixture)), $this->callFilePutContent($fileName, $this->getFixture($resultFixture)), ];