Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/Commands/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ public function handle(): void

$this->appUrl = $this->ask('Please enter an application URL', "https://api.dev.{$kebabName}.com");

$envFile = (file_exists('.env')) ? '.env' : '.env.example';

$envConfig = [
'APP_NAME' => $this->appName,
'DB_CONNECTION' => $this->dbConnection,
Expand All @@ -115,7 +113,13 @@ public function handle(): void
'DB_PASSWORD' => '',
];

$this->updateEnvFile($envFile, $envConfig);
$this->updateEnvFile('.env.example', $envConfig);

if (!file_exists('.env')) {
copy('.env.example', '.env');
} else {
$this->updateEnvFile('.env', $envConfig);
}

if (!file_exists('.env.development')) {
copy('.env.example', '.env.development');
Expand Down Expand Up @@ -166,12 +170,9 @@ public function handle(): void
$data['CLERK_ALLOWED_ORIGINS'] = '';
}

$this->updateEnvFile('.env', $data);
$this->updateEnvFile('.env.example', $data);
$this->updateEnvFile('.env.development', $data);
$this->updateEnvFile($envFile, $data);

if ($envFile !== '.env.example') {
$this->updateEnvFile('.env.example', $data);
}
}

if ($this->confirm('Do you want to generate an admin user?', true)) {
Expand Down
27 changes: 23 additions & 4 deletions tests/InitCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function testRunWithoutAdminAndReadmeCreationConvertAppNameToPascalCaseTe
$this->callFileExists('.env', false),
$this->callFileExists('.env.development', false),

$this->callCopy('.env.example', '.env'),
$this->callCopy('.env.example', '.env.development'),

$this->callClassExists('Laravel\Telescope\TelescopeServiceProvider'),
Expand Down Expand Up @@ -66,6 +67,7 @@ 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('config/auto-doc.php', 'auto_doc.php', 'auto_doc_after_changes.php'),
Expand Down Expand Up @@ -130,6 +132,8 @@ public function testRunWithAdminAndWithoutReadmeCreation()
$this->callFileExists('.env', false),
$this->callFileExists('.env.development'),

$this->callCopy('.env.example', '.env'),

$this->callFileGetContent(base_path('composer.json'), $this->getFixture('composer_with_pint_settings.json')),

$this->callFilePutContent('database/migrations/2018_11_11_111111_add_default_admin.php', $this->getFixture('migration.php')),
Expand Down Expand Up @@ -178,8 +182,9 @@ public function testRunWithAdminAndDefaultReadmeCreation()
'\Winter\LaravelConfigWriter',
$this->changeEnvFileCall('.env.example', 'env.example.yml', 'env.example_app_name_not_pascal_case.yml'),
$this->changeEnvFileCall('.env.development', 'env.development.yml', 'env.development_app_name_not_pascal_case.yml'),
$this->changeEnvFileCall('.env.development', 'env.development_app_name_not_pascal_case.yml', 'env.development_clerk_credentials_added.yml'),
$this->changeEnvFileCall('.env', 'env.example_app_name_not_pascal_case.yml', 'env.example_clerk_credentials_added.yml'),
$this->changeEnvFileCall('.env.example', 'env.example_app_name_not_pascal_case.yml', 'env.example_clerk_credentials_added.yml'),
$this->changeEnvFileCall('.env.development', 'env.development_app_name_not_pascal_case.yml', 'env.development_clerk_credentials_added.yml'),
$this->changeConfigFileCall('config/auto-doc.php', 'auto_doc.php', 'auto_doc_after_changes.php'),
$this->changeConfigFileCall('config/telescope.php', 'telescope_config.php', 'telescope_config_after_initialization.php'),
);
Expand All @@ -189,6 +194,8 @@ public function testRunWithAdminAndDefaultReadmeCreation()
$this->callFileExists('.env', false),
$this->callFileExists('.env.development'),

$this->callCopy('.env.example', '.env'),

$this->callFileGetContent(base_path('composer.json'), $this->getFixture('composer_with_pint_settings.json')),

$this->callFilePutContent('database/migrations/2018_11_11_111111_users_add_clerk_id_field.php', $this->getFixture('users_add_clerk_id_field_migration.php')),
Expand Down Expand Up @@ -322,6 +329,8 @@ public function testRunWithAdminAndPartialReadmeCreation()
$this->callFileExists('.env', false),
$this->callFileExists('.env.development'),

$this->callCopy('.env.example', '.env'),

$this->callFileGetContent(base_path('composer.json'), $this->getFixture('composer_with_pint_settings.json')),

$this->callFilePutContent(base_path('composer.json'), $this->getFixture('composer_with_pint_settings.json')),
Expand Down Expand Up @@ -429,6 +438,8 @@ public function testRunWithAdminAndFullReadmeCreationAndRemovingInitializatorIns
$this->callFileExists('.env', false),
$this->callFileExists('.env.development'),

