From 793d3eda9d83afd9d11c9a43fc1f7ae471957db0 Mon Sep 17 00:00:00 2001 From: Ni Nelli Date: Fri, 24 Oct 2025 13:00:18 +0900 Subject: [PATCH 1/4] fix: fix admin name option refs: https://github.com/RonasIT/laravel-project-initializator/issues/55 --- src/Commands/InitCommand.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Commands/InitCommand.php b/src/Commands/InitCommand.php index 0275ff9..0cadf6f 100644 --- a/src/Commands/InitCommand.php +++ b/src/Commands/InitCommand.php @@ -323,10 +323,12 @@ protected function runMigrations(): void protected function createAdminUser(string $kebabName, string $serviceKey = '', string $serviceName = ''): array { - $adminEmail = when(empty($serviceKey), "admin@{$kebabName}.com", "admin.{$serviceKey}@{$kebabName}.com"); + $isServiceAdmin = (!empty($serviceKey) && !empty($serviceName)); + + $adminEmail = when($isServiceAdmin, "admin.{$serviceKey}@{$kebabName}.com", "admin@{$kebabName}.com"); $defaultPassword = substr(md5(uniqid()), 0, 8); - $serviceLabel = when(!empty($serviceName), " for {$serviceName}"); + $serviceLabel = when($isServiceAdmin, " for {$serviceName}"); $adminCredentials = [ 'email' => $this->ask("Please enter admin email{$serviceLabel}", $adminEmail), @@ -334,11 +336,11 @@ protected function createAdminUser(string $kebabName, string $serviceKey = '', s ]; if ($this->authType === AuthTypeEnum::None) { - $adminCredentials['name'] = $this->ask("Please enter admin name{$serviceLabel}", "{$serviceName} Admin"); + $adminCredentials['name'] = $this->ask("Please enter admin name{$serviceLabel}", when($isServiceAdmin, "{$serviceName} Admin", 'Admin')); $adminCredentials['role_id'] = $this->ask("Please enter admin role id{$serviceLabel}", RoleEnum::Admin->value); } - if (empty($serviceName)) { + if (!$isServiceAdmin) { $this->adminCredentials = $adminCredentials; } From 02d896446ceb4e3b968fd8fc3dc1b90bdcfda737 Mon Sep 17 00:00:00 2001 From: Ni Nelli Date: Fri, 7 Nov 2025 13:42:55 +0900 Subject: [PATCH 2/4] refactor: clean createAdminUser method, add tests refs: https://github.com/RonasIT/laravel-project-initializator/issues/55 --- src/Commands/InitCommand.php | 4 +- tests/InitCommandTest.php | 149 ++++++++++++++++++ ..._add_default_admin_default_credentials.php | 28 ++++ ...ins_add_nova_admin_default_credentials.php | 28 ++++ ...dd_telescope_admin_default_credentials.php | 28 ++++ ..._auth_default_admins_credentials_readme.md | 40 +++++ ...admin_default_credentials_user_inputs.json | 33 ++++ ..._auth_default_admins_credentials_readme.md | 38 +++++ ...admin_default_credentials_user_inputs.json | 39 +++++ .../nova_users_default_credentials.php | 30 ++++ .../telescope_users_default_credentials.php | 30 ++++ ...sers_default_admin_default_credentials.php | 30 ++++ 12 files changed, 476 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/InitCommandTest/admins_add_default_admin_default_credentials.php create mode 100644 tests/fixtures/InitCommandTest/admins_add_nova_admin_default_credentials.php create mode 100644 tests/fixtures/InitCommandTest/admins_add_telescope_admin_default_credentials.php create mode 100644 tests/fixtures/InitCommandTest/clerk_auth_default_admins_credentials_readme.md create mode 100644 tests/fixtures/InitCommandTest/clerk_auth_type_admin_default_credentials_user_inputs.json create mode 100644 tests/fixtures/InitCommandTest/none_auth_default_admins_credentials_readme.md create mode 100644 tests/fixtures/InitCommandTest/none_auth_type_admin_default_credentials_user_inputs.json create mode 100644 tests/fixtures/InitCommandTest/nova_users_default_credentials.php create mode 100644 tests/fixtures/InitCommandTest/telescope_users_default_credentials.php create mode 100644 tests/fixtures/InitCommandTest/users_default_admin_default_credentials.php diff --git a/src/Commands/InitCommand.php b/src/Commands/InitCommand.php index 0cadf6f..dc18b67 100644 --- a/src/Commands/InitCommand.php +++ b/src/Commands/InitCommand.php @@ -335,8 +335,10 @@ protected function createAdminUser(string $kebabName, string $serviceKey = '', s 'password' => $this->ask("Please enter admin password{$serviceLabel}", $defaultPassword), ]; + $adminName = when($isServiceAdmin, "{$serviceName} Admin", 'Admin'); + if ($this->authType === AuthTypeEnum::None) { - $adminCredentials['name'] = $this->ask("Please enter admin name{$serviceLabel}", when($isServiceAdmin, "{$serviceName} Admin", 'Admin')); + $adminCredentials['name'] = $this->ask("Please enter admin name{$serviceLabel}", $adminName); $adminCredentials['role_id'] = $this->ask("Please enter admin role id{$serviceLabel}", RoleEnum::Admin->value); } diff --git a/tests/InitCommandTest.php b/tests/InitCommandTest.php index c077c2f..c62c59f 100644 --- a/tests/InitCommandTest.php +++ b/tests/InitCommandTest.php @@ -2,7 +2,10 @@ namespace RonasIT\ProjectInitializator\Tests; +use RonasIT\ProjectInitializator\Commands\InitCommand; use RonasIT\ProjectInitializator\Tests\Support\Traits\InitCommandMockTrait; +use Symfony\Component\Console\Application; +use Symfony\Component\Console\Tester\CommandTester; class InitCommandTest extends TestCase { @@ -958,4 +961,150 @@ public function testRunWithClerkAdditionalAdminsWithoutDefaultAdmin(): void ->expectsConfirmation('Do you want to uninstall project-initializator package?') ->assertExitCode(0); } + + public function testDefaultAdminsCredentialsNoneAuth() + { + $this->mockNativeFunction( + '\RonasIT\ProjectInitializator\Extensions\ConfigWriter', + $this->callFileExists(base_path('config/telescope.php')), + $this->callFileGetContent(base_path('config/telescope.php'), $this->getFixture('telescope_config.php')), + $this->callFileExists(base_path('config/auto-doc.php')), + $this->callFileGetContent(base_path('config/auto-doc.php'), $this->getFixture('auto_doc.php')), + ); + + $this->mockNativeFunction( + '\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->callFilePutContent(base_path('config/telescope.php'), $this->getFixture('telescope_config_after_initialization.php')), + $this->callFilePutContent(base_path('config/auto-doc.php'), $this->getFixture('auto_doc_after_changes.php')), + ); + + $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')), + $this->callFileGetContent($this->generateResourcePath('md/readme/CONTACTS.md'), $this->getReadmeTemplateContent('CONTACTS.md')), + $this->callFileGetContent($this->generateResourcePath('md/readme/CREDENTIALS_AND_ACCESS.md'), $this->getReadmeTemplateContent('CREDENTIALS_AND_ACCESS.md')), + $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('users_default_admin_default_credentials.php')), + $this->callFilePutContent('database/migrations/2018_11_11_111111_add_telescope_admin.php', $this->getFixture('telescope_users_default_credentials.php')), + $this->callFilePutContent('database/migrations/2018_11_11_111111_add_nova_admin.php', $this->getFixture('nova_users_default_credentials.php')), + $this->callFilePutContent('README.md', $this->getFixture('none_auth_default_admins_credentials_readme.md')), + $this->callFilePutContent(base_path('composer.json'), $this->getFixture('composer_with_pint_settings.json')), + $this->callFilePutContent(base_path('/routes/web.php'), "\nAuth::routes();\n", FILE_APPEND), + + $this->callShellExec('composer require laravel/ui --ansi'), + $this->callShellExec('composer require ronasit/laravel-helpers --ansi'), + $this->callShellExec('composer require ronasit/laravel-swagger --ansi'), + $this->callShellExec('php artisan vendor:publish --provider="RonasIT\AutoDoc\AutoDocServiceProvider" --ansi'), + $this->callShellExec('composer require --dev ronasit/laravel-entity-generator --ansi'), + $this->callShellExec('composer require --dev laravel/pint --ansi'), + $this->callShellExec('php artisan vendor:publish --tag=pint-config --ansi'), + $this->callShellExec('composer require --dev brainmaestro/composer-git-hooks --ansi'), + $this->callShellExec('./vendor/bin/cghooks update --ansi'), + $this->callShellExec('php artisan lang:publish --ansi'), + $this->callShellExec('composer require ronasit/laravel-telescope-extension --ansi'), + $this->callShellExec('php artisan telescope:install --ansi'), + $this->callShellExec('php artisan vendor:publish --tag=initializator-web-login --force'), + $this->callShellExec('php artisan migrate --ansi'), + ); + + $consoleApplication = new Application(); + $consoleApplication->add(app(InitCommand::class)); + + $command = $consoleApplication->find('init'); + $command->setLaravel(app()); + + $tester = new CommandTester($command); + $tester->setInputs($this->getJsonFixture('none_auth_type_admin_default_credentials_user_inputs')); + + $tester->execute([ + 'command' => $command->getName(), + 'application-name' => 'My App', + ]); + } + + public function testDefaultAdminsCredentialsClerkAuth() + { + $this->mockNativeFunction( + '\RonasIT\ProjectInitializator\Extensions\ConfigWriter', + $this->callFileExists(base_path('config/telescope.php')), + $this->callFileGetContent(base_path('config/telescope.php'), $this->getFixture('telescope_config.php')), + $this->callFileExists(base_path('config/auto-doc.php')), + $this->callFileGetContent(base_path('config/auto-doc.php'), $this->getFixture('auto_doc.php')), + ); + + $this->mockNativeFunction( + '\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.example', 'env.example.yml', 'env.example_clerk_credentials_added.yml'), + $this->callFilePutContent(base_path('config/telescope.php'), $this->getFixture('telescope_config_after_initialization.php')), + $this->callFilePutContent(base_path('config/auto-doc.php'), $this->getFixture('auto_doc_after_changes.php')), + ); + + $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')), + $this->callFileGetContent($this->generateResourcePath('md/readme/CONTACTS.md'), $this->getReadmeTemplateContent('CONTACTS.md')), + $this->callFileGetContent($this->generateResourcePath('md/readme/CREDENTIALS_AND_ACCESS.md'), $this->getReadmeTemplateContent('CREDENTIALS_AND_ACCESS.md')), + $this->callFileGetContent($this->generateResourcePath('md/readme/CLERK.md'), $this->getReadmeTemplateContent('CLERK.md')), + $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')), + $this->callFilePutContent('database/migrations/2018_11_11_111111_admins_create_table.php', $this->getFixture('admins_table_migration.php')), + $this->callFilePutContent('database/migrations/2018_11_11_111111_add_default_admin.php', $this->getFixture('admins_add_default_admin_default_credentials.php')), + $this->callGlob(base_path('database/migrations/*_admins_create_table.php'), [base_path('database/migrations/2018_11_11_111111_admins_create_table.php')]), + $this->callFilePutContent('database/migrations/2018_11_11_111111_add_telescope_admin.php', $this->getFixture('admins_add_telescope_admin_default_credentials.php')), + $this->callGlob(base_path('database/migrations/*_admins_create_table.php'), [base_path('database/migrations/2018_11_11_111111_admins_create_table.php')]), + $this->callFilePutContent('database/migrations/2018_11_11_111111_add_nova_admin.php', $this->getFixture('admins_add_nova_admin_default_credentials.php')), + $this->callFilePutContent('README.md', $this->getFixture('clerk_auth_default_admins_credentials_readme.md')), + $this->callFilePutContent(base_path('composer.json'), $this->getFixture('composer_with_pint_settings.json')), + $this->callFilePutContent(base_path('/routes/web.php'), "\nAuth::routes();\n", FILE_APPEND), + + $this->callShellExec('composer require laravel/ui --ansi'), + $this->callShellExec('composer require ronasit/laravel-helpers --ansi'), + $this->callShellExec('composer require ronasit/laravel-swagger --ansi'), + $this->callShellExec('php artisan vendor:publish --provider="RonasIT\AutoDoc\AutoDocServiceProvider" --ansi'), + $this->callShellExec('composer require --dev ronasit/laravel-entity-generator --ansi'), + $this->callShellExec('composer require --dev laravel/pint --ansi'), + $this->callShellExec('php artisan vendor:publish --tag=pint-config --ansi'), + $this->callShellExec('composer require --dev brainmaestro/composer-git-hooks --ansi'), + $this->callShellExec('./vendor/bin/cghooks update --ansi'), + $this->callShellExec('php artisan lang:publish --ansi'), + $this->callShellExec('composer require ronasit/laravel-clerk --ansi'), + $this->callShellExec('php artisan laravel-clerk:install --ansi'), + $this->callShellExec('composer require ronasit/laravel-telescope-extension --ansi'), + $this->callShellExec('php artisan telescope:install --ansi'), + $this->callShellExec('php artisan vendor:publish --tag=initializator-web-login --force'), + $this->callShellExec('php artisan migrate --ansi'), + ); + + $consoleApplication = new Application(); + $consoleApplication->add(app(InitCommand::class)); + + $command = $consoleApplication->find('init'); + $command->setLaravel(app()); + + $tester = new CommandTester($command); + $tester->setInputs($this->getJsonFixture('clerk_auth_type_admin_default_credentials_user_inputs')); + + $tester->execute([ + 'command' => $command->getName(), + 'application-name' => 'My App', + ]); + } } diff --git a/tests/fixtures/InitCommandTest/admins_add_default_admin_default_credentials.php b/tests/fixtures/InitCommandTest/admins_add_default_admin_default_credentials.php new file mode 100644 index 0000000..00e43f0 --- /dev/null +++ b/tests/fixtures/InitCommandTest/admins_add_default_admin_default_credentials.php @@ -0,0 +1,28 @@ +insert([ + 'email' => 'admin@my-app.com', + 'password' => Hash::make('123456'), + ]); + } + } + + public function down(): void + { + if (!App::environment('testing')) { + DB::table('admins') + ->where('email', 'admin@my-app.com') + ->delete(); + } + } +}; diff --git a/tests/fixtures/InitCommandTest/admins_add_nova_admin_default_credentials.php b/tests/fixtures/InitCommandTest/admins_add_nova_admin_default_credentials.php new file mode 100644 index 0000000..d0dcf0c --- /dev/null +++ b/tests/fixtures/InitCommandTest/admins_add_nova_admin_default_credentials.php @@ -0,0 +1,28 @@ +insert([ + 'email' => 'admin.nova@my-app.com', + 'password' => Hash::make('123456'), + ]); + } + } + + public function down(): void + { + if (!App::environment('testing')) { + DB::table('admins') + ->where('email', 'admin.nova@my-app.com') + ->delete(); + } + } +}; diff --git a/tests/fixtures/InitCommandTest/admins_add_telescope_admin_default_credentials.php b/tests/fixtures/InitCommandTest/admins_add_telescope_admin_default_credentials.php new file mode 100644 index 0000000..0838c4b --- /dev/null +++ b/tests/fixtures/InitCommandTest/admins_add_telescope_admin_default_credentials.php @@ -0,0 +1,28 @@ +insert([ + 'email' => 'admin.telescope@my-app.com', + 'password' => Hash::make('654321'), + ]); + } + } + + public function down(): void + { + if (!App::environment('testing')) { + DB::table('admins') + ->where('email', 'admin.telescope@my-app.com') + ->delete(); + } + } +}; diff --git a/tests/fixtures/InitCommandTest/clerk_auth_default_admins_credentials_readme.md b/tests/fixtures/InitCommandTest/clerk_auth_default_admins_credentials_readme.md new file mode 100644 index 0000000..e148ea4 --- /dev/null +++ b/tests/fixtures/InitCommandTest/clerk_auth_default_admins_credentials_readme.md @@ -0,0 +1,40 @@ +# My App + +This project implements an API for the My App Web app. + +## Project Resources & Contacts + +This section provides quick links to various resources and contacts associated +with this project. It's here to streamline your navigation and communication +process, so you can efficiently find what you need or reach out to who you need. + +### Resources + +Below are links to tools and services used in this project: +- [Laravel Telescope](): This is debug assistant for the Laravel framework. (will be added later) +- [Laravel Nova](): This is admin panel for the Laravel framework. (will be added later) +- [API Documentation](https://mysite.com) + +### Contacts + +Should you need assistance or have questions, feel free to connect with the following individuals: +- Manager: If you have any high-level project concerns, feel free to get in touch with our project manager. [Connect with Manager](mailto:manager@mail.com) +- Code Owner/Team Lead: For specific questions about the codebase or technical aspects, reach out to our team lead. [Connect with Team Lead](mailto:test@example.com) + +Please be mindful of each individual's preferred contact method and office hours. + +## Credentials and Access + +Default admin access: +- email `admin@my-app.com` +- password `123456` + +Laravel Telescope access: +- email `admin.telescope@my-app.com` +- password `654321` + +Laravel Nova access: +- email `admin.nova@my-app.com` +- password `123456` + +Core auth solution is [Clerk](https://clerk.com) so in `development` environment use any test phones and emails from [this list](https://clerk.com/docs/testing/test-emails-and-phones) diff --git a/tests/fixtures/InitCommandTest/clerk_auth_type_admin_default_credentials_user_inputs.json b/tests/fixtures/InitCommandTest/clerk_auth_type_admin_default_credentials_user_inputs.json new file mode 100644 index 0000000..fa79670 --- /dev/null +++ b/tests/fixtures/InitCommandTest/clerk_auth_type_admin_default_credentials_user_inputs.json @@ -0,0 +1,33 @@ +[ + "no", + "test@example.com", + "https://mysite.com", + "Web", + "clerk", + "yes", + null, + "123456", + "yes", + "yes", + "no", + "no", + "no", + "no", + "no", + "later", + "later", + "manager@mail.com", + "no", + "no", + "no", + "yes", + "no", + null, + "654321", + "no", + null, + "123456", + "no", + "no", + "no" +] \ No newline at end of file diff --git a/tests/fixtures/InitCommandTest/none_auth_default_admins_credentials_readme.md b/tests/fixtures/InitCommandTest/none_auth_default_admins_credentials_readme.md new file mode 100644 index 0000000..982b03a --- /dev/null +++ b/tests/fixtures/InitCommandTest/none_auth_default_admins_credentials_readme.md @@ -0,0 +1,38 @@ +# My App + +This project implements an API for the My App Web app. + +## Project Resources & Contacts + +This section provides quick links to various resources and contacts associated +with this project. It's here to streamline your navigation and communication +process, so you can efficiently find what you need or reach out to who you need. + +### Resources + +Below are links to tools and services used in this project: +- [Laravel Telescope](): This is debug assistant for the Laravel framework. (will be added later) +- [Laravel Nova](): This is admin panel for the Laravel framework. (will be added later) +- [API Documentation](https://mysite.com) + +### Contacts + +Should you need assistance or have questions, feel free to connect with the following individuals: +- Manager: If you have any high-level project concerns, feel free to get in touch with our project manager. [Connect with Manager](mailto:manager@mail.com) +- Code Owner/Team Lead: For specific questions about the codebase or technical aspects, reach out to our team lead. [Connect with Team Lead](mailto:test@example.com) + +Please be mindful of each individual's preferred contact method and office hours. + +## Credentials and Access + +Default admin access: +- email `admin@my-app.com` +- password `123456` + +Laravel Telescope access: +- email `admin.telescope@my-app.com` +- password `654321` + +Laravel Nova access: +- email `admin.nova@my-app.com` +- password `123456` diff --git a/tests/fixtures/InitCommandTest/none_auth_type_admin_default_credentials_user_inputs.json b/tests/fixtures/InitCommandTest/none_auth_type_admin_default_credentials_user_inputs.json new file mode 100644 index 0000000..9247880 --- /dev/null +++ b/tests/fixtures/InitCommandTest/none_auth_type_admin_default_credentials_user_inputs.json @@ -0,0 +1,39 @@ +[ + "no", + "test@example.com", + "https://mysite.com", + "Web", + "none", + "yes", + null, + "123456", + null, + 1, + "yes", + "yes", + "no", + "no", + "no", + "no", + "no", + "later", + "later", + "manager@mail.com", + "no", + "no", + "no", + "yes", + "no", + null, + "654321", + null, + 1, + "no", + null, + "123456", + null, + 1, + "no", + "no", + "no" +] \ No newline at end of file diff --git a/tests/fixtures/InitCommandTest/nova_users_default_credentials.php b/tests/fixtures/InitCommandTest/nova_users_default_credentials.php new file mode 100644 index 0000000..7e7cb88 --- /dev/null +++ b/tests/fixtures/InitCommandTest/nova_users_default_credentials.php @@ -0,0 +1,30 @@ +insert([ + 'name' => 'Laravel Nova Admin', + 'email' => 'admin.nova@my-app.com', + 'password' => Hash::make('123456'), + 'role_id' => 1, + ]); + } + } + + public function down(): void + { + if (!App::environment('testing')) { + DB::table('users') + ->where('email', 'admin.nova@my-app.com') + ->delete(); + } + } +}; diff --git a/tests/fixtures/InitCommandTest/telescope_users_default_credentials.php b/tests/fixtures/InitCommandTest/telescope_users_default_credentials.php new file mode 100644 index 0000000..de69839 --- /dev/null +++ b/tests/fixtures/InitCommandTest/telescope_users_default_credentials.php @@ -0,0 +1,30 @@ +insert([ + 'name' => 'Laravel Telescope Admin', + 'email' => 'admin.telescope@my-app.com', + 'password' => Hash::make('654321'), + 'role_id' => 1, + ]); + } + } + + public function down(): void + { + if (!App::environment('testing')) { + DB::table('users') + ->where('email', 'admin.telescope@my-app.com') + ->delete(); + } + } +}; diff --git a/tests/fixtures/InitCommandTest/users_default_admin_default_credentials.php b/tests/fixtures/InitCommandTest/users_default_admin_default_credentials.php new file mode 100644 index 0000000..b4608fa --- /dev/null +++ b/tests/fixtures/InitCommandTest/users_default_admin_default_credentials.php @@ -0,0 +1,30 @@ +insert([ + 'name' => 'Admin', + 'email' => 'admin@my-app.com', + 'password' => Hash::make('123456'), + 'role_id' => 1, + ]); + } + } + + public function down(): void + { + if (!App::environment('testing')) { + DB::table('users') + ->where('email', 'admin@my-app.com') + ->delete(); + } + } +}; From e2ab430c9a94bfc652b751395239a4ba9a2f51bd Mon Sep 17 00:00:00 2001 From: Ni Nelli Date: Fri, 7 Nov 2025 15:15:55 +0900 Subject: [PATCH 3/4] test: fix tests refs: https://github.com/RonasIT/laravel-project-initializator/issues/55 --- tests/InitCommandTest.php | 58 +++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/tests/InitCommandTest.php b/tests/InitCommandTest.php index 4281598..d90a5bf 100644 --- a/tests/InitCommandTest.php +++ b/tests/InitCommandTest.php @@ -913,20 +913,12 @@ public function testRunWithClerkAdditionalAdminsWithoutDefaultAdmin(): void public function testDefaultAdminsCredentialsNoneAuth() { - $this->mockNativeFunction( - '\RonasIT\ProjectInitializator\Extensions\ConfigWriter', - $this->callFileExists(base_path('config/telescope.php')), - $this->callFileGetContent(base_path('config/telescope.php'), $this->getFixture('telescope_config.php')), - $this->callFileExists(base_path('config/auto-doc.php')), - $this->callFileGetContent(base_path('config/auto-doc.php'), $this->getFixture('auto_doc.php')), - ); - $this->mockNativeFunction( '\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->callFilePutContent(base_path('config/telescope.php'), $this->getFixture('telescope_config_after_initialization.php')), - $this->callFilePutContent(base_path('config/auto-doc.php'), $this->getFixture('auto_doc_after_changes.php')), + $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'), ); $this->mockNativeFunction( @@ -934,17 +926,11 @@ public function testDefaultAdminsCredentialsNoneAuth() $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')), - $this->callFileGetContent($this->generateResourcePath('md/readme/CONTACTS.md'), $this->getReadmeTemplateContent('CONTACTS.md')), - $this->callFileGetContent($this->generateResourcePath('md/readme/CREDENTIALS_AND_ACCESS.md'), $this->getReadmeTemplateContent('CREDENTIALS_AND_ACCESS.md')), $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('users_default_admin_default_credentials.php')), $this->callFilePutContent('database/migrations/2018_11_11_111111_add_telescope_admin.php', $this->getFixture('telescope_users_default_credentials.php')), $this->callFilePutContent('database/migrations/2018_11_11_111111_add_nova_admin.php', $this->getFixture('nova_users_default_credentials.php')), - $this->callFilePutContent('README.md', $this->getFixture('none_auth_default_admins_credentials_readme.md')), $this->callFilePutContent(base_path('composer.json'), $this->getFixture('composer_with_pint_settings.json')), $this->callFilePutContent(base_path('/routes/web.php'), "\nAuth::routes();\n", FILE_APPEND), @@ -964,6 +950,16 @@ public function testDefaultAdminsCredentialsNoneAuth() $this->callShellExec('php artisan migrate --ansi'), ); + $this->mockNativeFunction( + 'RonasIT\ProjectInitializator\Generators', + $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')), + $this->callFileGetContent($this->generateResourcePath('md/readme/CONTACTS.md'), $this->getReadmeTemplateContent('CONTACTS.md')), + $this->callFileGetContent($this->generateResourcePath('md/readme/CREDENTIALS_AND_ACCESS.md'), $this->getReadmeTemplateContent('CREDENTIALS_AND_ACCESS.md')), + $this->callFilePutContent('README.md', $this->getFixture('none_auth_default_admins_credentials_readme.md')), + ); + $consoleApplication = new Application(); $consoleApplication->add(app(InitCommand::class)); @@ -981,22 +977,14 @@ public function testDefaultAdminsCredentialsNoneAuth() public function testDefaultAdminsCredentialsClerkAuth() { - $this->mockNativeFunction( - '\RonasIT\ProjectInitializator\Extensions\ConfigWriter', - $this->callFileExists(base_path('config/telescope.php')), - $this->callFileGetContent(base_path('config/telescope.php'), $this->getFixture('telescope_config.php')), - $this->callFileExists(base_path('config/auto-doc.php')), - $this->callFileGetContent(base_path('config/auto-doc.php'), $this->getFixture('auto_doc.php')), - ); - $this->mockNativeFunction( '\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.example', 'env.example.yml', 'env.example_clerk_credentials_added.yml'), - $this->callFilePutContent(base_path('config/telescope.php'), $this->getFixture('telescope_config_after_initialization.php')), - $this->callFilePutContent(base_path('config/auto-doc.php'), $this->getFixture('auto_doc_after_changes.php')), + $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'), ); $this->mockNativeFunction( @@ -1004,12 +992,6 @@ public function testDefaultAdminsCredentialsClerkAuth() $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')), - $this->callFileGetContent($this->generateResourcePath('md/readme/CONTACTS.md'), $this->getReadmeTemplateContent('CONTACTS.md')), - $this->callFileGetContent($this->generateResourcePath('md/readme/CREDENTIALS_AND_ACCESS.md'), $this->getReadmeTemplateContent('CREDENTIALS_AND_ACCESS.md')), - $this->callFileGetContent($this->generateResourcePath('md/readme/CLERK.md'), $this->getReadmeTemplateContent('CLERK.md')), $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')), @@ -1020,7 +1002,6 @@ public function testDefaultAdminsCredentialsClerkAuth() $this->callFilePutContent('database/migrations/2018_11_11_111111_add_telescope_admin.php', $this->getFixture('admins_add_telescope_admin_default_credentials.php')), $this->callGlob(base_path('database/migrations/*_admins_create_table.php'), [base_path('database/migrations/2018_11_11_111111_admins_create_table.php')]), $this->callFilePutContent('database/migrations/2018_11_11_111111_add_nova_admin.php', $this->getFixture('admins_add_nova_admin_default_credentials.php')), - $this->callFilePutContent('README.md', $this->getFixture('clerk_auth_default_admins_credentials_readme.md')), $this->callFilePutContent(base_path('composer.json'), $this->getFixture('composer_with_pint_settings.json')), $this->callFilePutContent(base_path('/routes/web.php'), "\nAuth::routes();\n", FILE_APPEND), @@ -1042,6 +1023,17 @@ public function testDefaultAdminsCredentialsClerkAuth() $this->callShellExec('php artisan migrate --ansi'), ); + $this->mockNativeFunction( + 'RonasIT\ProjectInitializator\Generators', + $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')), + $this->callFileGetContent($this->generateResourcePath('md/readme/CONTACTS.md'), $this->getReadmeTemplateContent('CONTACTS.md')), + $this->callFileGetContent($this->generateResourcePath('md/readme/CREDENTIALS_AND_ACCESS.md'), $this->getReadmeTemplateContent('CREDENTIALS_AND_ACCESS.md')), + $this->callFileGetContent($this->generateResourcePath('md/readme/CLERK.md'), $this->getReadmeTemplateContent('CLERK.md')), + $this->callFilePutContent('README.md', $this->getFixture('clerk_auth_default_admins_credentials_readme.md')), + ); + $consoleApplication = new Application(); $consoleApplication->add(app(InitCommand::class)); From 6986207cd9c9dc5cf65865013f2e0fa7aaf0bb27 Mon Sep 17 00:00:00 2001 From: Ni Nelli Date: Fri, 7 Nov 2025 15:23:44 +0900 Subject: [PATCH 4/4] test: fix tests refs: https://github.com/RonasIT/laravel-project-initializator/issues/55 --- tests/InitCommandTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/InitCommandTest.php b/tests/InitCommandTest.php index a72475c..3dff6f6 100644 --- a/tests/InitCommandTest.php +++ b/tests/InitCommandTest.php @@ -947,7 +947,7 @@ public function testDefaultAdminsCredentialsNoneAuth() $this->callShellExec('composer require ronasit/laravel-telescope-extension --ansi'), $this->callShellExec('php artisan telescope:install --ansi'), $this->callShellExec('php artisan vendor:publish --tag=initializator-web-login --force'), - $this->callShellExec('php artisan migrate --ansi'), + $this->callShellExec('php artisan migrate --ansi --force'), ); $this->mockNativeFunction( @@ -1020,7 +1020,7 @@ public function testDefaultAdminsCredentialsClerkAuth() $this->callShellExec('composer require ronasit/laravel-telescope-extension --ansi'), $this->callShellExec('php artisan telescope:install --ansi'), $this->callShellExec('php artisan vendor:publish --tag=initializator-web-login --force'), - $this->callShellExec('php artisan migrate --ansi'), + $this->callShellExec('php artisan migrate --ansi --force'), ); $this->mockNativeFunction(