From a4525002508a3b0a5fc8d03bea57fbc6d3c9be84 Mon Sep 17 00:00:00 2001 From: Vitaly Iskrin Date: Sun, 29 Oct 2023 22:19:13 -0500 Subject: [PATCH 01/11] feat: extends InitCommand --- .../CREDENTIALS_AND_ACCESS.md | 1 + .github/README_TEMPLATES/ENVIRONMENTS.md | 8 ++ .github/README_TEMPLATES/GETTING_STARTED.md | 12 +++ .github/README_TEMPLATES/PREREQUISITIES.md | 6 ++ .github/README_TEMPLATES/README.md | 3 + .../RESOURCES_AND_CONTACTS.md | 23 ++++++ app/Console/Commands/Init.php | 81 ++++++++++++++++++- tests/InitCommandTest.php | 57 +++++++++++++ 8 files changed, 188 insertions(+), 3 deletions(-) create mode 100644 .github/README_TEMPLATES/CREDENTIALS_AND_ACCESS.md create mode 100644 .github/README_TEMPLATES/ENVIRONMENTS.md create mode 100644 .github/README_TEMPLATES/GETTING_STARTED.md create mode 100644 .github/README_TEMPLATES/PREREQUISITIES.md create mode 100644 .github/README_TEMPLATES/README.md create mode 100644 .github/README_TEMPLATES/RESOURCES_AND_CONTACTS.md create mode 100644 tests/InitCommandTest.php diff --git a/.github/README_TEMPLATES/CREDENTIALS_AND_ACCESS.md b/.github/README_TEMPLATES/CREDENTIALS_AND_ACCESS.md new file mode 100644 index 0000000..b75b0be --- /dev/null +++ b/.github/README_TEMPLATES/CREDENTIALS_AND_ACCESS.md @@ -0,0 +1 @@ +## Credentials and Access diff --git a/.github/README_TEMPLATES/ENVIRONMENTS.md b/.github/README_TEMPLATES/ENVIRONMENTS.md new file mode 100644 index 0000000..da53f8a --- /dev/null +++ b/.github/README_TEMPLATES/ENVIRONMENTS.md @@ -0,0 +1,8 @@ +## Environments + +This repository by default supports three environments: `local`, `development`, +and `testing`. Each environment is represented by an appropriate environment file: + +- .env +- .env.development +- .env.testing diff --git a/.github/README_TEMPLATES/GETTING_STARTED.md b/.github/README_TEMPLATES/GETTING_STARTED.md new file mode 100644 index 0000000..b998b60 --- /dev/null +++ b/.github/README_TEMPLATES/GETTING_STARTED.md @@ -0,0 +1,12 @@ +## Getting Started + +To get started with this repository, follow these steps: + +Clone this repository to your local machine. +```sh +git clone :git_project_path +``` +Build and start containers. It may takes some time. +```sh +docker compose up -d +``` diff --git a/.github/README_TEMPLATES/PREREQUISITIES.md b/.github/README_TEMPLATES/PREREQUISITIES.md new file mode 100644 index 0000000..dd8d4f3 --- /dev/null +++ b/.github/README_TEMPLATES/PREREQUISITIES.md @@ -0,0 +1,6 @@ +## Prerequisites + +To work with this repository, you will need to have the following +installed: + +- [Docker](https://www.docker.com) diff --git a/.github/README_TEMPLATES/README.md b/.github/README_TEMPLATES/README.md new file mode 100644 index 0000000..e6c005d --- /dev/null +++ b/.github/README_TEMPLATES/README.md @@ -0,0 +1,3 @@ +# :project_name + +Project description will be here diff --git a/.github/README_TEMPLATES/RESOURCES_AND_CONTACTS.md b/.github/README_TEMPLATES/RESOURCES_AND_CONTACTS.md new file mode 100644 index 0000000..e222985 --- /dev/null +++ b/.github/README_TEMPLATES/RESOURCES_AND_CONTACTS.md @@ -0,0 +1,23 @@ +## 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: +- Issue Tracker: Here, you can report any issues or bugs related to the project. [Issue Tracker](:issue_tracker_link) +- Figma: This is where we maintain all our design assets and mock-ups. [Figma](:figma_link) +- Sentry: To monitor application performance and error tracking. [Sentry](:sentry_link) +- DataDog: This is where we monitor our logs, and server performance, and receive alerts. [DataDog](:datadog_link) +- ArgoCD +- API Documentation +- Telescope + +### 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](manager_link) +• Code Owner/Team Lead: For specific questions about the codebase or technical aspects, reach out to our team lead. [Connect with Team Lead](team_lead_link) +Please be mindful of each individual's preferred contact method and office hours. diff --git a/app/Console/Commands/Init.php b/app/Console/Commands/Init.php index d250bff..3a7db62 100755 --- a/app/Console/Commands/Init.php +++ b/app/Console/Commands/Init.php @@ -7,9 +7,6 @@ use Illuminate\Support\Carbon; use Illuminate\Support\Str; -/** - * @codeCoverageIgnore - */ class Init extends Command { protected $signature = 'init {application-name : The application name }'; @@ -44,6 +41,30 @@ public function handle(): void if ($this->confirm('Do you want generate admin user?', true)) { $this->createAdminUser($kebabName); } + + if ($this->confirm('Do you want to generate a README file?', true)) { + $this->fillReadme(); + + if ($this->confirm('Do you need `Resources & Contacts` part?', true)) { + $this->fillResourcesAndContacts(); + } + + if ($this->confirm('Do you need `Prerequisites` part?', true)) { + $this->fillPrerequisites(); + } + + if ($this->confirm('Do you need `Getting Started` part?', true)) { + $this->fillGettingStarted(); + } + + if ($this->confirm('Do you need `Environments` part?', true)) { + $this->fillEnvironments(); + } + + if ($this->confirm('Do you need `Credentials and Access` part?', true)) { + $this->fillCredentialsAndAccess(); + } + } } protected function createAdminUser($kebabName): void @@ -58,6 +79,53 @@ protected function createAdminUser($kebabName): void ]); } + protected function fillReadme(): void + { + $appName = $this->argument('application-name'); + $file = file_get_contents('.github/README_TEMPLATES/README.md'); + + $file = str_replace($file, ':project_name', $appName); + + file_put_contents('README.md', $file); + } + + protected function fillResourcesAndContacts(): void + { + $filePart = file_get_contents('.github/README_TEMPLATES/RESOURCES_AND_CONTACTS.md'); + + $this->updateReadmeFile($filePart); + } + + protected function fillPrerequisites(): void + { + $filePart = file_get_contents('.github/README_TEMPLATES/PREREQUISITES.md'); + + $this->updateReadmeFile($filePart); + } + + protected function fillGettingStarted(): void + { + $gitProjectPath = trim((string) shell_exec('git ls-remote --get-url origin')); + $filePart = file_get_contents('.github/README_TEMPLATES/GETTING_STARTED.md'); + $filePart = str_replace($filePart, ':git_project_path', $gitProjectPath); + + $this->updateReadmeFile($filePart); + } + + protected function fillEnvironments(): void + { + $filePart = file_get_contents('.github/README_TEMPLATES/ENVIRONMENTS.md'); + + $this->updateReadmeFile($filePart); + } + + protected function fillCredentialsAndAccess(): void + { + $filePart = file_get_contents('.github/README_TEMPLATES/CREDENTIALS_AND_ACCESS.md'); + + $this->updateReadmeFile($filePart); + } + protected function addQuotes($string): string { return (Str::contains($string, ' ')) ? "\"{$string}\"" : $string; @@ -92,4 +160,11 @@ protected function updateConfigFile($fileName, $separator, $data): void file_put_contents($fileName, $ymlSettings); } + + protected function updateReadmeFile(string $filePart): void + { + $file = file_get_contents('README.md'); + + file_put_contents('README.md', $file . $filePart); + } } diff --git a/tests/InitCommandTest.php b/tests/InitCommandTest.php new file mode 100644 index 0000000..f237fe2 --- /dev/null +++ b/tests/InitCommandTest.php @@ -0,0 +1,57 @@ +getFunctionMock('App\Console\Commands', 'file_put_contents'); + + $filePutContentsMock + ->expects($this->exactly(4)) + ->withConsecutive( + ['.env.testing', $this->getFixture('env.testing.yml')], + ['.env', $this->getFixture('env.yml')], + ['.env.development', $this->getFixture('env.development.yml')], + ['.env.ci-testing', $this->getFixture('env.ci-testing.yml')] + ); + + $this->artisan('init my-app') + ->expectsOutput('Project initialized successfully') + ->expectsConfirmation('Do you want generate admin user?', 'no') + ->assertExitCode(0); + } + + public function testRunWithAdminCreation() + { + $filePutContentsMock = $this->getFunctionMock('App\Console\Commands', 'file_put_contents'); + + $filePutContentsMock + ->expects($this->exactly(5)) + ->withConsecutive( + ['.env.testing', $this->getFixture('env.testing.yml')], + ['.env', $this->getFixture('env.yml')], + ['.env.development', $this->getFixture('env.development.yml')], + ['.env.ci-testing', $this->getFixture('env.ci-testing.yml')], + ['database/migrations/2018_11_11_111111_add_default_user.php', $this->getFixture('migration.php')] + ); + + $this->artisan('init my-app') + ->expectsOutput('Project initialized successfully') + ->expectsConfirmation('Do you want generate admin user?', 'yes') + ->expectsQuestion('Please enter admin name', 'TestAdmin') + ->expectsQuestion('Please enter admin email', 'mail@mail.com') + ->expectsQuestion('Please enter admin password', '123456') + ->assertExitCode(0); + } +} \ No newline at end of file From 28ab74f39cf91f3b076f652c9157b5387ab0d2f7 Mon Sep 17 00:00:00 2001 From: Vitaly Iskrin Date: Wed, 1 Nov 2023 23:54:20 -0500 Subject: [PATCH 02/11] feat: extends InitCommand --- .github/README_TEMPLATES/CONTACTS.md | 6 ++ .../CREDENTIALS_AND_ACCESS.md | 1 + .../RESOURCES_AND_CONTACTS.md | 21 ++---- app/Console/Commands/Init.php | 68 +++++++++++++++++-- .../InitCommandTest/env.ci-testing.yml | 42 ++++++++++++ .../InitCommandTest/env.development.yml | 39 +++++++++++ .../fixtures/InitCommandTest/env.testing.yml | 44 ++++++++++++ tests/fixtures/InitCommandTest/env.yml | 43 ++++++++++++ tests/fixtures/InitCommandTest/migration.php | 30 ++++++++ 9 files changed, 275 insertions(+), 19 deletions(-) create mode 100644 .github/README_TEMPLATES/CONTACTS.md create mode 100644 tests/fixtures/InitCommandTest/env.ci-testing.yml create mode 100644 tests/fixtures/InitCommandTest/env.development.yml create mode 100644 tests/fixtures/InitCommandTest/env.testing.yml create mode 100644 tests/fixtures/InitCommandTest/env.yml create mode 100644 tests/fixtures/InitCommandTest/migration.php diff --git a/.github/README_TEMPLATES/CONTACTS.md b/.github/README_TEMPLATES/CONTACTS.md new file mode 100644 index 0000000..a16f2c7 --- /dev/null +++ b/.github/README_TEMPLATES/CONTACTS.md @@ -0,0 +1,6 @@ +### 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](:manager_link) +- Code Owner/Team Lead: For specific questions about the codebase or technical aspects, reach out to our team lead. [Connect with Team Lead](:team_lead_link) +Please be mindful of each individual's preferred contact method and office hours. diff --git a/.github/README_TEMPLATES/CREDENTIALS_AND_ACCESS.md b/.github/README_TEMPLATES/CREDENTIALS_AND_ACCESS.md index b75b0be..47011b3 100644 --- a/.github/README_TEMPLATES/CREDENTIALS_AND_ACCESS.md +++ b/.github/README_TEMPLATES/CREDENTIALS_AND_ACCESS.md @@ -1 +1,2 @@ ## Credentials and Access + diff --git a/.github/README_TEMPLATES/RESOURCES_AND_CONTACTS.md b/.github/README_TEMPLATES/RESOURCES_AND_CONTACTS.md index e222985..07d57cd 100644 --- a/.github/README_TEMPLATES/RESOURCES_AND_CONTACTS.md +++ b/.github/README_TEMPLATES/RESOURCES_AND_CONTACTS.md @@ -7,17 +7,10 @@ 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: -- Issue Tracker: Here, you can report any issues or bugs related to the project. [Issue Tracker](:issue_tracker_link) -- Figma: This is where we maintain all our design assets and mock-ups. [Figma](:figma_link) -- Sentry: To monitor application performance and error tracking. [Sentry](:sentry_link) -- DataDog: This is where we monitor our logs, and server performance, and receive alerts. [DataDog](:datadog_link) -- ArgoCD -- API Documentation -- Telescope - -### 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](manager_link) -• Code Owner/Team Lead: For specific questions about the codebase or technical aspects, reach out to our team lead. [Connect with Team Lead](team_lead_link) -Please be mindful of each individual's preferred contact method and office hours. +{issue_tracker}- Issue Tracker: Here, you can report any issues or bugs related to the project. [Issue Tracker](:issue_tracker_link){/issue_tracker} +{figma}- Figma: This is where we maintain all our design assets and mock-ups. [Figma](:figma_link){/figma} +{sentry}- Sentry: To monitor application performance and error tracking. [Sentry](:sentry_link){/sentry} +{datadog}- DataDog: This is where we monitor our logs, and server performance, and receive alerts. [DataDog](:datadog_link){/datadog} +{argocd}- ArgoCD: Is a kubernetes controller which continuously monitors running applications. [ArgoCD](:argocd_link){/argocd} +{telescope}- Laravel Telescope: This is debug assistant for the Laravel framework. [Laravel Telescope](:telescope_link){/telescope} +- [API Documentation](:api_link) diff --git a/app/Console/Commands/Init.php b/app/Console/Commands/Init.php index 3a7db62..0b7371f 100755 --- a/app/Console/Commands/Init.php +++ b/app/Console/Commands/Init.php @@ -18,6 +18,8 @@ public function handle(): void $appName = $this->argument('application-name'); $kebabName = Str::kebab($appName); + $appUrl = $this->ask('Please enter an application URL', 'http://localhost'); + $this->updateConfigFile('.env.testing', '=', [ 'DATA_COLLECTOR_KEY' => "{$kebabName}-local" ]); @@ -29,7 +31,8 @@ public function handle(): void $this->updateConfigFile('.env.development', '=', [ 'APP_NAME' => $appName, - 'DATA_COLLECTOR_KEY' => "{$kebabName}" + 'DATA_COLLECTOR_KEY' => "{$kebabName}", + 'APP_URL' => "{$appUrl}", ]); $this->updateConfigFile('.env.ci-testing', '=', [ @@ -46,7 +49,8 @@ public function handle(): void $this->fillReadme(); if ($this->confirm('Do you need `Resources & Contacts` part?', true)) { - $this->fillResourcesAndContacts(); + $this->fillResources($appUrl); + $this->fillContacts(); } if ($this->confirm('Do you need `Prerequisites` part?', true)) { @@ -83,15 +87,59 @@ protected function fillReadme(): void { $appName = $this->argument('application-name'); $file = file_get_contents('.github/README_TEMPLATES/README.md'); - $file = str_replace($file, ':project_name', $appName); file_put_contents('README.md', $file); } - protected function fillResourcesAndContacts(): void + protected function fillResources(string $appUrl): void + { + $resources = [ + 'issue_tracker' => 'Issue Tracker', + 'figma' => 'Figma', + 'sentry' => 'Sentry', + 'datadog' => 'DataDog', + 'argocd' => 'ArgoCD', + 'telescope' => 'Laravel Telescope', + ]; + + $filePart = file_get_contents('.github/README_TEMPLATES/RESOURCES.md'); + + foreach ($resources as $key => $title) { + if ($this->confirm("Are you going to use {$title}?", true)) { + $defaultLink = ($key === 'telescope') ? $appUrl . '/telescope' : ''; + + if ($link = $this->ask("Please enter a {$title} link", $defaultLink)) { + $filePart = str_replace($filePart, ":{$key}_link", $link); + } + + $this->removeTag($filePart, $key); + } else { + $this->removeStringByTag($filePart, $key); + } + } + + $filePart = str_replace($filePart, ":api_link", $appUrl); + + $this->updateReadmeFile($filePart); + } + + protected function fillContacts(): void { - $filePart = file_get_contents('.github/README_TEMPLATES/RESOURCES_AND_CONTACTS.md'); + $contacts = [ + 'manager' => 'Manager', + 'team_lead' => 'Code Owner/Team Lead', + ]; + + $filePart = file_get_contents('.github/README_TEMPLATES/CONTACTS.md'); + + foreach ($contacts as $key => $title) { + if ($link = $this->ask("Please enter a {$title} contact", '')) { + $filePart = str_replace($filePart, ":{$key}_link", $link); + } + + $this->removeTag($filePart, $key); + } $this->updateReadmeFile($filePart); } @@ -167,4 +215,14 @@ protected function updateReadmeFile(string $filePart): void file_put_contents('README.md', $file . $filePart); } + + protected function removeStringByTag(string &$text, string $tag): void + { + $text = preg_replace("#({{$tag}.*?}).*?({/{$tag}})#", '', $text); + } + + protected function removeTag(string &$text, string $tag): void + { + $text = preg_replace("#{(/*){$tag}}#", '', $text); + } } diff --git a/tests/fixtures/InitCommandTest/env.ci-testing.yml b/tests/fixtures/InitCommandTest/env.ci-testing.yml new file mode 100644 index 0000000..900d9dd --- /dev/null +++ b/tests/fixtures/InitCommandTest/env.ci-testing.yml @@ -0,0 +1,42 @@ +APP_NAME=Laravel +APP_ENV=testing +APP_KEY=base64:RMlWJrRHIuHLYRplJvWaLNwWvRoVkQdDTZe6U1Z4xRY= +APP_DEBUG=true +APP_LOG_LEVEL=debug +APP_URL=http://localhost + +DB_CONNECTION=pgsql +DB_HOST=pgsql_test +DB_PORT=5432 +DB_DATABASE=forge +DB_USERNAME=forge +DB_PASSWORD="" + +BROADCAST_DRIVER=log +CACHE_DRIVER=file +SESSION_DRIVER=file +QUEUE_CONNECTION=sync + +REDIS_HOST=redis +REDIS_PASSWORD=null +REDIS_PORT=6379 + +MAIL_DRIVER=smtp +MAIL_HOST=smtp.mailtrap.io +MAIL_PORT=2525 +MAIL_USERNAME=null +MAIL_PASSWORD=null +MAIL_ENCRYPTION=null + +FILESYSTEM_DISK=local + +PUSHER_APP_ID= +PUSHER_APP_KEY= +PUSHER_APP_SECRET= + +FRONTEND_URL=http://localhost + +JWT_SECRET=av30tMhdKMXfF3OT1OPljEJ7e9KRG7Y4ruqfOPYWx1jRtqpgKwIohtp2n30uZtfs + +NOVA_GUARD=nova +NOVA_PASSWORDS=nova \ No newline at end of file diff --git a/tests/fixtures/InitCommandTest/env.development.yml b/tests/fixtures/InitCommandTest/env.development.yml new file mode 100644 index 0000000..0c24285 --- /dev/null +++ b/tests/fixtures/InitCommandTest/env.development.yml @@ -0,0 +1,39 @@ +APP_NAME=my-app +APP_ENV=development +APP_KEY= +APP_DEBUG=true +APP_LOG_LEVEL=debug +APP_URL=http://localhost + +DB_CONNECTION=pgsql +DB_HOST= +DB_PORT= +DB_DATABASE= +DB_USERNAME= +DB_PASSWORD= + +BROADCAST_DRIVER=log +CACHE_DRIVER=file +SESSION_DRIVER=redis +QUEUE_CONNECTION=redis + +REDIS_HOST=redis +REDIS_PASSWORD= +REDIS_PORT= + +MAIL_DRIVER=smtp +MAIL_HOST= +MAIL_PORT= +MAIL_USERNAME= +MAIL_PASSWORD= +MAIL_ENCRYPTION= + +FILESYSTEM_DISK=gcs + +PUSHER_APP_ID= +PUSHER_APP_KEY= +PUSHER_APP_SECRET= + +FRONTEND_URL= + +JWT_SHOW_BLACKLIST_EXCEPTION=true \ No newline at end of file diff --git a/tests/fixtures/InitCommandTest/env.testing.yml b/tests/fixtures/InitCommandTest/env.testing.yml new file mode 100644 index 0000000..7c2a234 --- /dev/null +++ b/tests/fixtures/InitCommandTest/env.testing.yml @@ -0,0 +1,44 @@ +APP_NAME=Laravel +APP_ENV=testing +APP_KEY=base64:RMlWJrRHIuHLYRplJvWaLNwWvRoVkQdDTZe6U1Z4xRY= +APP_DEBUG=true +APP_LOG_LEVEL=debug +APP_URL=http://localhost +FAIL_EXPORT_JSON=false + +DB_CONNECTION=pgsql +DB_HOST=pgsql_test +DB_PORT=5432 +DB_DATABASE=forge +DB_USERNAME=forge +DB_PASSWORD="" + +BROADCAST_DRIVER=log +CACHE_DRIVER=file +SESSION_DRIVER=file +QUEUE_CONNECTION=sync + +REDIS_HOST=redis +REDIS_PASSWORD=null +REDIS_PORT=6379 + +MAIL_DRIVER=log +MAIL_HOST=smtp.mailtrap.io +MAIL_PORT=2525 +MAIL_USERNAME=null +MAIL_PASSWORD=null +MAIL_ENCRYPTION=null + +FILESYSTEM_DISK=local +GOOGLE_CLOUD_STORAGE_BUCKET=ronasit-development +GOOGLE_CLOUD_PROJECT_ID=ronas-it-development +GOOGLE_CLOUD_KEY_FILE=gcs.key + +PUSHER_APP_ID= +PUSHER_APP_KEY= +PUSHER_APP_SECRET= + +FRONTEND_URL=http://localhost + +JWT_SECRET=av30tMhdKMXfF3OT1OPljEJ7e9KRG7Y4ruqfOPYWx1jRtqpgKwIohtp2n30uZtfs +JWT_SHOW_BLACKLIST_EXCEPTION=true \ No newline at end of file diff --git a/tests/fixtures/InitCommandTest/env.yml b/tests/fixtures/InitCommandTest/env.yml new file mode 100644 index 0000000..39d1e1d --- /dev/null +++ b/tests/fixtures/InitCommandTest/env.yml @@ -0,0 +1,43 @@ +APP_NAME=my-app +APP_ENV=local +APP_KEY=base64:RMlWJrRHIuHLYRplJvWaLNwWvRoVkQdDTZe6U1Z4xRY= +APP_DEBUG=true +APP_LOG_LEVEL=debug +APP_URL=http://localhost + +DB_CONNECTION=pgsql +DB_HOST=pgsql +DB_PORT=5432 +DB_DATABASE=pgdb +DB_USERNAME=pguser +DB_PASSWORD="" + +BROADCAST_DRIVER=log +CACHE_DRIVER=redis +SESSION_DRIVER=redis +QUEUE_CONNECTION=sync + +REDIS_HOST=redis +REDIS_PASSWORD=null +REDIS_PORT=6379 + +MAIL_DRIVER=smtp +MAIL_HOST=smtp.mailtrap.io +MAIL_PORT=2525 +MAIL_USERNAME=null +MAIL_PASSWORD=null +MAIL_ENCRYPTION=null + +FILESYSTEM_DISK=local +GOOGLE_CLOUD_STORAGE_BUCKET=ronasit-development +GOOGLE_CLOUD_PROJECT_ID=ronas-it-development +GOOGLE_CLOUD_KEY_FILE=gcs.key + +PUSHER_APP_ID= +PUSHER_APP_KEY= +PUSHER_APP_SECRET= + +FRONTEND_URL=http://localhost + +JWT_SECRET=av30tMhdKMXfF3OT1OPljEJ7e9KRG7Y4ruqfOPYWx1jRtqpgKwIohtp2n30uZtfs +JWT_SHOW_BLACKLIST_EXCEPTION=true \ No newline at end of file diff --git a/tests/fixtures/InitCommandTest/migration.php b/tests/fixtures/InitCommandTest/migration.php new file mode 100644 index 0000000..2f9e433 --- /dev/null +++ b/tests/fixtures/InitCommandTest/migration.php @@ -0,0 +1,30 @@ + 'TestAdmin', + 'email' => 'mail@mail.com', + 'password' => Hash::make('123456'), + 'role_id' => '1' + ]); + } + } + + public function down() + { + if (config('app.env') !== 'testing') { + User::where('email', 'mail@mail.com')->delete(); + } + } +} \ No newline at end of file From 5db887f3205dd5deeb667513346581b339e9a882 Mon Sep 17 00:00:00 2001 From: Vitaly Iskrin Date: Fri, 3 Nov 2023 14:33:03 -0500 Subject: [PATCH 03/11] feat: extends InitCommand --- .../CREDENTIALS_AND_ACCESS.md | 2 - .github/README_TEMPLATES/ENVIRONMENTS.md | 8 --- .../CONTACTS.md | 0 .templates/CREDENTIALS_AND_ACCESS.md | 3 + .templates/ENVIRONMENTS.md | 10 +++ .../GETTING_STARTED.md | 0 .../PREREQUISITIES.md | 0 .../README_TEMPLATES => .templates}/README.md | 0 .../RESOURCES.md | 0 app/Console/Commands/Init.php | 71 +++++++++++++------ 10 files changed, 62 insertions(+), 32 deletions(-) delete mode 100644 .github/README_TEMPLATES/CREDENTIALS_AND_ACCESS.md delete mode 100644 .github/README_TEMPLATES/ENVIRONMENTS.md rename {.github/README_TEMPLATES => .templates}/CONTACTS.md (100%) create mode 100644 .templates/CREDENTIALS_AND_ACCESS.md create mode 100644 .templates/ENVIRONMENTS.md rename {.github/README_TEMPLATES => .templates}/GETTING_STARTED.md (100%) rename {.github/README_TEMPLATES => .templates}/PREREQUISITIES.md (100%) rename {.github/README_TEMPLATES => .templates}/README.md (100%) rename .github/README_TEMPLATES/RESOURCES_AND_CONTACTS.md => .templates/RESOURCES.md (100%) diff --git a/.github/README_TEMPLATES/CREDENTIALS_AND_ACCESS.md b/.github/README_TEMPLATES/CREDENTIALS_AND_ACCESS.md deleted file mode 100644 index 47011b3..0000000 --- a/.github/README_TEMPLATES/CREDENTIALS_AND_ACCESS.md +++ /dev/null @@ -1,2 +0,0 @@ -## Credentials and Access - diff --git a/.github/README_TEMPLATES/ENVIRONMENTS.md b/.github/README_TEMPLATES/ENVIRONMENTS.md deleted file mode 100644 index da53f8a..0000000 --- a/.github/README_TEMPLATES/ENVIRONMENTS.md +++ /dev/null @@ -1,8 +0,0 @@ -## Environments - -This repository by default supports three environments: `local`, `development`, -and `testing`. Each environment is represented by an appropriate environment file: - -- .env -- .env.development -- .env.testing diff --git a/.github/README_TEMPLATES/CONTACTS.md b/.templates/CONTACTS.md similarity index 100% rename from .github/README_TEMPLATES/CONTACTS.md rename to .templates/CONTACTS.md diff --git a/.templates/CREDENTIALS_AND_ACCESS.md b/.templates/CREDENTIALS_AND_ACCESS.md new file mode 100644 index 0000000..0ea74f7 --- /dev/null +++ b/.templates/CREDENTIALS_AND_ACCESS.md @@ -0,0 +1,3 @@ +## Credentials and Access + +{admin_credentials}Default admin email and password: `{:admin_email}`/`{:admin_password}`{/admin_credentials} \ No newline at end of file diff --git a/.templates/ENVIRONMENTS.md b/.templates/ENVIRONMENTS.md new file mode 100644 index 0000000..bc2868d --- /dev/null +++ b/.templates/ENVIRONMENTS.md @@ -0,0 +1,10 @@ +## Environments + +This repository by default supports three environments: `local`, `development`, +and `testing`. Each environment is represented by an appropriate environment file: + +| Environment | File | URL | +| --- | --- |--------------------------------------| +| local | .env | [http://localhost](http://localhost) | +| testing | .env.testing | - | +| development | .env.development | [:api_link](:api_link) | diff --git a/.github/README_TEMPLATES/GETTING_STARTED.md b/.templates/GETTING_STARTED.md similarity index 100% rename from .github/README_TEMPLATES/GETTING_STARTED.md rename to .templates/GETTING_STARTED.md diff --git a/.github/README_TEMPLATES/PREREQUISITIES.md b/.templates/PREREQUISITIES.md similarity index 100% rename from .github/README_TEMPLATES/PREREQUISITIES.md rename to .templates/PREREQUISITIES.md diff --git a/.github/README_TEMPLATES/README.md b/.templates/README.md similarity index 100% rename from .github/README_TEMPLATES/README.md rename to .templates/README.md diff --git a/.github/README_TEMPLATES/RESOURCES_AND_CONTACTS.md b/.templates/RESOURCES.md similarity index 100% rename from .github/README_TEMPLATES/RESOURCES_AND_CONTACTS.md rename to .templates/RESOURCES.md diff --git a/app/Console/Commands/Init.php b/app/Console/Commands/Init.php index 0b7371f..84d7787 100755 --- a/app/Console/Commands/Init.php +++ b/app/Console/Commands/Init.php @@ -9,16 +9,22 @@ class Init extends Command { + const TEMPLATES_PATH = '.templates'; + protected $signature = 'init {application-name : The application name }'; protected $description = 'Initialize required project parameters to run DEV environment'; + protected array $adminCredentials = []; + + protected string $appUrl; + public function handle(): void { $appName = $this->argument('application-name'); $kebabName = Str::kebab($appName); - $appUrl = $this->ask('Please enter an application URL', 'http://localhost'); + $this->appUrl = $this->ask('Please enter an application URL', 'http://localhost'); $this->updateConfigFile('.env.testing', '=', [ 'DATA_COLLECTOR_KEY' => "{$kebabName}-local" @@ -32,7 +38,7 @@ public function handle(): void $this->updateConfigFile('.env.development', '=', [ 'APP_NAME' => $appName, 'DATA_COLLECTOR_KEY' => "{$kebabName}", - 'APP_URL' => "{$appUrl}", + 'APP_URL' => "{$this->appUrl}", ]); $this->updateConfigFile('.env.ci-testing', '=', [ @@ -49,7 +55,7 @@ public function handle(): void $this->fillReadme(); if ($this->confirm('Do you need `Resources & Contacts` part?', true)) { - $this->fillResources($appUrl); + $this->fillResources(); $this->fillContacts(); } @@ -75,24 +81,27 @@ protected function createAdminUser($kebabName): void { $defaultPassword = substr(md5(uniqid()), 0, 8); - $this->publishMigration([ + $this->adminCredentials = [ 'name' => $this->ask('Please enter admin name', 'Admin'), 'email' => $this->ask('Please enter admin email', "admin@{$kebabName}.com"), 'password' => $this->ask('Please enter admin password', $defaultPassword), 'role_id' => Role::ADMIN - ]); + ]; + + $this->publishMigration(); } protected function fillReadme(): void { $appName = $this->argument('application-name'); - $file = file_get_contents('.github/README_TEMPLATES/README.md'); - $file = str_replace($file, ':project_name', $appName); + $file = $this->loadReadmePart('README.md'); + + $this->setReadmeValue($file, 'project_name', $appName); file_put_contents('README.md', $file); } - protected function fillResources(string $appUrl): void + protected function fillResources(): void { $resources = [ 'issue_tracker' => 'Issue Tracker', @@ -103,14 +112,14 @@ protected function fillResources(string $appUrl): void 'telescope' => 'Laravel Telescope', ]; - $filePart = file_get_contents('.github/README_TEMPLATES/RESOURCES.md'); + $filePart = $this->loadReadmePart('RESOURCES.md'); foreach ($resources as $key => $title) { if ($this->confirm("Are you going to use {$title}?", true)) { - $defaultLink = ($key === 'telescope') ? $appUrl . '/telescope' : ''; + $defaultLink = ($key === 'telescope') ? $this->appUrl . '/telescope' : ''; if ($link = $this->ask("Please enter a {$title} link", $defaultLink)) { - $filePart = str_replace($filePart, ":{$key}_link", $link); + $this->setReadmeValue($filePart, "{$key}_link", $link); } $this->removeTag($filePart, $key); @@ -119,8 +128,7 @@ protected function fillResources(string $appUrl): void } } - $filePart = str_replace($filePart, ":api_link", $appUrl); - + $this->setReadmeValue($filePart, 'api_link', $this->appUrl); $this->updateReadmeFile($filePart); } @@ -131,11 +139,11 @@ protected function fillContacts(): void 'team_lead' => 'Code Owner/Team Lead', ]; - $filePart = file_get_contents('.github/README_TEMPLATES/CONTACTS.md'); + $filePart = $this->loadReadmePart('CONTACTS.md'); foreach ($contacts as $key => $title) { if ($link = $this->ask("Please enter a {$title} contact", '')) { - $filePart = str_replace($filePart, ":{$key}_link", $link); + $this->setReadmeValue($filePart, "{$key}_link", $link); } $this->removeTag($filePart, $key); @@ -146,7 +154,7 @@ protected function fillContacts(): void protected function fillPrerequisites(): void { - $filePart = file_get_contents('.github/README_TEMPLATES/PREREQUISITES.md'); + $filePart = $this->loadReadmePart('PREREQUISITES.md'); $this->updateReadmeFile($filePart); } @@ -154,22 +162,31 @@ protected function fillPrerequisites(): void protected function fillGettingStarted(): void { $gitProjectPath = trim((string) shell_exec('git ls-remote --get-url origin')); - $filePart = file_get_contents('.github/README_TEMPLATES/GETTING_STARTED.md'); - $filePart = str_replace($filePart, ':git_project_path', $gitProjectPath); + $filePart = $this->loadReadmePart('GETTING_STARTED.md'); + $this->setReadmeValue($filePart, 'git_project_path', $gitProjectPath); $this->updateReadmeFile($filePart); } protected function fillEnvironments(): void { - $filePart = file_get_contents('.github/README_TEMPLATES/ENVIRONMENTS.md'); + $filePart = $this->loadReadmePart('ENVIRONMENTS.md'); + $this->setReadmeValue($filePart, 'api_link', $this->appUrl); $this->updateReadmeFile($filePart); } protected function fillCredentialsAndAccess(): void { - $filePart = file_get_contents('.github/README_TEMPLATES/CREDENTIALS_AND_ACCESS.md'); + $filePart = $this->loadReadmePart('CREDENTIALS_AND_ACCESS.md'); + + if ($this->adminCredentials) { + $this->setReadmeValue($filePart, 'admin_email', $this->adminCredentials['email']); + $this->setReadmeValue($filePart, 'admin_password', $this->adminCredentials['password']); + $this->removeTag($filePart, 'admin_credentials'); + } else { + $this->removeStringByTag($filePart, 'admin_credentials'); + } $this->updateReadmeFile($filePart); } @@ -179,9 +196,9 @@ protected function addQuotes($string): string return (Str::contains($string, ' ')) ? "\"{$string}\"" : $string; } - protected function publishMigration($admin): void + protected function publishMigration(): void { - $data = view('add_default_user')->with($admin)->render(); + $data = view('add_default_user')->with($this->adminCredentials)->render(); $fileName = Carbon::now()->format('Y_m_d_His') . '_add_default_user.php'; file_put_contents("database/migrations/{$fileName}", " Date: Fri, 3 Nov 2023 14:38:00 -0500 Subject: [PATCH 04/11] chore: fix typo --- .templates/{PREREQUISITIES.md => PREREQUISITES.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .templates/{PREREQUISITIES.md => PREREQUISITES.md} (100%) diff --git a/.templates/PREREQUISITIES.md b/.templates/PREREQUISITES.md similarity index 100% rename from .templates/PREREQUISITIES.md rename to .templates/PREREQUISITES.md From 6a54c43a4e1addfce067d5dbec8114a90dae7e9a Mon Sep 17 00:00:00 2001 From: Vitaly Iskrin Date: Fri, 3 Nov 2023 21:02:15 -0500 Subject: [PATCH 05/11] feat: extends InitCommand --- .templates/CREDENTIALS_AND_ACCESS.md | 2 +- .templates/RESOURCES.md | 7 +---- .templates/RESOURCES_AND_CONTACTS.md | 5 ++++ app/Console/Commands/Init.php | 44 ++++++++++++++++++++++------ 4 files changed, 42 insertions(+), 16 deletions(-) create mode 100644 .templates/RESOURCES_AND_CONTACTS.md diff --git a/.templates/CREDENTIALS_AND_ACCESS.md b/.templates/CREDENTIALS_AND_ACCESS.md index 0ea74f7..599edcc 100644 --- a/.templates/CREDENTIALS_AND_ACCESS.md +++ b/.templates/CREDENTIALS_AND_ACCESS.md @@ -1,3 +1,3 @@ ## Credentials and Access -{admin_credentials}Default admin email and password: `{:admin_email}`/`{:admin_password}`{/admin_credentials} \ No newline at end of file +{admin_credentials}Default admin email and password: `:admin_email`/`:admin_password`{/admin_credentials} \ No newline at end of file diff --git a/.templates/RESOURCES.md b/.templates/RESOURCES.md index 07d57cd..31036b6 100644 --- a/.templates/RESOURCES.md +++ b/.templates/RESOURCES.md @@ -1,9 +1,3 @@ -## 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: @@ -14,3 +8,4 @@ Below are links to tools and services used in this project: {argocd}- ArgoCD: Is a kubernetes controller which continuously monitors running applications. [ArgoCD](:argocd_link){/argocd} {telescope}- Laravel Telescope: This is debug assistant for the Laravel framework. [Laravel Telescope](:telescope_link){/telescope} - [API Documentation](:api_link) + diff --git a/.templates/RESOURCES_AND_CONTACTS.md b/.templates/RESOURCES_AND_CONTACTS.md new file mode 100644 index 0000000..8e2f971 --- /dev/null +++ b/.templates/RESOURCES_AND_CONTACTS.md @@ -0,0 +1,5 @@ +## 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. diff --git a/app/Console/Commands/Init.php b/app/Console/Commands/Init.php index 84d7787..c7c518e 100755 --- a/app/Console/Commands/Init.php +++ b/app/Console/Commands/Init.php @@ -19,6 +19,8 @@ class Init extends Command protected string $appUrl; + protected array $emptyValuesList = []; + public function handle(): void { $appName = $this->argument('application-name'); @@ -45,35 +47,46 @@ public function handle(): void 'DATA_COLLECTOR_KEY' => "{$kebabName}" ]); - $this->info('Project initialized successfully'); + $this->info('Project initialized successfully!'); - if ($this->confirm('Do you want generate admin user?', true)) { + if ($this->confirm('Do you want to generate admin user?', true)) { $this->createAdminUser($kebabName); } if ($this->confirm('Do you want to generate a README file?', true)) { $this->fillReadme(); - if ($this->confirm('Do you need `Resources & Contacts` part?', true)) { + if ($this->confirm('Do you need a `Resources & Contacts` part?', true)) { + $this->fillResourcesAndContacts(); $this->fillResources(); $this->fillContacts(); } - if ($this->confirm('Do you need `Prerequisites` part?', true)) { + if ($this->confirm('Do you need a `Prerequisites` part?', true)) { $this->fillPrerequisites(); } - if ($this->confirm('Do you need `Getting Started` part?', true)) { + if ($this->confirm('Do you need a `Getting Started` part?', true)) { $this->fillGettingStarted(); } - if ($this->confirm('Do you need `Environments` part?', true)) { + if ($this->confirm('Do you need an `Environments` part?', true)) { $this->fillEnvironments(); } - if ($this->confirm('Do you need `Credentials and Access` part?', true)) { + if ($this->confirm('Do you need a `Credentials and Access` part?', true)) { $this->fillCredentialsAndAccess(); } + + $this->info('README generated successfully!'); + + if ($this->emptyValuesList) { + $this->warn('Don`t forget to fill the following empty values:'); + + foreach ($this->emptyValuesList as $value) { + $this->warn("- {$value}"); + } + } } } @@ -101,6 +114,13 @@ protected function fillReadme(): void file_put_contents('README.md', $file); } + protected function fillResourcesAndContacts(): void + { + $filePart = $this->loadReadmePart('RESOURCES_AND_CONTACTS.md'); + + $this->updateReadmeFile($filePart); + } + protected function fillResources(): void { $resources = [ @@ -120,6 +140,8 @@ protected function fillResources(): void if ($link = $this->ask("Please enter a {$title} link", $defaultLink)) { $this->setReadmeValue($filePart, "{$key}_link", $link); + } else { + $this->emptyValuesList[] = "{$title} link"; } $this->removeTag($filePart, $key); @@ -144,6 +166,8 @@ protected function fillContacts(): void foreach ($contacts as $key => $title) { if ($link = $this->ask("Please enter a {$title} contact", '')) { $this->setReadmeValue($filePart, "{$key}_link", $link); + } else { + $this->emptyValuesList[] = "{$title} contact"; } $this->removeTag($filePart, $key); @@ -235,7 +259,9 @@ protected function updateReadmeFile(string $filePart): void { $file = file_get_contents('README.md'); - file_put_contents('README.md', $file . $filePart); + $filePart = preg_replace('#(\n){2,}#', "\n", $filePart); + + file_put_contents('README.md', $file . "\n" . $filePart); } protected function removeStringByTag(string &$text, string $tag): void @@ -250,6 +276,6 @@ protected function removeTag(string &$text, string $tag): void protected function setReadmeValue(string &$file, string $key, string $value): void { - $file = str_replace($file, ":{$key}", $value); + $file = str_replace(":{$key}", $value, $file); } } From 88b9c013e6ad4859c43137a7443be98f5f3611be Mon Sep 17 00:00:00 2001 From: Vitaly Iskrin Date: Fri, 3 Nov 2023 22:00:05 -0500 Subject: [PATCH 06/11] chore: fix typo --- .templates/RESOURCES.md | 1 - app/Console/Commands/Init.php | 23 +++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.templates/RESOURCES.md b/.templates/RESOURCES.md index 31036b6..230b504 100644 --- a/.templates/RESOURCES.md +++ b/.templates/RESOURCES.md @@ -8,4 +8,3 @@ Below are links to tools and services used in this project: {argocd}- ArgoCD: Is a kubernetes controller which continuously monitors running applications. [ArgoCD](:argocd_link){/argocd} {telescope}- Laravel Telescope: This is debug assistant for the Laravel framework. [Laravel Telescope](:telescope_link){/telescope} - [API Documentation](:api_link) - diff --git a/app/Console/Commands/Init.php b/app/Console/Commands/Init.php index c7c518e..135552b 100755 --- a/app/Console/Commands/Init.php +++ b/app/Console/Commands/Init.php @@ -21,6 +21,8 @@ class Init extends Command protected array $emptyValuesList = []; + protected string $readmeContent = ''; + public function handle(): void { $appName = $this->argument('application-name'); @@ -49,7 +51,7 @@ public function handle(): void $this->info('Project initialized successfully!'); - if ($this->confirm('Do you want to generate admin user?', true)) { + if ($this->confirm('Do you want to generate an admin user?', true)) { $this->createAdminUser($kebabName); } @@ -78,6 +80,8 @@ public function handle(): void $this->fillCredentialsAndAccess(); } + $this->saveReadme(); + $this->info('README generated successfully!'); if ($this->emptyValuesList) { @@ -95,9 +99,9 @@ protected function createAdminUser($kebabName): void $defaultPassword = substr(md5(uniqid()), 0, 8); $this->adminCredentials = [ - 'name' => $this->ask('Please enter admin name', 'Admin'), - 'email' => $this->ask('Please enter admin email', "admin@{$kebabName}.com"), - 'password' => $this->ask('Please enter admin password', $defaultPassword), + 'name' => $this->ask('Please enter an admin name', 'Admin'), + 'email' => $this->ask('Please enter an admin email', "admin@{$kebabName}.com"), + 'password' => $this->ask('Please enter an admin password', $defaultPassword), 'role_id' => Role::ADMIN ]; @@ -111,7 +115,7 @@ protected function fillReadme(): void $this->setReadmeValue($file, 'project_name', $appName); - file_put_contents('README.md', $file); + $this->readmeContent = $file; } protected function fillResourcesAndContacts(): void @@ -257,11 +261,9 @@ protected function loadReadmePart(string $fileName): string protected function updateReadmeFile(string $filePart): void { - $file = file_get_contents('README.md'); - $filePart = preg_replace('#(\n){2,}#', "\n", $filePart); - file_put_contents('README.md', $file . "\n" . $filePart); + $this->readmeContent .= "\n" . $filePart; } protected function removeStringByTag(string &$text, string $tag): void @@ -278,4 +280,9 @@ protected function setReadmeValue(string &$file, string $key, string $value): vo { $file = str_replace(":{$key}", $value, $file); } + + protected function saveReadme(): void + { + file_put_contents('README.md', $this->readmeContent); + } } From 141284ccde247bba0a7a036c2ae0f49e10c0ed57 Mon Sep 17 00:00:00 2001 From: Vitaly Iskrin Date: Fri, 3 Nov 2023 22:16:03 -0500 Subject: [PATCH 07/11] test: cover InitCommand --- tests/InitCommandTest.php | 130 ++++++++++++++++-- .../InitCommandTest/default_readme.md | 52 +++++++ .../InitCommandTest/env.ci-testing.yml | 2 +- .../InitCommandTest/env.development.yml | 6 +- .../fixtures/InitCommandTest/env.testing.yml | 2 +- tests/fixtures/InitCommandTest/env.yml | 4 +- tests/fixtures/InitCommandTest/full_readme.md | 52 +++++++ tests/fixtures/InitCommandTest/migration.php | 2 +- 8 files changed, 229 insertions(+), 21 deletions(-) create mode 100644 tests/fixtures/InitCommandTest/default_readme.md create mode 100644 tests/fixtures/InitCommandTest/full_readme.md diff --git a/tests/InitCommandTest.php b/tests/InitCommandTest.php index f237fe2..91f6df7 100644 --- a/tests/InitCommandTest.php +++ b/tests/InitCommandTest.php @@ -13,7 +13,7 @@ public function setUp(): void TestCase::setUp(); } - public function testRunWithoutAdminCreation() + public function testRunWithoutAdminAndReadmeCreation() { $filePutContentsMock = $this->getFunctionMock('App\Console\Commands', 'file_put_contents'); @@ -23,16 +23,18 @@ public function testRunWithoutAdminCreation() ['.env.testing', $this->getFixture('env.testing.yml')], ['.env', $this->getFixture('env.yml')], ['.env.development', $this->getFixture('env.development.yml')], - ['.env.ci-testing', $this->getFixture('env.ci-testing.yml')] + ['.env.ci-testing', $this->getFixture('env.ci-testing.yml')], ); - $this->artisan('init my-app') - ->expectsOutput('Project initialized successfully') - ->expectsConfirmation('Do you want generate admin user?', 'no') + $this->artisan('init "My App"') + ->expectsOutput('Project initialized successfully!') + ->expectsQuestion('Please enter an application URL', 'https://mysite.com') + ->expectsConfirmation('Do you want to generate an admin user?') + ->expectsConfirmation('Do you want to generate a README file?') ->assertExitCode(0); } - public function testRunWithAdminCreation() + public function testRunWithAdminAndWithoutReadmeCreation() { $filePutContentsMock = $this->getFunctionMock('App\Console\Commands', 'file_put_contents'); @@ -43,15 +45,117 @@ public function testRunWithAdminCreation() ['.env', $this->getFixture('env.yml')], ['.env.development', $this->getFixture('env.development.yml')], ['.env.ci-testing', $this->getFixture('env.ci-testing.yml')], - ['database/migrations/2018_11_11_111111_add_default_user.php', $this->getFixture('migration.php')] + ['database/migrations/2018_11_11_111111_add_default_user.php', $this->getFixture('migration.php')], + ); + + $this->artisan('init "My App"') + ->expectsOutput('Project initialized successfully!') + ->expectsQuestion('Please enter an application URL', 'https://mysite.com') + ->expectsConfirmation('Do you want to generate an admin user?', 'yes') + ->expectsQuestion('Please enter an admin name', 'TestAdmin') + ->expectsQuestion('Please enter an admin email', 'mail@mail.com') + ->expectsQuestion('Please enter an admin password', '123456') + ->expectsConfirmation('Do you want to generate a README file?') + ->assertExitCode(0); + } + + public function testRunWithAdminAndDefaultReadmeCreation() + { + $filePutContentsMock = $this->getFunctionMock('App\Console\Commands', 'file_put_contents'); + + $filePutContentsMock + ->expects($this->exactly(6)) + ->withConsecutive( + ['.env.testing', $this->getFixture('env.testing.yml')], + ['.env', $this->getFixture('env.yml')], + ['.env.development', $this->getFixture('env.development.yml')], + ['.env.ci-testing', $this->getFixture('env.ci-testing.yml')], + ['database/migrations/2018_11_11_111111_add_default_user.php', $this->getFixture('migration.php')], + ['README.md', $this->getFixture('default_readme.md')], + ); + + $this->artisan('init "My App"') + ->expectsOutput('Project initialized successfully!') + ->expectsQuestion('Please enter an application URL', 'https://mysite.com') + ->expectsConfirmation('Do you want to generate an admin user?', 'yes') + ->expectsQuestion('Please enter an admin name', 'TestAdmin') + ->expectsQuestion('Please enter an admin email', 'mail@mail.com') + ->expectsQuestion('Please enter an admin password', '123456') + ->expectsConfirmation('Do you want to generate a README file?', 'yes') + ->expectsConfirmation('Do you need a `Resources & Contacts` part?', 'yes') + ->expectsConfirmation('Are you going to use Issue Tracker?', 'yes') + ->expectsQuestion('Please enter a Issue Tracker link', '') + ->expectsConfirmation('Are you going to use Figma?', 'yes') + ->expectsQuestion('Please enter a Figma link', '') + ->expectsConfirmation('Are you going to use Sentry?', 'yes') + ->expectsQuestion('Please enter a Sentry link', '') + ->expectsConfirmation('Are you going to use DataDog?', 'yes') + ->expectsQuestion('Please enter a DataDog link', '') + ->expectsConfirmation('Are you going to use ArgoCD?', 'yes') + ->expectsQuestion('Please enter a ArgoCD link', '') + ->expectsConfirmation('Are you going to use Laravel Telescope?', 'yes') + ->expectsQuestion('Please enter a Laravel Telescope link', '') + ->expectsQuestion('Please enter a Manager contact', '') + ->expectsQuestion('Please enter a Code Owner/Team Lead contact', '') + ->expectsConfirmation('Do you need a `Prerequisites` part?', 'yes') + ->expectsConfirmation('Do you need a `Getting Started` part?', 'yes') + ->expectsConfirmation('Do you need an `Environments` part?', 'yes') + ->expectsConfirmation('Do you need a `Credentials and Access` part?', 'yes') + ->expectsOutput('README generated successfully!') + ->expectsOutput('Don`t forget to fill the following empty values:') + ->expectsOutput('- Issue Tracker link') + ->expectsOutput('- Figma link') + ->expectsOutput('- Sentry link') + ->expectsOutput('- DataDog link') + ->expectsOutput('- ArgoCD link') + ->expectsOutput('- Manager contact') + ->expectsOutput('- Code Owner/Team Lead contact') + ->assertExitCode(0); + } + + public function testRunWithAdminAndFullReadmeCreation() + { + $filePutContentsMock = $this->getFunctionMock('App\Console\Commands', 'file_put_contents'); + + $filePutContentsMock + ->expects($this->exactly(6)) + ->withConsecutive( + ['.env.testing', $this->getFixture('env.testing.yml')], + ['.env', $this->getFixture('env.yml')], + ['.env.development', $this->getFixture('env.development.yml')], + ['.env.ci-testing', $this->getFixture('env.ci-testing.yml')], + ['database/migrations/2018_11_11_111111_add_default_user.php', $this->getFixture('migration.php')], + ['README.md', $this->getFixture('full_readme.md')], ); - $this->artisan('init my-app') - ->expectsOutput('Project initialized successfully') - ->expectsConfirmation('Do you want generate admin user?', 'yes') - ->expectsQuestion('Please enter admin name', 'TestAdmin') - ->expectsQuestion('Please enter admin email', 'mail@mail.com') - ->expectsQuestion('Please enter admin password', '123456') + $this->artisan('init "My App"') + ->expectsOutput('Project initialized successfully!') + ->expectsQuestion('Please enter an application URL', 'https://mysite.com') + ->expectsConfirmation('Do you want to generate an admin user?', 'yes') + ->expectsQuestion('Please enter an admin name', 'TestAdmin') + ->expectsQuestion('Please enter an admin email', 'mail@mail.com') + ->expectsQuestion('Please enter an admin password', '123456') + ->expectsConfirmation('Do you want to generate a README file?', 'yes') + ->expectsConfirmation('Do you need a `Resources & Contacts` part?', 'yes') + ->expectsConfirmation('Are you going to use Issue Tracker?', 'yes') + ->expectsQuestion('Please enter a Issue Tracker link', 'https://gitlab.com/my-project') + ->expectsConfirmation('Are you going to use Figma?', 'yes') + ->expectsQuestion('Please enter a Figma link', 'https://figma.com/my-project') + ->expectsConfirmation('Are you going to use Sentry?', 'yes') + ->expectsQuestion('Please enter a Sentry link', 'https://sentry.com/my-project') + ->expectsConfirmation('Are you going to use DataDog?', 'yes') + ->expectsQuestion('Please enter a DataDog link', 'https://datadoghq.com/my-project') + ->expectsConfirmation('Are you going to use ArgoCD?', 'yes') + ->expectsQuestion('Please enter a ArgoCD link', 'https://argocd.com/my-project') + ->expectsConfirmation('Are you going to use Laravel Telescope?', 'yes') + ->expectsQuestion('Please enter a Laravel Telescope link', 'https://mypsite.com/telescope-link') + ->expectsQuestion('Please enter a Manager contact', 'manager@mail.com') + ->expectsQuestion('Please enter a Code Owner/Team Lead contact', 'lead@mail.com') + ->expectsConfirmation('Do you need a `Prerequisites` part?', 'yes') + ->expectsConfirmation('Do you need a `Getting Started` part?', 'yes') + ->expectsConfirmation('Do you need an `Environments` part?', 'yes') + ->expectsConfirmation('Do you need a `Credentials and Access` part?', 'yes') + ->expectsOutput('README generated successfully!') ->assertExitCode(0); } } \ No newline at end of file diff --git a/tests/fixtures/InitCommandTest/default_readme.md b/tests/fixtures/InitCommandTest/default_readme.md new file mode 100644 index 0000000..5508159 --- /dev/null +++ b/tests/fixtures/InitCommandTest/default_readme.md @@ -0,0 +1,52 @@ +# My App + +Project description will be here + +## 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: +- Issue Tracker: Here, you can report any issues or bugs related to the project. [Issue Tracker](:issue_tracker_link) +- Figma: This is where we maintain all our design assets and mock-ups. [Figma](:figma_link) +- Sentry: To monitor application performance and error tracking. [Sentry](:sentry_link) +- DataDog: This is where we monitor our logs, and server performance, and receive alerts. [DataDog](:datadog_link) +- ArgoCD: Is a kubernetes controller which continuously monitors running applications. [ArgoCD](:argocd_link) +- Laravel Telescope: This is debug assistant for the Laravel framework. [Laravel Telescope](:telescope_link) +- [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](:manager_link) +- Code Owner/Team Lead: For specific questions about the codebase or technical aspects, reach out to our team lead. [Connect with Team Lead](:team_lead_link) +Please be mindful of each individual's preferred contact method and office hours. + +## Prerequisites +To work with this repository, you will need to have the following +installed: +- [Docker](https://www.docker.com) + +## Getting Started +To get started with this repository, follow these steps: +Clone this repository to your local machine. +```sh +git clone git@github.com:RonasIT/laravel-empty-project.git +``` +Build and start containers. It may takes some time. +```sh +docker compose up -d +``` + +## Environments +This repository by default supports three environments: `local`, `development`, +and `testing`. Each environment is represented by an appropriate environment file: +| Environment | File | URL | +| --- | --- |--------------------------------------| +| local | .env | [http://localhost](http://localhost) | +| testing | .env.testing | - | +| development | .env.development | [https://mysite.com](https://mysite.com) | + +## Credentials and Access +Default admin email and password: `mail@mail.com`/`123456` \ No newline at end of file diff --git a/tests/fixtures/InitCommandTest/env.ci-testing.yml b/tests/fixtures/InitCommandTest/env.ci-testing.yml index 900d9dd..d1b64d3 100644 --- a/tests/fixtures/InitCommandTest/env.ci-testing.yml +++ b/tests/fixtures/InitCommandTest/env.ci-testing.yml @@ -39,4 +39,4 @@ FRONTEND_URL=http://localhost JWT_SECRET=av30tMhdKMXfF3OT1OPljEJ7e9KRG7Y4ruqfOPYWx1jRtqpgKwIohtp2n30uZtfs NOVA_GUARD=nova -NOVA_PASSWORDS=nova \ No newline at end of file +NOVA_PASSWORDS=nova diff --git a/tests/fixtures/InitCommandTest/env.development.yml b/tests/fixtures/InitCommandTest/env.development.yml index 0c24285..2a5b9d7 100644 --- a/tests/fixtures/InitCommandTest/env.development.yml +++ b/tests/fixtures/InitCommandTest/env.development.yml @@ -1,9 +1,9 @@ -APP_NAME=my-app +APP_NAME="My App" APP_ENV=development APP_KEY= APP_DEBUG=true APP_LOG_LEVEL=debug -APP_URL=http://localhost +APP_URL=https://mysite.com DB_CONNECTION=pgsql DB_HOST= @@ -36,4 +36,4 @@ PUSHER_APP_SECRET= FRONTEND_URL= -JWT_SHOW_BLACKLIST_EXCEPTION=true \ No newline at end of file +JWT_SHOW_BLACKLIST_EXCEPTION=true diff --git a/tests/fixtures/InitCommandTest/env.testing.yml b/tests/fixtures/InitCommandTest/env.testing.yml index 7c2a234..0c42a14 100644 --- a/tests/fixtures/InitCommandTest/env.testing.yml +++ b/tests/fixtures/InitCommandTest/env.testing.yml @@ -41,4 +41,4 @@ PUSHER_APP_SECRET= FRONTEND_URL=http://localhost JWT_SECRET=av30tMhdKMXfF3OT1OPljEJ7e9KRG7Y4ruqfOPYWx1jRtqpgKwIohtp2n30uZtfs -JWT_SHOW_BLACKLIST_EXCEPTION=true \ No newline at end of file +JWT_SHOW_BLACKLIST_EXCEPTION=true diff --git a/tests/fixtures/InitCommandTest/env.yml b/tests/fixtures/InitCommandTest/env.yml index 39d1e1d..02b1534 100644 --- a/tests/fixtures/InitCommandTest/env.yml +++ b/tests/fixtures/InitCommandTest/env.yml @@ -1,4 +1,4 @@ -APP_NAME=my-app +APP_NAME="My App" APP_ENV=local APP_KEY=base64:RMlWJrRHIuHLYRplJvWaLNwWvRoVkQdDTZe6U1Z4xRY= APP_DEBUG=true @@ -40,4 +40,4 @@ PUSHER_APP_SECRET= FRONTEND_URL=http://localhost JWT_SECRET=av30tMhdKMXfF3OT1OPljEJ7e9KRG7Y4ruqfOPYWx1jRtqpgKwIohtp2n30uZtfs -JWT_SHOW_BLACKLIST_EXCEPTION=true \ No newline at end of file +JWT_SHOW_BLACKLIST_EXCEPTION=true diff --git a/tests/fixtures/InitCommandTest/full_readme.md b/tests/fixtures/InitCommandTest/full_readme.md new file mode 100644 index 0000000..cd3c024 --- /dev/null +++ b/tests/fixtures/InitCommandTest/full_readme.md @@ -0,0 +1,52 @@ +# My App + +Project description will be here + +## 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: +- Issue Tracker: Here, you can report any issues or bugs related to the project. [Issue Tracker](https://gitlab.com/my-project) +- Figma: This is where we maintain all our design assets and mock-ups. [Figma](https://figma.com/my-project) +- Sentry: To monitor application performance and error tracking. [Sentry](https://sentry.com/my-project) +- DataDog: This is where we monitor our logs, and server performance, and receive alerts. [DataDog](https://datadoghq.com/my-project) +- ArgoCD: Is a kubernetes controller which continuously monitors running applications. [ArgoCD](https://argocd.com/my-project) +- Laravel Telescope: This is debug assistant for the Laravel framework. [Laravel Telescope](https://mypsite.com/telescope-link) +- [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](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](lead@mail.com) +Please be mindful of each individual's preferred contact method and office hours. + +## Prerequisites +To work with this repository, you will need to have the following +installed: +- [Docker](https://www.docker.com) + +## Getting Started +To get started with this repository, follow these steps: +Clone this repository to your local machine. +```sh +git clone git@github.com:RonasIT/laravel-empty-project.git +``` +Build and start containers. It may takes some time. +```sh +docker compose up -d +``` + +## Environments +This repository by default supports three environments: `local`, `development`, +and `testing`. Each environment is represented by an appropriate environment file: +| Environment | File | URL | +| --- | --- |--------------------------------------| +| local | .env | [http://localhost](http://localhost) | +| testing | .env.testing | - | +| development | .env.development | [https://mysite.com](https://mysite.com) | + +## Credentials and Access +Default admin email and password: `mail@mail.com`/`123456` \ No newline at end of file diff --git a/tests/fixtures/InitCommandTest/migration.php b/tests/fixtures/InitCommandTest/migration.php index 2f9e433..4e7993d 100644 --- a/tests/fixtures/InitCommandTest/migration.php +++ b/tests/fixtures/InitCommandTest/migration.php @@ -27,4 +27,4 @@ public function down() User::where('email', 'mail@mail.com')->delete(); } } -} \ No newline at end of file +} From 78eb974187588775105595ed54512032700a7e64 Mon Sep 17 00:00:00 2001 From: Vitaly Iskrin Date: Fri, 3 Nov 2023 22:25:18 -0500 Subject: [PATCH 08/11] test: cover InitCommand --- tests/InitCommandTest.php | 40 +++++++++++++++++++ .../InitCommandTest/partial_readme.md | 30 ++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 tests/fixtures/InitCommandTest/partial_readme.md diff --git a/tests/InitCommandTest.php b/tests/InitCommandTest.php index 91f6df7..e86a3ff 100644 --- a/tests/InitCommandTest.php +++ b/tests/InitCommandTest.php @@ -113,6 +113,46 @@ public function testRunWithAdminAndDefaultReadmeCreation() ->assertExitCode(0); } + public function testRunWithAdminAndPartialReadmeCreation() + { + $filePutContentsMock = $this->getFunctionMock('App\Console\Commands', 'file_put_contents'); + + $filePutContentsMock + ->expects($this->exactly(5)) + ->withConsecutive( + ['.env.testing', $this->getFixture('env.testing.yml')], + ['.env', $this->getFixture('env.yml')], + ['.env.development', $this->getFixture('env.development.yml')], + ['.env.ci-testing', $this->getFixture('env.ci-testing.yml')], + ['README.md', $this->getFixture('partial_readme.md')], + ); + + $this->artisan('init "My App"') + ->expectsOutput('Project initialized successfully!') + ->expectsQuestion('Please enter an application URL', 'https://mysite.com') + ->expectsConfirmation('Do you want to generate an admin user?') + ->expectsConfirmation('Do you want to generate a README file?', 'yes') + ->expectsConfirmation('Do you need a `Resources & Contacts` part?', 'yes') + ->expectsConfirmation('Are you going to use Issue Tracker?', 'yes') + ->expectsQuestion('Please enter a Issue Tracker link', '') + ->expectsConfirmation('Are you going to use Figma?') + ->expectsConfirmation('Are you going to use Sentry?') + ->expectsConfirmation('Are you going to use DataDog?') + ->expectsConfirmation('Are you going to use ArgoCD?') + ->expectsConfirmation('Are you going to use Laravel Telescope?') + ->expectsQuestion('Please enter a Manager contact', 'manager@mail.com') + ->expectsQuestion('Please enter a Code Owner/Team Lead contact', '') + ->expectsConfirmation('Do you need a `Prerequisites` part?') + ->expectsConfirmation('Do you need a `Getting Started` part?') + ->expectsConfirmation('Do you need an `Environments` part?', 'yes') + ->expectsConfirmation('Do you need a `Credentials and Access` part?', 'yes') + ->expectsOutput('README generated successfully!') + ->expectsOutput('Don`t forget to fill the following empty values:') + ->expectsOutput('- Issue Tracker link') + ->expectsOutput('- Code Owner/Team Lead contact') + ->assertExitCode(0); + } + public function testRunWithAdminAndFullReadmeCreation() { $filePutContentsMock = $this->getFunctionMock('App\Console\Commands', 'file_put_contents'); diff --git a/tests/fixtures/InitCommandTest/partial_readme.md b/tests/fixtures/InitCommandTest/partial_readme.md new file mode 100644 index 0000000..57ace7b --- /dev/null +++ b/tests/fixtures/InitCommandTest/partial_readme.md @@ -0,0 +1,30 @@ +# My App + +Project description will be here + +## 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: +- Issue Tracker: Here, you can report any issues or bugs related to the project. [Issue Tracker](:issue_tracker_link) +- [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](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](:team_lead_link) +Please be mindful of each individual's preferred contact method and office hours. + +## Environments +This repository by default supports three environments: `local`, `development`, +and `testing`. Each environment is represented by an appropriate environment file: +| Environment | File | URL | +| --- | --- |--------------------------------------| +| local | .env | [http://localhost](http://localhost) | +| testing | .env.testing | - | +| development | .env.development | [https://mysite.com](https://mysite.com) | + +## Credentials and Access From 445efb79024f27095e8df7a4855a85a9ca923454 Mon Sep 17 00:00:00 2001 From: Vitaly Iskrin Date: Sat, 11 Nov 2023 17:11:12 -0600 Subject: [PATCH 09/11] style: change code according to the comments --- .env.development | 2 +- .templates/CONTACTS.md | 1 + .templates/GETTING_STARTED.md | 3 + README.md | 71 +++++-------------- app/Console/Commands/Init.php | 49 +++++++------ resources/views/add_default_user.blade.php | 7 +- tests/InitCommandTest.php | 30 ++++---- .../{env.yml => default.env.yml} | 2 +- .../InitCommandTest/default_readme.md | 14 ++++ .../fixtures/InitCommandTest/env.example.yml | 43 +++++++++++ tests/fixtures/InitCommandTest/full_readme.md | 14 ++++ tests/fixtures/InitCommandTest/migration.php | 7 +- .../InitCommandTest/partial_readme.md | 7 ++ 13 files changed, 153 insertions(+), 97 deletions(-) rename tests/fixtures/InitCommandTest/{env.yml => default.env.yml} (97%) create mode 100644 tests/fixtures/InitCommandTest/env.example.yml diff --git a/.env.development b/.env.development index 83a2a68..ba96d54 100644 --- a/.env.development +++ b/.env.development @@ -1,4 +1,4 @@ -APP_NAME= +APP_NAME="Project Management API" APP_ENV=development APP_KEY= APP_DEBUG=true diff --git a/.templates/CONTACTS.md b/.templates/CONTACTS.md index a16f2c7..5fc025e 100644 --- a/.templates/CONTACTS.md +++ b/.templates/CONTACTS.md @@ -3,4 +3,5 @@ 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](:manager_link) - Code Owner/Team Lead: For specific questions about the codebase or technical aspects, reach out to our team lead. [Connect with Team Lead](:team_lead_link) + Please be mindful of each individual's preferred contact method and office hours. diff --git a/.templates/GETTING_STARTED.md b/.templates/GETTING_STARTED.md index b998b60..9a87d86 100644 --- a/.templates/GETTING_STARTED.md +++ b/.templates/GETTING_STARTED.md @@ -3,10 +3,13 @@ To get started with this repository, follow these steps: Clone this repository to your local machine. + ```sh git clone :git_project_path ``` + Build and start containers. It may takes some time. + ```sh docker compose up -d ``` diff --git a/README.md b/README.md index ebc3653..1ba572e 100644 --- a/README.md +++ b/README.md @@ -2,75 +2,42 @@ [![Coverage Status](https://coveralls.io/repos/github/RonasIT/laravel-empty-project/badge.svg?branch=development)](https://coveralls.io/github/RonasIT/laravel-empty-project?branch=development) -This repository can be used to scaffold a Laravel project. +### Resources +Below are links to tools and services used in this project: +- Issue Tracker: Here, you can report any issues or bugs related to the project. [Issue Tracker](https://github.com/Goodmain/project-management-backpack-laravel/issues) +- [API Documentation](http://localhost) -## Prerequisites +### Contacts +Should you need assistance or have questions, feel free to connect with the following individuals: +- Code Owner: For specific questions about the codebase or technical aspects, reach out to our team lead. [Connect with Code Owner](iskrinvv@gmail.com) + +Please be mindful of each individual's preferred contact method and office hours. +## Prerequisites To work with this repository, you will need to have the following installed: - - [Docker](https://www.docker.com) ## Getting Started - To get started with this repository, follow these steps: - Clone this repository to your local machine. ```sh -git clone git@github.com:RonasIT/laravel-empty-project.git -``` -Remove the existing GitHub [remote](https://git-scm.com/docs/git-remote). -```sh -git remote remove origin -``` -Add your project remote. -```sh -git remote add origin +git clone git@github.com:Goodmain/project-management-backpack-laravel.git ``` Build and start containers. It may takes some time. ```sh docker compose up -d ``` -Check docker containers health status. -```sh -docker ps -``` -You should see something like this. -``` -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -5ae2e24d63bb ronasit/php-nginx-dev:8.1 "/entrypoint bash -c…" About a minute ago Up About a minute 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 9000/tcp laravel-empty-project-nginx-1 -ef37a992c53c webdevops/php:8.1-alpine "/entrypoint supervi…" About a minute ago Up About a minute 9000/tcp laravel-empty-project-php-1 -e02e9f746731 ronasit/postgres:12.5 "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:5433->5432/tcp laravel-empty-project-pgsql_test-1 -4e1fda859342 ronasit/postgres:12.5 "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:5432->5432/tcp laravel-empty-project-pgsql-1 -728c83486f92 redis:6.2.3 "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:6379->6379/tcp laravel-empty-project-redis-1 -``` -Connect to the `nginx` container. -```sh -docker exec -i -t laravel-empty-project-nginx-1 /bin/bash -``` -Init your new project. -```sh -php artisan init -``` -Set required configs: `contact.email` in the `configs/auto-doc.php`. - -Run tests to generate documentation -```sh -php vendor/bin/phpunit tests/ -``` - -API documentation can be accessed by visiting `http://localhost` in your -web browser. - -### Environments +## Environments This repository by default supports three environments: `local`, `development`, and `testing`. Each environment is represented by an appropriate environment file: -- .env -- .env.development -- .env.testing - -## Contributing +| Environment | File | URL | +| --- | --- |--------------------------------------| +| local | .env | [http://localhost](http://localhost) | +| testing | .env.testing | - | +| development | .env.development | [http://localhost](http://localhost) | -Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details. +## Credentials and Access +Default admin email and password: `admin@mail.com`/`a318afa8` \ No newline at end of file diff --git a/app/Console/Commands/Init.php b/app/Console/Commands/Init.php index 135552b..593fbf9 100755 --- a/app/Console/Commands/Init.php +++ b/app/Console/Commands/Init.php @@ -11,6 +11,21 @@ class Init extends Command { const TEMPLATES_PATH = '.templates'; + const RESOURCES_ITEMS = [ + 'issue_tracker' => 'Issue Tracker', + 'figma' => 'Figma', + 'sentry' => 'Sentry', + 'datadog' => 'DataDog', + 'argocd' => 'ArgoCD', + 'telescope' => 'Laravel Telescope', + ]; + + + const CONTACTS_ITEMS = [ + 'manager' => 'Manager', + 'team_lead' => 'Code Owner/Team Lead', + ]; + protected $signature = 'init {application-name : The application name }'; protected $description = 'Initialize required project parameters to run DEV environment'; @@ -28,21 +43,25 @@ public function handle(): void $appName = $this->argument('application-name'); $kebabName = Str::kebab($appName); - $this->appUrl = $this->ask('Please enter an application URL', 'http://localhost'); + $this->appUrl = $this->ask('Please enter an application URL', "https://api.dev.{$kebabName}.com"); $this->updateConfigFile('.env.testing', '=', [ 'DATA_COLLECTOR_KEY' => "{$kebabName}-local" ]); - $this->updateConfigFile('.env', '=', [ + $envFile = file_exists('.env') + ? '.env' + : '.env.example'; + + $this->updateConfigFile($envFile, '=', [ 'APP_NAME' => $appName, 'SWAGGER_REMOTE_DRIVER_KEY' => "{$kebabName}-local" ]); $this->updateConfigFile('.env.development', '=', [ 'APP_NAME' => $appName, - 'DATA_COLLECTOR_KEY' => "{$kebabName}", - 'APP_URL' => "{$this->appUrl}", + 'DATA_COLLECTOR_KEY' => $kebabName, + 'APP_URL' => $this->appUrl, ]); $this->updateConfigFile('.env.ci-testing', '=', [ @@ -127,18 +146,9 @@ protected function fillResourcesAndContacts(): void protected function fillResources(): void { - $resources = [ - 'issue_tracker' => 'Issue Tracker', - 'figma' => 'Figma', - 'sentry' => 'Sentry', - 'datadog' => 'DataDog', - 'argocd' => 'ArgoCD', - 'telescope' => 'Laravel Telescope', - ]; - $filePart = $this->loadReadmePart('RESOURCES.md'); - foreach ($resources as $key => $title) { + foreach (self::RESOURCES_ITEMS as $key => $title) { if ($this->confirm("Are you going to use {$title}?", true)) { $defaultLink = ($key === 'telescope') ? $this->appUrl . '/telescope' : ''; @@ -160,14 +170,9 @@ protected function fillResources(): void protected function fillContacts(): void { - $contacts = [ - 'manager' => 'Manager', - 'team_lead' => 'Code Owner/Team Lead', - ]; - $filePart = $this->loadReadmePart('CONTACTS.md'); - foreach ($contacts as $key => $title) { + foreach (self::CONTACTS_ITEMS as $key => $title) { if ($link = $this->ask("Please enter a {$title} contact", '')) { $this->setReadmeValue($filePart, "{$key}_link", $link); } else { @@ -256,12 +261,12 @@ protected function updateConfigFile($fileName, $separator, $data): void protected function loadReadmePart(string $fileName): string { - return file_get_contents(self::TEMPLATES_PATH . '/' . $fileName); + return file_get_contents(self::TEMPLATES_PATH . DIRECTORY_SEPARATOR . $fileName); } protected function updateReadmeFile(string $filePart): void { - $filePart = preg_replace('#(\n){2,}#', "\n", $filePart); + $filePart = preg_replace('#(\n){3,}#', "\n", $filePart); $this->readmeContent .= "\n" . $filePart; } diff --git a/resources/views/add_default_user.blade.php b/resources/views/add_default_user.blade.php index 02ed8de..77f4138 100644 --- a/resources/views/add_default_user.blade.php +++ b/resources/views/add_default_user.blade.php @@ -1,4 +1,3 @@ -use App\Models\User; use Illuminate\Database\Migrations\Migration; use Illuminate\Support\Facades\Hash; use RonasIT\Support\Traits\MigrationTrait; @@ -10,7 +9,7 @@ class AddDefaultUser extends Migration public function up() { if (config('app.env') !== 'testing') { - User::create([ + DB::table('users')->insert([ 'name' => '{{ $name }}', 'email' => '{{ $email }}', 'password' => Hash::make('{{ $password }}'), @@ -22,7 +21,9 @@ public function up() public function down() { if (config('app.env') !== 'testing') { - User::where('email', '{{ $email }}')->delete(); + DB::table('users') + ->where('email', '{{ $email }}') + ->delete(); } } } diff --git a/tests/InitCommandTest.php b/tests/InitCommandTest.php index e86a3ff..7f8b5e3 100644 --- a/tests/InitCommandTest.php +++ b/tests/InitCommandTest.php @@ -8,11 +8,6 @@ class InitCommandTest extends TestCase { use PHPMock; - public function setUp(): void - { - TestCase::setUp(); - } - public function testRunWithoutAdminAndReadmeCreation() { $filePutContentsMock = $this->getFunctionMock('App\Console\Commands', 'file_put_contents'); @@ -21,12 +16,13 @@ public function testRunWithoutAdminAndReadmeCreation() ->expects($this->exactly(4)) ->withConsecutive( ['.env.testing', $this->getFixture('env.testing.yml')], - ['.env', $this->getFixture('env.yml')], + ['.env.example', $this->getFixture('env.example.yml')], ['.env.development', $this->getFixture('env.development.yml')], ['.env.ci-testing', $this->getFixture('env.ci-testing.yml')], ); - $this->artisan('init "My App"') + $this + ->artisan('init "My App"') ->expectsOutput('Project initialized successfully!') ->expectsQuestion('Please enter an application URL', 'https://mysite.com') ->expectsConfirmation('Do you want to generate an admin user?') @@ -42,13 +38,14 @@ public function testRunWithAdminAndWithoutReadmeCreation() ->expects($this->exactly(5)) ->withConsecutive( ['.env.testing', $this->getFixture('env.testing.yml')], - ['.env', $this->getFixture('env.yml')], + ['.env.example', $this->getFixture('env.example.yml')], ['.env.development', $this->getFixture('env.development.yml')], ['.env.ci-testing', $this->getFixture('env.ci-testing.yml')], ['database/migrations/2018_11_11_111111_add_default_user.php', $this->getFixture('migration.php')], ); - $this->artisan('init "My App"') + $this + ->artisan('init "My App"') ->expectsOutput('Project initialized successfully!') ->expectsQuestion('Please enter an application URL', 'https://mysite.com') ->expectsConfirmation('Do you want to generate an admin user?', 'yes') @@ -67,14 +64,15 @@ public function testRunWithAdminAndDefaultReadmeCreation() ->expects($this->exactly(6)) ->withConsecutive( ['.env.testing', $this->getFixture('env.testing.yml')], - ['.env', $this->getFixture('env.yml')], + ['.env.example', $this->getFixture('env.example.yml')], ['.env.development', $this->getFixture('env.development.yml')], ['.env.ci-testing', $this->getFixture('env.ci-testing.yml')], ['database/migrations/2018_11_11_111111_add_default_user.php', $this->getFixture('migration.php')], ['README.md', $this->getFixture('default_readme.md')], ); - $this->artisan('init "My App"') + $this + ->artisan('init "My App"') ->expectsOutput('Project initialized successfully!') ->expectsQuestion('Please enter an application URL', 'https://mysite.com') ->expectsConfirmation('Do you want to generate an admin user?', 'yes') @@ -121,13 +119,14 @@ public function testRunWithAdminAndPartialReadmeCreation() ->expects($this->exactly(5)) ->withConsecutive( ['.env.testing', $this->getFixture('env.testing.yml')], - ['.env', $this->getFixture('env.yml')], + ['.env.example', $this->getFixture('env.example.yml')], ['.env.development', $this->getFixture('env.development.yml')], ['.env.ci-testing', $this->getFixture('env.ci-testing.yml')], ['README.md', $this->getFixture('partial_readme.md')], ); - $this->artisan('init "My App"') + $this + ->artisan('init "My App"') ->expectsOutput('Project initialized successfully!') ->expectsQuestion('Please enter an application URL', 'https://mysite.com') ->expectsConfirmation('Do you want to generate an admin user?') @@ -161,14 +160,15 @@ public function testRunWithAdminAndFullReadmeCreation() ->expects($this->exactly(6)) ->withConsecutive( ['.env.testing', $this->getFixture('env.testing.yml')], - ['.env', $this->getFixture('env.yml')], + ['.env.example', $this->getFixture('env.example.yml')], ['.env.development', $this->getFixture('env.development.yml')], ['.env.ci-testing', $this->getFixture('env.ci-testing.yml')], ['database/migrations/2018_11_11_111111_add_default_user.php', $this->getFixture('migration.php')], ['README.md', $this->getFixture('full_readme.md')], ); - $this->artisan('init "My App"') + $this + ->artisan('init "My App"') ->expectsOutput('Project initialized successfully!') ->expectsQuestion('Please enter an application URL', 'https://mysite.com') ->expectsConfirmation('Do you want to generate an admin user?', 'yes') diff --git a/tests/fixtures/InitCommandTest/env.yml b/tests/fixtures/InitCommandTest/default.env.yml similarity index 97% rename from tests/fixtures/InitCommandTest/env.yml rename to tests/fixtures/InitCommandTest/default.env.yml index 02b1534..84bae44 100644 --- a/tests/fixtures/InitCommandTest/env.yml +++ b/tests/fixtures/InitCommandTest/default.env.yml @@ -1,4 +1,4 @@ -APP_NAME="My App" +APP_NAME= APP_ENV=local APP_KEY=base64:RMlWJrRHIuHLYRplJvWaLNwWvRoVkQdDTZe6U1Z4xRY= APP_DEBUG=true diff --git a/tests/fixtures/InitCommandTest/default_readme.md b/tests/fixtures/InitCommandTest/default_readme.md index 5508159..807ce48 100644 --- a/tests/fixtures/InitCommandTest/default_readme.md +++ b/tests/fixtures/InitCommandTest/default_readme.md @@ -3,11 +3,13 @@ Project description will be here ## 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: - Issue Tracker: Here, you can report any issues or bugs related to the project. [Issue Tracker](:issue_tracker_link) - Figma: This is where we maintain all our design assets and mock-ups. [Figma](:figma_link) @@ -18,30 +20,41 @@ Below are links to tools and services used in this project: - [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](:manager_link) - Code Owner/Team Lead: For specific questions about the codebase or technical aspects, reach out to our team lead. [Connect with Team Lead](:team_lead_link) + Please be mindful of each individual's preferred contact method and office hours. ## Prerequisites + To work with this repository, you will need to have the following installed: + - [Docker](https://www.docker.com) ## Getting Started + To get started with this repository, follow these steps: + Clone this repository to your local machine. + ```sh git clone git@github.com:RonasIT/laravel-empty-project.git ``` + Build and start containers. It may takes some time. + ```sh docker compose up -d ``` ## Environments + This repository by default supports three environments: `local`, `development`, and `testing`. Each environment is represented by an appropriate environment file: + | Environment | File | URL | | --- | --- |--------------------------------------| | local | .env | [http://localhost](http://localhost) | @@ -49,4 +62,5 @@ and `testing`. Each environment is represented by an appropriate environment fil | development | .env.development | [https://mysite.com](https://mysite.com) | ## Credentials and Access + Default admin email and password: `mail@mail.com`/`123456` \ No newline at end of file diff --git a/tests/fixtures/InitCommandTest/env.example.yml b/tests/fixtures/InitCommandTest/env.example.yml new file mode 100644 index 0000000..ac5788b --- /dev/null +++ b/tests/fixtures/InitCommandTest/env.example.yml @@ -0,0 +1,43 @@ +APP_NAME="My App" +APP_ENV=local +APP_KEY= +APP_DEBUG=true +APP_LOG_LEVEL=debug +APP_URL=http://localhost + +DB_CONNECTION=pgsql +DB_HOST=pgsql +DB_PORT=5432 +DB_DATABASE=pgdb +DB_USERNAME=pguser +DB_PASSWORD="" + +BROADCAST_DRIVER=log +CACHE_DRIVER=redis +SESSION_DRIVER=redis +QUEUE_CONNECTION=sync + +REDIS_HOST=redis +REDIS_PASSWORD=null +REDIS_PORT=6379 + +MAIL_DRIVER=smtp +MAIL_HOST=smtp.mailtrap.io +MAIL_PORT=2525 +MAIL_USERNAME=null +MAIL_PASSWORD=null +MAIL_ENCRYPTION=null + +FILESYSTEM_DISK=local +GOOGLE_CLOUD_STORAGE_BUCKET=ronasit-development +GOOGLE_CLOUD_PROJECT_ID=ronas-it-development +GOOGLE_CLOUD_KEY_FILE=gcs.key + +PUSHER_APP_ID= +PUSHER_APP_KEY= +PUSHER_APP_SECRET= + +FRONTEND_URL=http://localhost + +JWT_SECRET= +JWT_SHOW_BLACKLIST_EXCEPTION=true diff --git a/tests/fixtures/InitCommandTest/full_readme.md b/tests/fixtures/InitCommandTest/full_readme.md index cd3c024..183dda5 100644 --- a/tests/fixtures/InitCommandTest/full_readme.md +++ b/tests/fixtures/InitCommandTest/full_readme.md @@ -3,11 +3,13 @@ Project description will be here ## 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: - Issue Tracker: Here, you can report any issues or bugs related to the project. [Issue Tracker](https://gitlab.com/my-project) - Figma: This is where we maintain all our design assets and mock-ups. [Figma](https://figma.com/my-project) @@ -18,30 +20,41 @@ Below are links to tools and services used in this project: - [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](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](lead@mail.com) + Please be mindful of each individual's preferred contact method and office hours. ## Prerequisites + To work with this repository, you will need to have the following installed: + - [Docker](https://www.docker.com) ## Getting Started + To get started with this repository, follow these steps: + Clone this repository to your local machine. + ```sh git clone git@github.com:RonasIT/laravel-empty-project.git ``` + Build and start containers. It may takes some time. + ```sh docker compose up -d ``` ## Environments + This repository by default supports three environments: `local`, `development`, and `testing`. Each environment is represented by an appropriate environment file: + | Environment | File | URL | | --- | --- |--------------------------------------| | local | .env | [http://localhost](http://localhost) | @@ -49,4 +62,5 @@ and `testing`. Each environment is represented by an appropriate environment fil | development | .env.development | [https://mysite.com](https://mysite.com) | ## Credentials and Access + Default admin email and password: `mail@mail.com`/`123456` \ No newline at end of file diff --git a/tests/fixtures/InitCommandTest/migration.php b/tests/fixtures/InitCommandTest/migration.php index 4e7993d..cc0abd6 100644 --- a/tests/fixtures/InitCommandTest/migration.php +++ b/tests/fixtures/InitCommandTest/migration.php @@ -1,6 +1,5 @@ insert([ 'name' => 'TestAdmin', 'email' => 'mail@mail.com', 'password' => Hash::make('123456'), @@ -24,7 +23,9 @@ public function up() public function down() { if (config('app.env') !== 'testing') { - User::where('email', 'mail@mail.com')->delete(); + DB::table('users') + ->where('email', 'mail@mail.com') + ->delete(); } } } diff --git a/tests/fixtures/InitCommandTest/partial_readme.md b/tests/fixtures/InitCommandTest/partial_readme.md index 57ace7b..207c892 100644 --- a/tests/fixtures/InitCommandTest/partial_readme.md +++ b/tests/fixtures/InitCommandTest/partial_readme.md @@ -3,24 +3,30 @@ Project description will be here ## 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: - Issue Tracker: Here, you can report any issues or bugs related to the project. [Issue Tracker](:issue_tracker_link) - [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](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](:team_lead_link) + Please be mindful of each individual's preferred contact method and office hours. ## Environments + This repository by default supports three environments: `local`, `development`, and `testing`. Each environment is represented by an appropriate environment file: + | Environment | File | URL | | --- | --- |--------------------------------------| | local | .env | [http://localhost](http://localhost) | @@ -28,3 +34,4 @@ and `testing`. Each environment is represented by an appropriate environment fil | development | .env.development | [https://mysite.com](https://mysite.com) | ## Credentials and Access + From ff99db373428c5d3235b34abe09a7d5eed17d0e8 Mon Sep 17 00:00:00 2001 From: Vitaly Iskrin Date: Mon, 13 Nov 2023 00:36:55 -0600 Subject: [PATCH 10/11] refactor: move duplicated code into the trait --- tests/InitCommandTest.php | 73 +++++-------------- tests/Support/InitCommandMockTrait.php | 38 ++++++++++ .../InitCommandTest/default_readme.md | 2 +- tests/fixtures/InitCommandTest/full_readme.md | 2 +- 4 files changed, 59 insertions(+), 56 deletions(-) create mode 100644 tests/Support/InitCommandMockTrait.php diff --git a/tests/InitCommandTest.php b/tests/InitCommandTest.php index 7f8b5e3..2656c29 100644 --- a/tests/InitCommandTest.php +++ b/tests/InitCommandTest.php @@ -2,24 +2,17 @@ namespace App\Tests; +use App\Tests\Support\InitCommandMockTrait; use phpmock\phpunit\PHPMock; class InitCommandTest extends TestCase { + use InitCommandMockTrait; use PHPMock; public function testRunWithoutAdminAndReadmeCreation() { - $filePutContentsMock = $this->getFunctionMock('App\Console\Commands', 'file_put_contents'); - - $filePutContentsMock - ->expects($this->exactly(4)) - ->withConsecutive( - ['.env.testing', $this->getFixture('env.testing.yml')], - ['.env.example', $this->getFixture('env.example.yml')], - ['.env.development', $this->getFixture('env.development.yml')], - ['.env.ci-testing', $this->getFixture('env.ci-testing.yml')], - ); + $this->mockFilePutContent(); $this ->artisan('init "My App"') @@ -32,17 +25,9 @@ public function testRunWithoutAdminAndReadmeCreation() public function testRunWithAdminAndWithoutReadmeCreation() { - $filePutContentsMock = $this->getFunctionMock('App\Console\Commands', 'file_put_contents'); - - $filePutContentsMock - ->expects($this->exactly(5)) - ->withConsecutive( - ['.env.testing', $this->getFixture('env.testing.yml')], - ['.env.example', $this->getFixture('env.example.yml')], - ['.env.development', $this->getFixture('env.development.yml')], - ['.env.ci-testing', $this->getFixture('env.ci-testing.yml')], - ['database/migrations/2018_11_11_111111_add_default_user.php', $this->getFixture('migration.php')], - ); + $this->mockFilePutContent([ + 'database/migrations/2018_11_11_111111_add_default_user.php' => $this->getFixture('migration.php'), + ]); $this ->artisan('init "My App"') @@ -58,18 +43,12 @@ public function testRunWithAdminAndWithoutReadmeCreation() public function testRunWithAdminAndDefaultReadmeCreation() { - $filePutContentsMock = $this->getFunctionMock('App\Console\Commands', 'file_put_contents'); + $this->mockShellExec(); - $filePutContentsMock - ->expects($this->exactly(6)) - ->withConsecutive( - ['.env.testing', $this->getFixture('env.testing.yml')], - ['.env.example', $this->getFixture('env.example.yml')], - ['.env.development', $this->getFixture('env.development.yml')], - ['.env.ci-testing', $this->getFixture('env.ci-testing.yml')], - ['database/migrations/2018_11_11_111111_add_default_user.php', $this->getFixture('migration.php')], - ['README.md', $this->getFixture('default_readme.md')], - ); + $this->mockFilePutContent([ + 'database/migrations/2018_11_11_111111_add_default_user.php' => $this->getFixture('migration.php'), + 'README.md' => $this->getFixture('default_readme.md'), + ]); $this ->artisan('init "My App"') @@ -113,17 +92,9 @@ public function testRunWithAdminAndDefaultReadmeCreation() public function testRunWithAdminAndPartialReadmeCreation() { - $filePutContentsMock = $this->getFunctionMock('App\Console\Commands', 'file_put_contents'); - - $filePutContentsMock - ->expects($this->exactly(5)) - ->withConsecutive( - ['.env.testing', $this->getFixture('env.testing.yml')], - ['.env.example', $this->getFixture('env.example.yml')], - ['.env.development', $this->getFixture('env.development.yml')], - ['.env.ci-testing', $this->getFixture('env.ci-testing.yml')], - ['README.md', $this->getFixture('partial_readme.md')], - ); + $this->mockFilePutContent([ + 'README.md' => $this->getFixture('partial_readme.md'), + ]); $this ->artisan('init "My App"') @@ -154,18 +125,12 @@ public function testRunWithAdminAndPartialReadmeCreation() public function testRunWithAdminAndFullReadmeCreation() { - $filePutContentsMock = $this->getFunctionMock('App\Console\Commands', 'file_put_contents'); + $this->mockShellExec(); - $filePutContentsMock - ->expects($this->exactly(6)) - ->withConsecutive( - ['.env.testing', $this->getFixture('env.testing.yml')], - ['.env.example', $this->getFixture('env.example.yml')], - ['.env.development', $this->getFixture('env.development.yml')], - ['.env.ci-testing', $this->getFixture('env.ci-testing.yml')], - ['database/migrations/2018_11_11_111111_add_default_user.php', $this->getFixture('migration.php')], - ['README.md', $this->getFixture('full_readme.md')], - ); + $this->mockFilePutContent([ + 'database/migrations/2018_11_11_111111_add_default_user.php' => $this->getFixture('migration.php'), + 'README.md' => $this->getFixture('full_readme.md'), + ]); $this ->artisan('init "My App"') diff --git a/tests/Support/InitCommandMockTrait.php b/tests/Support/InitCommandMockTrait.php new file mode 100644 index 0000000..12888f4 --- /dev/null +++ b/tests/Support/InitCommandMockTrait.php @@ -0,0 +1,38 @@ + $this->getFixture('env.testing.yml'), + '.env.example' => $this->getFixture('env.example.yml'), + '.env.development' => $this->getFixture('env.development.yml'), + '.env.ci-testing' => $this->getFixture('env.ci-testing.yml'), + ]; + + $fileContents = $defaultFileContents + $fileContents; + + $mock = $this->getFunctionMock('App\Console\Commands', 'file_put_contents'); + + $mock + ->expects($this->exactly(count($fileContents))) + ->willReturnCallback(fn ($file) => $fileContents[$file]); + } + + public function mockShellExec(): void + { + $mock = $this->getFunctionMock('App\Console\Commands', 'shell_exec'); + + $mock + ->expects($this->once()) + ->with('git ls-remote --get-url origin') + ->willReturn('https://github.com/ronasit/laravel-helpers.git'); + } +} \ No newline at end of file diff --git a/tests/fixtures/InitCommandTest/default_readme.md b/tests/fixtures/InitCommandTest/default_readme.md index 807ce48..3d9a59d 100644 --- a/tests/fixtures/InitCommandTest/default_readme.md +++ b/tests/fixtures/InitCommandTest/default_readme.md @@ -41,7 +41,7 @@ To get started with this repository, follow these steps: Clone this repository to your local machine. ```sh -git clone git@github.com:RonasIT/laravel-empty-project.git +git clone https://github.com/RonasIT/laravel-empty-project ``` Build and start containers. It may takes some time. diff --git a/tests/fixtures/InitCommandTest/full_readme.md b/tests/fixtures/InitCommandTest/full_readme.md index 183dda5..4318874 100644 --- a/tests/fixtures/InitCommandTest/full_readme.md +++ b/tests/fixtures/InitCommandTest/full_readme.md @@ -41,7 +41,7 @@ To get started with this repository, follow these steps: Clone this repository to your local machine. ```sh -git clone git@github.com:RonasIT/laravel-empty-project.git +git clone https://github.com/RonasIT/laravel-empty-project ``` Build and start containers. It may takes some time. From b8571ee3a830962c99de79e6753f8336925b2dc6 Mon Sep 17 00:00:00 2001 From: Vitaly Iskrin Date: Tue, 14 Nov 2023 22:40:24 -0600 Subject: [PATCH 11/11] chore: revert changes in readme.md and .env.development --- .env.development | 2 +- README.md | 88 +++++++++++++++++++++++++++-------- app/Console/Commands/Init.php | 3 +- 3 files changed, 71 insertions(+), 22 deletions(-) diff --git a/.env.development b/.env.development index ba96d54..83a2a68 100644 --- a/.env.development +++ b/.env.development @@ -1,4 +1,4 @@ -APP_NAME="Project Management API" +APP_NAME= APP_ENV=development APP_KEY= APP_DEBUG=true diff --git a/README.md b/README.md index 1ba572e..ccefd18 100644 --- a/README.md +++ b/README.md @@ -2,42 +2,92 @@ [![Coverage Status](https://coveralls.io/repos/github/RonasIT/laravel-empty-project/badge.svg?branch=development)](https://coveralls.io/github/RonasIT/laravel-empty-project?branch=development) -### Resources -Below are links to tools and services used in this project: -- Issue Tracker: Here, you can report any issues or bugs related to the project. [Issue Tracker](https://github.com/Goodmain/project-management-backpack-laravel/issues) -- [API Documentation](http://localhost) - -### Contacts -Should you need assistance or have questions, feel free to connect with the following individuals: -- Code Owner: For specific questions about the codebase or technical aspects, reach out to our team lead. [Connect with Code Owner](iskrinvv@gmail.com) - -Please be mindful of each individual's preferred contact method and office hours. +This repository can be used to scaffold a Laravel project. ## Prerequisites + To work with this repository, you will need to have the following installed: + - [Docker](https://www.docker.com) ## Getting Started + To get started with this repository, follow these steps: + Clone this repository to your local machine. + +```sh +git clone git@github.com:RonasIT/laravel-empty-project.git +``` + +Remove the existing GitHub [remote](https://git-scm.com/docs/git-remote). + ```sh -git clone git@github.com:Goodmain/project-management-backpack-laravel.git +git remote remove origin ``` + +Add your project remote. + +```sh +git remote add origin +``` + Build and start containers. It may takes some time. + ```sh docker compose up -d ``` -## Environments +Check docker containers health status. + +```sh +docker ps +``` + +You should see something like this. + +``` +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +5ae2e24d63bb ronasit/php-nginx-dev:8.1 "/entrypoint bash -c…" About a minute ago Up About a minute 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 9000/tcp laravel-empty-project-nginx-1 +ef37a992c53c webdevops/php:8.1-alpine "/entrypoint supervi…" About a minute ago Up About a minute 9000/tcp laravel-empty-project-php-1 +e02e9f746731 ronasit/postgres:12.5 "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:5433->5432/tcp laravel-empty-project-pgsql_test-1 +4e1fda859342 ronasit/postgres:12.5 "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:5432->5432/tcp laravel-empty-project-pgsql-1 +728c83486f92 redis:6.2.3 "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:6379->6379/tcp laravel-empty-project-redis-1 +``` + +Connect to the `nginx` container. + +```sh +docker exec -i -t laravel-empty-project-nginx-1 /bin/bash +``` + +Init your new project. + +```sh +php artisan init +``` + +Set required configs: `contact.email` in the `configs/auto-doc.php`. + +Run tests to generate documentation + +```sh +php vendor/bin/phpunit tests/ +``` + +API documentation can be accessed by visiting `http://localhost` in your +web browser. + +### Environments + This repository by default supports three environments: `local`, `development`, and `testing`. Each environment is represented by an appropriate environment file: -| Environment | File | URL | -| --- | --- |--------------------------------------| -| local | .env | [http://localhost](http://localhost) | -| testing | .env.testing | - | -| development | .env.development | [http://localhost](http://localhost) | +- .env +- .env.development +- .env.testing + +## Contributing -## Credentials and Access -Default admin email and password: `admin@mail.com`/`a318afa8` \ No newline at end of file +Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details. diff --git a/app/Console/Commands/Init.php b/app/Console/Commands/Init.php index 593fbf9..4598fa2 100755 --- a/app/Console/Commands/Init.php +++ b/app/Console/Commands/Init.php @@ -20,7 +20,6 @@ class Init extends Command 'telescope' => 'Laravel Telescope', ]; - const CONTACTS_ITEMS = [ 'manager' => 'Manager', 'team_lead' => 'Code Owner/Team Lead', @@ -49,7 +48,7 @@ public function handle(): void 'DATA_COLLECTOR_KEY' => "{$kebabName}-local" ]); - $envFile = file_exists('.env') + $envFile = (file_exists('.env')) ? '.env' : '.env.example';