$this->callCopy('.env.example', '.env'),

$this->callFileGetContent(base_path('composer.json'), $this->getFixture('composer_with_pint_settings.json')),

$this->callFilePutContent('database/migrations/2018_11_11_111111_add_default_admin.php', $this->getFixture('migration.php')),
Expand Down Expand Up @@ -554,6 +565,8 @@ public function testRunWithoutAdminAndUsingTelescope()
$this->callFileExists('.env', false),
$this->callFileExists('.env.development'),

$this->callCopy('.env.example', '.env'),

$this->callFileGetContent(base_path('composer.json'), $this->getFixture('composer_with_pint_settings.json')),

$this->callFilePutContent('database/migrations/2018_11_11_111111_add_telescope_admin.php', $this->getFixture('telescope_users_table_migration.php')),
Expand Down Expand Up @@ -662,8 +675,9 @@ public function testRunWithClerkMobileAppWithPintInstalled(): void
'\Winter\LaravelConfigWriter',
$this->changeEnvFileCall('.env.example', 'env.example.yml', 'env.example_app_name_not_pascal_case.yml'),
$this->changeEnvFileCall('.env.development', 'env.development.yml', 'env.development_app_name_not_pascal_case.yml'),
$this->changeEnvFileCall('.env.development', 'env.development_app_name_not_pascal_case.yml', 'env.development_clerk_credentials_added_mobile_app.yml'),
$this->changeEnvFileCall('.env', 'env.example_app_name_not_pascal_case.yml', 'env.example_clerk_credentials_added_mobile_app.yml'),
$this->changeEnvFileCall('.env.example', 'env.example_app_name_not_pascal_case.yml', 'env.example_clerk_credentials_added_mobile_app.yml'),
$this->changeEnvFileCall('.env.development', 'env.development_app_name_not_pascal_case.yml', 'env.development_clerk_credentials_added_mobile_app.yml'),
$this->changeConfigFileCall('config/auto-doc.php', 'auto_doc.php', 'auto_doc_after_changes.php'),
$this->changeConfigFileCall('config/telescope.php', 'telescope_config.php', 'telescope_config_after_initialization.php'),
);
Expand All @@ -673,6 +687,8 @@ public function testRunWithClerkMobileAppWithPintInstalled(): void
$this->callFileExists('.env', false),
$this->callFileExists('.env.development'),

$this->callCopy('.env.example', '.env'),

$this->callFileGetContent(base_path('composer.json'), $this->getFixture('composer_with_pint_settings.json')),

$this->callFilePutContent('database/migrations/2018_11_11_111111_users_add_clerk_id_field.php', $this->getFixture('users_add_clerk_id_field_migration.php')),
Expand Down Expand Up @@ -793,8 +809,9 @@ public function testRunWithClerkAdditionalAdminsWithoutDefaultAdmin(): void
'\Winter\LaravelConfigWriter',
$this->changeEnvFileCall('.env.example', 'env.example.yml', 'env.example_app_name_not_pascal_case.yml'),
$this->changeEnvFileCall('.env.development', 'env.development.yml', 'env.development_app_name_not_pascal_case.yml'),
$this->changeEnvFileCall('.env.development', 'env.development_app_name_not_pascal_case.yml', 'env.development_clerk_credentials_added.yml'),
$this->changeEnvFileCall('.env', 'env.example.yml', 'env.example_clerk_credentials_added.yml'),
$this->changeEnvFileCall('.env.example', 'env.example.yml', 'env.example_clerk_credentials_added.yml'),
$this->changeEnvFileCall('.env.development', 'env.development_app_name_not_pascal_case.yml', 'env.development_clerk_credentials_added.yml'),
$this->changeConfigFileCall('config/auto-doc.php', 'auto_doc.php', 'auto_doc_after_changes.php'),
$this->changeConfigFileCall('config/telescope.php', 'telescope_config.php', 'telescope_config_after_initialization.php'),
);
Expand All @@ -804,7 +821,9 @@ public function testRunWithClerkAdditionalAdminsWithoutDefaultAdmin(): void
$this->callFileExists('.env', false),
$this->callFileExists('.env.development'),

$this->callFileGetContent(base_path('composer.json'), $this->getFixture('composer_with_pint_settings.json')),
$this->callCopy('.env.example', '.env'),

$this->callFileGetContent(base_path('composer.json'), $this->getFixture('composer_with_pint_settings.json')),

$this->callFilePutContent('database/migrations/2018_11_11_111111_users_add_clerk_id_field.php', $this->getFixture('users_add_clerk_id_field_migration.php')),
$this->callFilePutContent('app/Support/Clerk/ClerkUserRepository.php', $this->getFixture('clerk_user_repository.php')),
Expand Down