Skip to content

Commit 4951657

Browse files
committed
fix: test
refs: #26
1 parent 5c84bce commit 4951657

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
lines changed

tests/InitCommandTest.php

Lines changed: 19 additions & 24 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 testRunWithoutAdminAndReadmeCreationConvertAppNameToPascalCaseTelescopeAlreadyInstalled()
52+
public function testRunWithoutAdminAndReadmeCreation()
5753
{
5854
$this->mockFileGetContent(
5955
[
@@ -69,31 +65,30 @@ public function testRunWithoutAdminAndReadmeCreationConvertAppNameToPascalCaseTe
6965
$this->mockFilePutContent(
7066
'env.example_app_name_pascal_case.yml',
7167
'env.development_app_name_pascal_case.yml',
72-
);
73-
74-
$this->mockNativeFunction('RonasIT\ProjectInitializator\Commands',
75-
callChain: [
76-
$this->functionCall(
77-
name: 'class_exists',
78-
arguments: ['Laravel\Telescope\TelescopeServiceProvider', true],
79-
),
68+
[
69+
'renovate.json',
70+
$this->getFixture('renovate.json'),
71+
'optionalParameter',
72+
'optionalParameter',
8073
],
8174
);
8275

8376
$this->mockShellExec(
8477
['arguments' => 'composer require ronasit/laravel-helpers --ansi'],
8578
['arguments' => 'composer require ronasit/laravel-swagger --ansi'],
8679
['arguments' => 'composer require --dev ronasit/laravel-entity-generator --ansi'],
80+
['arguments' => 'composer require ronasit/laravel-telescope-extension --ansi'],
81+
['arguments' => 'php artisan telescope:install --ansi'],
8782
);
8883

8984
$this
90-
->artisan('init "My App"')
91-
->expectsConfirmation('The application name is not in PascalCase, would you like to use MyApp', 'yes')
85+
->artisan('init "MyApp"')
9286
->expectsOutput('Project initialized successfully!')
9387
->expectsQuestion('Please enter an application URL', 'https://mysite.com')
9488
->expectsConfirmation('Do you want to generate an admin user?')
9589
->expectsConfirmation('Do you want to generate a README file?')
96-
->expectsConfirmation('Would you use Renovate dependabot?')
90+
->expectsConfirmation('Would you use Renovate dependabot?', 'yes')
91+
->expectsQuestion('Please type username of the project reviewer', 'reviewer')
9792
->expectsConfirmation('Do you want to install media package?')
9893
->expectsConfirmation('Do you want to uninstall project-initializator package?')
9994
->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)