Skip to content

Commit c9d1269

Browse files
committed
refactor:add test case
1 parent 0a037a6 commit c9d1269

File tree

4 files changed

+170
-17
lines changed

4 files changed

+170
-17
lines changed

src/Commands/InitCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ protected function fillCredentialsAndAccess(string $kebabName): void
333333
{
334334
$filePart = $this->loadReadmePart('CREDENTIALS_AND_ACCESS.md');
335335

336-
if ($this->adminCredentials) {
336+
if (!empty($this->adminCredentials)) {
337337
$this->setReadmeValue($filePart, 'admin_email', $this->adminCredentials['email']);
338338
$this->setReadmeValue($filePart, 'admin_password', $this->adminCredentials['password']);
339339
}
@@ -347,7 +347,7 @@ protected function fillCredentialsAndAccess(string $kebabName): void
347347
continue;
348348
}
349349

350-
if ($this->adminCredentials && $this->confirm("Is {$title}'s admin the same as default one?", true)) {
350+
if (!empty($this->adminCredentials) && $this->confirm("Is {$title}'s admin the same as default one?", true)) {
351351
$email = $this->adminCredentials['email'];
352352
$password = $this->adminCredentials['password'];
353353
} else {

tests/InitCommandTest.php

Lines changed: 123 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -428,22 +428,18 @@ public function testRunWithAdminAndPartialReadmeCreation()
428428
->expectsQuestion(
429429
'Are you going to use Laravel Telescope? '
430430
. 'Please enter a link or select `later` to do it later, otherwise select `no`.',
431-
'later'
431+
'no'
432432
)
433433
->expectsQuestion(
434434
'Are you going to use Laravel Nova? '
435435
. 'Please enter a link or select `later` to do it later, otherwise select `no`.',
436-
'later'
436+
'no'
437437
)
438438
->expectsQuestion('Please enter a Manager\'s email', 'manager@mail.com')
439439
->expectsConfirmation('Do you need a `Prerequisites` part?')
440440
->expectsConfirmation('Do you need a `Getting Started` part?')
441441
->expectsConfirmation('Do you need an `Environments` part?', 'yes')
442442
->expectsConfirmation('Do you need a `Credentials and Access` part?', 'yes')
443-
->expectsQuestion('Please enter a Laravel Telescope\'s admin email', 'telescope_mail@mail.com')
444-
->expectsQuestion('Please enter a Laravel Telescope\'s admin password', '654321')
445-
->expectsQuestion('Please enter a Laravel Nova\'s admin email', 'nova_mail@mail.com')
446-
->expectsQuestion('Please enter a Laravel Nova\'s admin password', '654321')
447443
->expectsOutput('README generated successfully!')
448444
->expectsOutput('Don`t forget to fill the following empty values:')
449445
->expectsOutput('- Issue Tracker link')
@@ -603,4 +599,125 @@ public function testRunWithAdminAndFullReadmeCreationAndRemovingInitializatorIns
603599
->expectsConfirmation('Do you want to uninstall project-initializator package?', 'yes')
604600
->assertExitCode(0);
605601
}
602+
603+
public function testRunWithoutAdminAndUsingTelescope()
604+
{
605+
$this->mockChangeConfig('config/auto-doc.php', 'auto_doc.php', 'auto_doc_after_changes.php');
606+
607+
$this->mockFileGetContent(
608+
[
609+
'arguments' => ['.env.example'],
610+
'result' => $this->getFixture('env.example.yml'),
611+
],
612+
[
613+
'arguments' => ['.env.development'],
614+
'result' => $this->getFixture('env.development.yml'),
615+
],
616+
[
617+
'arguments' => [base_path('/vendor/ronasit/laravel-project-initializator/resources/md/readme/README.md')],
618+
'result' => $this->getTemplate('README.md'),
619+
],
620+
[
621+
'arguments' => [base_path('/vendor/ronasit/laravel-project-initializator/resources/md/readme/RESOURCES_AND_CONTACTS.md')],
622+
'result' => $this->getTemplate('RESOURCES_AND_CONTACTS.md'),
623+
],
624+
[
625+
'arguments' => [base_path('/vendor/ronasit/laravel-project-initializator/resources/md/readme/RESOURCES.md')],
626+
'result' => $this->getTemplate('RESOURCES.md'),
627+
],
628+
[
629+
'arguments' => [base_path('/vendor/ronasit/laravel-project-initializator/resources/md/readme/CONTACTS.md')],
630+
'result' => $this->getTemplate('CONTACTS.md'),
631+
],
632+
[
633+
'arguments' => [base_path('/vendor/ronasit/laravel-project-initializator/resources/md/readme/ENVIRONMENTS.md')],
634+
'result' => $this->getTemplate('ENVIRONMENTS.md'),
635+
],
636+
[
637+
'arguments' => [base_path('/vendor/ronasit/laravel-project-initializator/resources/md/readme/CREDENTIALS_AND_ACCESS.md')],
638+
'result' => $this->getTemplate('CREDENTIALS_AND_ACCESS.md'),
639+
],
640+
);
641+
642+
$this->mockFilePutContent(
643+
'env.example.yml',
644+
'env.development.yml',
645+
[
646+
'README.md',
647+
$this->getFixture('partial_readme_with_telescope.md'),
648+
]
649+
);
650+
651+
$this->mockShellExec(
652+
['arguments' => 'composer require ronasit/laravel-helpers --ansi'],
653+
['arguments' => 'composer require ronasit/laravel-swagger --ansi'],
654+
['arguments' => 'php artisan vendor:publish --provider="RonasIT\AutoDoc\AutoDocServiceProvider" --ansi'],
655+
['arguments' => 'composer require --dev ronasit/laravel-entity-generator --ansi'],
656+
['arguments' => 'composer require ronasit/laravel-telescope-extension --ansi'],
657+
['arguments' => 'php artisan telescope:install --ansi'],
658+
);
659+
660+
$this
661+
->artisan('init "My App"')
662+
->expectsConfirmation('The application name is not in PascalCase, would you like to use MyApp')
663+
->expectsQuestion("Please specify a Code Owner/Team Lead's email", 'test@example.com')
664+
->expectsOutput('Project initialized successfully!')
665+
->expectsQuestion('Please enter an application URL', 'https://mysite.com')
666+
->expectsChoice('Please choose the authentication type', 'none', ['clerk', 'none'])
667+
->expectsConfirmation('Do you want to generate an admin user?')
668+
->expectsConfirmation('Do you want to generate a README file?', 'yes')
669+
->expectsQuestion('What type of application will your API serve?', 'Web')
670+
->expectsConfirmation('Do you need a `Resources & Contacts` part?', 'yes')
671+
->expectsQuestion(
672+
'Are you going to use Issue Tracker? '
673+
. 'Please enter a link or select `later` to do it later, otherwise select `no`.',
674+
'later'
675+
)
676+
->expectsQuestion(
677+
'Are you going to use Figma? '
678+
. 'Please enter a link or select `later` to do it later, otherwise select `no`.',
679+
'no'
680+
)
681+
->expectsQuestion(
682+
'Are you going to use Sentry? '
683+
. 'Please enter a link or select `later` to do it later, otherwise select `no`.',
684+
'no'
685+
)
686+
->expectsQuestion(
687+
'Are you going to use DataDog? '
688+
. 'Please enter a link or select `later` to do it later, otherwise select `no`.',
689+
'no'
690+
)
691+
->expectsQuestion(
692+
'Are you going to use ArgoCD? '
693+
. 'Please enter a link or select `later` to do it later, otherwise select `no`.',
694+
'no'
695+
)
696+
->expectsQuestion(
697+
'Are you going to use Laravel Telescope? '
698+
. 'Please enter a link or select `later` to do it later, otherwise select `no`.',
699+
'later'
700+
)
701+
->expectsQuestion(
702+
'Are you going to use Laravel Nova? '
703+
. 'Please enter a link or select `later` to do it later, otherwise select `no`.',
704+
'later'
705+
)
706+
->expectsQuestion('Please enter a Manager\'s email', 'manager@mail.com')
707+
->expectsConfirmation('Do you need a `Prerequisites` part?')
708+
->expectsConfirmation('Do you need a `Getting Started` part?')
709+
->expectsConfirmation('Do you need an `Environments` part?', 'yes')
710+
->expectsConfirmation('Do you need a `Credentials and Access` part?', 'yes')
711+
->expectsQuestion('Please enter a Laravel Telescope\'s admin email', 'telescope_mail@mail.com')
712+
->expectsQuestion('Please enter a Laravel Telescope\'s admin password', '654321')
713+
->expectsQuestion('Please enter a Laravel Nova\'s admin email', 'nova_mail@mail.com')
714+
->expectsQuestion('Please enter a Laravel Nova\'s admin password', '654321')
715+
->expectsOutput('README generated successfully!')
716+
->expectsOutput('Don`t forget to fill the following empty values:')
717+
->expectsOutput('- Issue Tracker link')
718+
->expectsConfirmation('Would you use Renovate dependabot?')
719+
->expectsConfirmation('Do you want to install media package?')
720+
->expectsConfirmation('Do you want to uninstall project-initializator package?')
721+
->assertExitCode(0);
722+
}
606723
}

tests/fixtures/InitCommandTest/partial_readme.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ process, so you can efficiently find what you need or reach out to who you need.
1212

1313
Below are links to tools and services used in this project:
1414
- [Issue Tracker](): Here, you can report any issues or bugs related to the project. (will be added later)
15-
- [Laravel Telescope](): This is debug assistant for the Laravel framework. (will be added later)
16-
- [Laravel Nova](): This is admin panel for the Laravel framework. (will be added later)
1715
- [API Documentation](https://mysite.com)
1816

1917
### Contacts
@@ -36,10 +34,3 @@ and `testing`. Each environment is represented by an appropriate environment fil
3634
| development | .env.development | [https://mysite.com](https://mysite.com) |
3735

3836
## Credentials and Access
39-
Laravel Telescope access:
40-
- email `telescope_mail@mail.com`
41-
- password `654321`
42-
43-
Laravel Nova access:
44-
- email `nova_mail@mail.com`
45-
- password `654321`
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# My App
2+
3+
This project implements an API for the My App Web app.
4+
5+
## Project Resources & Contacts
6+
7+
This section provides quick links to various resources and contacts associated
8+
with this project. It's here to streamline your navigation and communication
9+
process, so you can efficiently find what you need or reach out to who you need.
10+
11+
### Resources
12+
13+
Below are links to tools and services used in this project:
14+
- [Issue Tracker](): Here, you can report any issues or bugs related to the project. (will be added later)
15+
- [Laravel Telescope](): This is debug assistant for the Laravel framework. (will be added later)
16+
- [Laravel Nova](): This is admin panel for the Laravel framework. (will be added later)
17+
- [API Documentation](https://mysite.com)
18+
19+
### Contacts
20+
21+
Should you need assistance or have questions, feel free to connect with the following individuals:
22+
- Manager: If you have any high-level project concerns, feel free to get in touch with our project manager. [Connect with Manager](mailto:manager@mail.com)
23+
- Code Owner/Team Lead: For specific questions about the codebase or technical aspects, reach out to our team lead. [Connect with Team Lead](mailto:test@example.com)
24+
25+
Please be mindful of each individual's preferred contact method and office hours.
26+
27+
## Environments
28+
29+
This repository by default supports three environments: `local`, `development`,
30+
and `testing`. Each environment is represented by an appropriate environment file:
31+
32+
| Environment | File | URL |
33+
| --- | --- |--------------------------------------|
34+
| local | .env | [http://localhost](http://localhost) |
35+
| testing | .env.testing | - |
36+
| development | .env.development | [https://mysite.com](https://mysite.com) |
37+
38+
## Credentials and Access
39+
Laravel Telescope access:
40+
- email `telescope_mail@mail.com`
41+
- password `654321`
42+
43+
Laravel Nova access:
44+
- email `nova_mail@mail.com`
45+
- password `654321`

0 commit comments

Comments
 (0)