Skip to content

Commit 2de6d18

Browse files
authored
Merge pull request #63 from RonasIT/generate-env-development
feat: generate .env.development file if missing
2 parents e85101b + 9b934ec commit 2de6d18

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

src/Commands/InitCommand.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ public function handle(): void
104104
'DB_PASSWORD' => '',
105105
]);
106106

107+
if (!file_exists('.env.development')) {
108+
copy('.env.example', '.env.development');
109+
}
110+
107111
$this->updateEnvFile('.env.development', [
108112
'APP_NAME' => $this->appName,
109113
'APP_URL' => $this->appUrl,

tests/InitCommandTest.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public function testRunWithoutAdminAndReadmeCreationConvertAppNameToPascalCaseTe
2020

2121
$this->mockNativeFunction(
2222
'RonasIT\ProjectInitializator\Commands',
23+
$this->callFileExists('.env', false),
24+
$this->callFileExists('.env.development', false),
25+
26+
$this->callCopy('.env.example', '.env.development'),
27+
2328
$this->callClassExists('Laravel\Telescope\TelescopeServiceProvider'),
2429

2530
$this->callFileGetContent(base_path('composer.json'), $this->getFixture('composer_with_pint_settings.json')),
@@ -60,13 +65,16 @@ public function testRunWithoutAdminAndReadmeCreation()
6065
{
6166
$this->mockNativeFunction(
6267
'\Winter\LaravelConfigWriter',
63-
$this->changeEnvFileCall('.env.example', 'env.example.yml', 'env.example_app_name_pascal_case.yml'),
68+
$this->changeEnvFileCall('.env', 'env.example.yml', 'env.example_app_name_pascal_case.yml'),
6469
$this->changeEnvFileCall('.env.development', 'env.development.yml', 'env.development_app_name_pascal_case.yml'),
6570
$this->changeConfigFileCall(base_path('config/auto-doc.php'), 'auto_doc.php', 'auto_doc_after_changes.php'),
6671
);
6772

6873
$this->mockNativeFunction(
6974
'RonasIT\ProjectInitializator\Commands',
75+
$this->callFileExists('.env'),
76+
$this->callFileExists('.env.development'),
77+
7078
$this->callFileGetContent(base_path('composer.json'), $this->getFixture('composer_with_pint_settings.json')),
7179

7280
$this->callFilePutContent(base_path('/routes/web.php'), "\nAuth::routes();\n", FILE_APPEND),
@@ -115,6 +123,9 @@ public function testRunWithAdminAndWithoutReadmeCreation()
115123

116124
$this->mockNativeFunction(
117125
'RonasIT\ProjectInitializator\Commands',
126+
$this->callFileExists('.env', false),
127+
$this->callFileExists('.env.development'),
128+
118129
$this->callFileGetContent(base_path('composer.json'), $this->getFixture('composer_with_pint_settings.json')),
119130

120131
$this->callFilePutContent(base_path('/routes/web.php'), "\nAuth::routes();\n", FILE_APPEND),
@@ -169,6 +180,9 @@ public function testRunWithAdminAndDefaultReadmeCreation()
169180

170181
$this->mockNativeFunction(
171182
'RonasIT\ProjectInitializator\Commands',
183+
$this->callFileExists('.env', false),
184+
$this->callFileExists('.env.development'),
185+
172186
$this->callFileGetContent($this->generateResourcePath('md/readme/README.md'), $this->getReadmeTemplateContent('README.md')),
173187
$this->callFileGetContent($this->generateResourcePath('md/readme/RESOURCES_AND_CONTACTS.md'), $this->getReadmeTemplateContent('RESOURCES_AND_CONTACTS.md')),
174188
$this->callFileGetContent($this->generateResourcePath('md/readme/RESOURCES.md'), $this->getReadmeTemplateContent('RESOURCES.md')),
@@ -289,6 +303,9 @@ public function testRunWithAdminAndPartialReadmeCreation()
289303

290304
$this->mockNativeFunction(
291305
'RonasIT\ProjectInitializator\Commands',
306+
$this->callFileExists('.env', false),
307+
$this->callFileExists('.env.development'),
308+
292309
$this->callFileGetContent($this->generateResourcePath('md/readme/README.md'), $this->getReadmeTemplateContent('README.md')),
293310
$this->callFileGetContent($this->generateResourcePath('md/readme/RESOURCES_AND_CONTACTS.md'), $this->getReadmeTemplateContent('RESOURCES_AND_CONTACTS.md')),
294311
$this->callFileGetContent($this->generateResourcePath('md/readme/RESOURCES.md'), $this->getReadmeTemplateContent('RESOURCES.md')),
@@ -387,6 +404,9 @@ public function testRunWithAdminAndFullReadmeCreationAndRemovingInitializatorIns
387404

388405
$this->mockNativeFunction(
389406
'RonasIT\ProjectInitializator\Commands',
407+
$this->callFileExists('.env', false),
408+
$this->callFileExists('.env.development'),
409+
390410
$this->callFileGetContent($this->generateResourcePath('md/readme/README.md'), $this->getReadmeTemplateContent('README.md')),
391411
$this->callFileGetContent($this->generateResourcePath('md/readme/RESOURCES_AND_CONTACTS.md'), $this->getReadmeTemplateContent('RESOURCES_AND_CONTACTS.md')),
392412
$this->callFileGetContent($this->generateResourcePath('md/readme/RESOURCES.md'), $this->getReadmeTemplateContent('RESOURCES.md')),
@@ -501,6 +521,9 @@ public function testRunWithoutAdminAndUsingTelescope()
501521

502522
$this->mockNativeFunction(
503523
'RonasIT\ProjectInitializator\Commands',
524+
$this->callFileExists('.env', false),
525+
$this->callFileExists('.env.development'),
526+
504527
$this->callFileGetContent($this->generateResourcePath('md/readme/README.md'), $this->getReadmeTemplateContent('README.md')),
505528
$this->callFileGetContent($this->generateResourcePath('md/readme/RESOURCES_AND_CONTACTS.md'), $this->getReadmeTemplateContent('RESOURCES_AND_CONTACTS.md')),
506529
$this->callFileGetContent($this->generateResourcePath('md/readme/RESOURCES.md'), $this->getReadmeTemplateContent('RESOURCES.md')),
@@ -605,6 +628,9 @@ public function testRunWithClerkMobileAppWithPintInstalled(): void
605628

606629
$this->mockNativeFunction(
607630
'RonasIT\ProjectInitializator\Commands',
631+
$this->callFileExists('.env', false),
632+
$this->callFileExists('.env.development'),
633+
608634
$this->callFileGetContent($this->generateResourcePath('md/readme/README.md'), $this->getReadmeTemplateContent('README.md')),
609635
$this->callFileGetContent($this->generateResourcePath('md/readme/RESOURCES_AND_CONTACTS.md'), $this->getReadmeTemplateContent('RESOURCES_AND_CONTACTS.md')),
610636
$this->callFileGetContent($this->generateResourcePath('md/readme/RESOURCES.md'), $this->getReadmeTemplateContent('RESOURCES.md')),

tests/Support/Traits/InitCommandMockTrait.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ protected function callClassExists(string $class, bool $result = true): array
1313
return $this->functionCall('class_exists', [$class], $result);
1414
}
1515

16+
protected function callCopy(string $source, string $result): array
17+
{
18+
return $this->functionCall('copy', [$source, $result], true);
19+
}
20+
21+
protected function callFileExists(string $fileName, bool $result = true): array
22+
{
23+
return $this->functionCall('file_exists', [$fileName], $result);
24+
}
25+
1626
protected function callFileGetContent(string $fileName, string $sourceFixture): array
1727
{
1828
return $this->functionCall('file_get_contents', [$fileName], $sourceFixture);
@@ -40,7 +50,7 @@ protected function changeEnvFileCall(string $fileName, string $sourceFixture, st
4050
protected function changeConfigFileCall(string $fileName, string $sourceFixture, string $resultFixture): array
4151
{
4252
return [
43-
$this->functionCall('file_exists', [$fileName]),
53+
$this->callFileExists($fileName),
4454
$this->callFileGetContent($fileName, $this->getFixture($sourceFixture)),
4555
$this->callFilePutContent($fileName, $this->getFixture($resultFixture)),
4656
];

0 commit comments

Comments
 (0)