Skip to content

Commit ef22ad9

Browse files
authored
Merge pull request #27 from RonasIT/26_install_telescope_if_not_exists
feat: install telescope if not exists
2 parents 360d14f + 4ed62ec commit ef22ad9

File tree

3 files changed

+37
-18
lines changed

3 files changed

+37
-18
lines changed

src/Commands/InitCommand.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ class InitCommand extends Command implements Isolatable
6060
'composer require ronasit/laravel-helpers',
6161
'composer require ronasit/laravel-swagger',
6262
'composer require --dev ronasit/laravel-entity-generator',
63-
'composer require ronasit/laravel-telescope-extension',
64-
'php artisan telescope:install',
6563
];
6664

6765
protected string $appName;
@@ -141,6 +139,14 @@ public function handle(): void
141139
}
142140
}
143141

142+
if (!class_exists(\Laravel\Telescope\TelescopeServiceProvider::class)) {
143+
array_push(
144+
$this->shellCommands,
145+
'composer require ronasit/laravel-telescope-extension',
146+
'php artisan telescope:install',
147+
);
148+
}
149+
144150
if ($this->confirm('Do you want to install media package?')) {
145151
$this->shellCommands[] = 'composer require ronasit/laravel-media';
146152
}

tests/InitCommandTest.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class InitCommandTest extends TestCase
88
{
99
use InitCommandMockTrait;
1010

11-
public function testRunWithoutAdminAndReadmeCreation()
11+
public function testRunWithoutAdminAndReadmeCreationConvertAppNameToPascalCaseTelescopeAlreadyInstalled()
1212
{
1313
$this->mockFileGetContent(
1414
[
@@ -24,36 +24,32 @@ public function testRunWithoutAdminAndReadmeCreation()
2424
$this->mockFilePutContent(
2525
'env.example_app_name_pascal_case.yml',
2626
'env.development_app_name_pascal_case.yml',
27-
[
28-
'renovate.json',
29-
$this->getFixture('renovate.json'),
30-
'optionalParameter',
31-
'optionalParameter',
32-
],
3327
);
3428

29+
$this->mockClassExists([
30+
'arguments' => ['Laravel\Telescope\TelescopeServiceProvider', true],
31+
]);
32+
3533
$this->mockShellExec(
3634
['arguments' => 'composer require ronasit/laravel-helpers --ansi'],
3735
['arguments' => 'composer require ronasit/laravel-swagger --ansi'],
3836
['arguments' => 'composer require --dev ronasit/laravel-entity-generator --ansi'],
39-
['arguments' => 'composer require ronasit/laravel-telescope-extension --ansi'],
40-
['arguments' => 'php artisan telescope:install --ansi'],
4137
);
4238

4339
$this
44-
->artisan('init "MyApp"')
40+
->artisan('init "My App"')
41+
->expectsConfirmation('The application name is not in PascalCase, would you like to use MyApp', 'yes')
4542
->expectsOutput('Project initialized successfully!')
4643
->expectsQuestion('Please enter an application URL', 'https://mysite.com')
4744
->expectsConfirmation('Do you want to generate an admin user?')
4845
->expectsConfirmation('Do you want to generate a README file?')
49-
->expectsConfirmation('Would you use Renovate dependabot?', 'yes')
50-
->expectsQuestion('Please type username of the project reviewer', 'reviewer')
46+
->expectsConfirmation('Would you use Renovate dependabot?')
5147
->expectsConfirmation('Do you want to install media package?')
5248
->expectsConfirmation('Do you want to uninstall project-initializator package?')
5349
->assertExitCode(0);
5450
}
5551

56-
public function testRunWithoutAdminAndReadmeCreationConvertAppNameToPascalCase()
52+
public function testRunWithoutAdminAndReadmeCreation()
5753
{
5854
$this->mockFileGetContent(
5955
[
@@ -69,6 +65,12 @@ public function testRunWithoutAdminAndReadmeCreationConvertAppNameToPascalCase()
6965
$this->mockFilePutContent(
7066
'env.example_app_name_pascal_case.yml',
7167
'env.development_app_name_pascal_case.yml',
68+
[
69+
'renovate.json',
70+
$this->getFixture('renovate.json'),
71+
'optionalParameter',
72+
'optionalParameter',
73+
],
7274
);
7375

7476
$this->mockShellExec(
@@ -80,13 +82,13 @@ public function testRunWithoutAdminAndReadmeCreationConvertAppNameToPascalCase()
8082
);
8183

8284
$this
83-
->artisan('init "My App"')
84-
->expectsConfirmation('The application name is not in PascalCase, would you like to use MyApp', 'yes')
85+
->artisan('init "MyApp"')
8586
->expectsOutput('Project initialized successfully!')
8687
->expectsQuestion('Please enter an application URL', 'https://mysite.com')
8788
->expectsConfirmation('Do you want to generate an admin user?')
8889
->expectsConfirmation('Do you want to generate a README file?')
89-
->expectsConfirmation('Would you use Renovate dependabot?')
90+
->expectsConfirmation('Would you use Renovate dependabot?', 'yes')
91+
->expectsQuestion('Please type username of the project reviewer', 'reviewer')
9092
->expectsConfirmation('Do you want to install media package?')
9193
->expectsConfirmation('Do you want to uninstall project-initializator package?')
9294
->assertExitCode(0);

tests/Support/Traits/InitCommandMockTrait.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ public function mockFileGetContent(array ...$rawCallChain): void
5757
);
5858
}
5959

60+
protected function mockClassExists(array ...$rawCallChain): void
61+
{
62+
$callChain = array_map(fn ($call) => $this->functionCall(
63+
name: 'class_exists',
64+
arguments: Arr::wrap($call['arguments']),
65+
result: Arr::get($call, 'result', true),
66+
), $rawCallChain);
67+
68+
$this->mockNativeFunction('RonasIT\ProjectInitializator\Commands', $callChain);
69+
}
70+
6071
protected function getTemplate(string $template): string
6172
{
6273
return file_get_contents(dirname(__DIR__, 3) . "/resources/md/readme/{$template}");

0 commit comments

Comments
 (0)