Skip to content

Commit eb56f2e

Browse files
authored
Merge pull request #71 from RonasIT/use-library-arrayfile
refactor: replace custom ArrayFile with laravel-config-writer version
2 parents 568a896 + 1e6feda commit eb56f2e

File tree

5 files changed

+30
-173
lines changed

5 files changed

+30
-173
lines changed

src/Commands/InitCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use RonasIT\ProjectInitializator\Enums\AppTypeEnum;
1313
use RonasIT\ProjectInitializator\Enums\AuthTypeEnum;
1414
use RonasIT\ProjectInitializator\Enums\RoleEnum;
15-
use RonasIT\ProjectInitializator\Extensions\ConfigWriter\ArrayFile;
15+
use Winter\LaravelConfigWriter\ArrayFile;
1616
use Winter\LaravelConfigWriter\EnvFile;
1717

1818
class InitCommand extends Command implements Isolatable

src/Extensions/ConfigWriter/ArrayFile.php

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/Extensions/ConfigWriter/ArrayPrinter.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

tests/InitCommandTest.php

Lines changed: 18 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,12 @@ class InitCommandTest extends TestCase
1010

1111
public function testRunWithoutAdminAndReadmeCreationConvertAppNameToPascalCaseTelescopeAlreadyInstalled()
1212
{
13-
$this->mockNativeFunction(
14-
'\RonasIT\ProjectInitializator\Extensions\ConfigWriter',
15-
$this->callFileExists(base_path('config/telescope.php')),
16-
$this->callFileGetContent(base_path('config/telescope.php'), $this->getFixture('telescope_config.php')),
17-
$this->callFileExists(base_path('config/auto-doc.php')),
18-
$this->callFileGetContent(base_path('config/auto-doc.php'), $this->getFixture('auto_doc.php')),
19-
);
20-
2113
$this->mockNativeFunction(
2214
'\Winter\LaravelConfigWriter',
2315
$this->changeEnvFileCall('.env.example', 'env.example.yml', 'env.example_app_name_pascal_case.yml'),
2416
$this->changeEnvFileCall('.env.development', 'env.development.yml', 'env.development_app_name_pascal_case.yml'),
25-
$this->callFilePutContent(base_path('config/telescope.php'), $this->getFixture('telescope_config_after_initialization.php')),
26-
$this->callFilePutContent(base_path('config/auto-doc.php'), $this->getFixture('auto_doc_after_changes.php')),
17+
$this->changeConfigFileCall('config/telescope.php', 'telescope_config.php', 'telescope_config_after_initialization.php'),
18+
$this->changeConfigFileCall('config/auto-doc.php', 'auto_doc.php', 'auto_doc_after_changes.php'),
2719
);
2820

2921
$this->mockNativeFunction(
@@ -72,20 +64,12 @@ public function testRunWithoutAdminAndReadmeCreationConvertAppNameToPascalCaseTe
7264

7365
public function testRunWithoutAdminAndReadmeCreation()
7466
{
75-
$this->mockNativeFunction(
76-
'\RonasIT\ProjectInitializator\Extensions\ConfigWriter',
77-
$this->callFileExists(base_path('config/telescope.php')),
78-
$this->callFileGetContent(base_path('config/telescope.php'), $this->getFixture('telescope_config.php')),
79-
$this->callFileExists(base_path('config/auto-doc.php')),
80-
$this->callFileGetContent(base_path('config/auto-doc.php'), $this->getFixture('auto_doc.php')),
81-
);
82-
8367
$this->mockNativeFunction(
8468
'\Winter\LaravelConfigWriter',
8569
$this->changeEnvFileCall('.env', 'env.example.yml', 'env.example_app_name_pascal_case.yml'),
8670
$this->changeEnvFileCall('.env.development', 'env.development.yml', 'env.development_app_name_pascal_case.yml'),
87-
$this->callFilePutContent(base_path('config/telescope.php'), $this->getFixture('telescope_config_after_initialization.php')),
88-
$this->callFilePutContent(base_path('config/auto-doc.php'), $this->getFixture('auto_doc_after_changes.php')),
71+
$this->changeConfigFileCall('config/telescope.php', 'telescope_config.php', 'telescope_config_after_initialization.php'),
72+
$this->changeConfigFileCall('config/auto-doc.php', 'auto_doc.php', 'auto_doc_after_changes.php'),
8973
);
9074

9175
$this->mockNativeFunction(
@@ -133,20 +117,12 @@ public function testRunWithoutAdminAndReadmeCreation()
133117

134118
public function testRunWithAdminAndWithoutReadmeCreation()
135119
{
136-
$this->mockNativeFunction(
137-
'\RonasIT\ProjectInitializator\Extensions\ConfigWriter',
138-
$this->callFileExists(base_path('config/telescope.php')),
139-
$this->callFileGetContent(base_path('config/telescope.php'), $this->getFixture('telescope_config.php')),
140-
$this->callFileExists(base_path('config/auto-doc.php')),
141-
$this->callFileGetContent(base_path('config/auto-doc.php'), $this->getFixture('auto_doc.php')),
142-
);
143-
144120
$this->mockNativeFunction(
145121
'\Winter\LaravelConfigWriter',
146122
$this->changeEnvFileCall('.env.example', 'env.example.yml', 'env.example_app_name_not_pascal_case.yml'),
147123
$this->changeEnvFileCall('.env.development', 'env.development.yml', 'env.development_app_name_not_pascal_case.yml'),
148-
$this->callFilePutContent(base_path('config/telescope.php'), $this->getFixture('telescope_config_after_initialization.php')),
149-
$this->callFilePutContent(base_path('config/auto-doc.php'), $this->getFixture('auto_doc_after_changes.php')),
124+
$this->changeConfigFileCall('config/telescope.php', 'telescope_config.php', 'telescope_config_after_initialization.php'),
125+
$this->changeConfigFileCall('config/auto-doc.php', 'auto_doc.php', 'auto_doc_after_changes.php'),
150126
);
151127

152128
$this->mockNativeFunction(
@@ -198,22 +174,14 @@ public function testRunWithAdminAndWithoutReadmeCreation()
198174

199175
public function testRunWithAdminAndDefaultReadmeCreation()
200176
{
201-
$this->mockNativeFunction(
202-
'\RonasIT\ProjectInitializator\Extensions\ConfigWriter',
203-
$this->callFileExists(base_path('config/telescope.php')),
204-
$this->callFileGetContent(base_path('config/telescope.php'), $this->getFixture('telescope_config.php')),
205-
$this->callFileExists(base_path('config/auto-doc.php')),
206-
$this->callFileGetContent(base_path('config/auto-doc.php'), $this->getFixture('auto_doc.php')),
207-
);
208-
209177
$this->mockNativeFunction(
210178
'\Winter\LaravelConfigWriter',
211179
$this->changeEnvFileCall('.env.example', 'env.example.yml', 'env.example_app_name_not_pascal_case.yml'),
212180
$this->changeEnvFileCall('.env.development', 'env.development.yml', 'env.development_app_name_not_pascal_case.yml'),
213181
$this->changeEnvFileCall('.env.development', 'env.development_app_name_not_pascal_case.yml', 'env.development_clerk_credentials_added.yml'),
214182
$this->changeEnvFileCall('.env.example', 'env.example_app_name_not_pascal_case.yml', 'env.example_clerk_credentials_added.yml'),
215-
$this->callFilePutContent(base_path('config/telescope.php'), $this->getFixture('telescope_config_after_initialization.php')),
216-
$this->callFilePutContent(base_path('config/auto-doc.php'), $this->getFixture('auto_doc_after_changes.php')),
183+
$this->changeConfigFileCall('config/telescope.php', 'telescope_config.php', 'telescope_config_after_initialization.php'),
184+
$this->changeConfigFileCall('config/auto-doc.php', 'auto_doc.php', 'auto_doc_after_changes.php'),
217185
);
218186

219187
$this->mockNativeFunction(
@@ -338,20 +306,12 @@ public function testRunWithAdminAndDefaultReadmeCreation()
338306

339307
public function testRunWithAdminAndPartialReadmeCreation()
340308
{
341-
$this->mockNativeFunction(
342-
'\RonasIT\ProjectInitializator\Extensions\ConfigWriter',
343-
$this->callFileExists(base_path('config/telescope.php')),
344-
$this->callFileGetContent(base_path('config/telescope.php'), $this->getFixture('telescope_config.php')),
345-
$this->callFileExists(base_path('config/auto-doc.php')),
346-
$this->callFileGetContent(base_path('config/auto-doc.php'), $this->getFixture('auto_doc.php')),
347-
);
348-
349309
$this->mockNativeFunction(
350310
'\Winter\LaravelConfigWriter',
351311
$this->changeEnvFileCall('.env.example', 'env.example.yml', 'env.example_app_name_not_pascal_case.yml'),
352312
$this->changeEnvFileCall('.env.development', 'env.development.yml', 'env.development_app_name_not_pascal_case.yml'),
353-
$this->callFilePutContent(base_path('config/telescope.php'), $this->getFixture('telescope_config_after_initialization.php')),
354-
$this->callFilePutContent(base_path('config/auto-doc.php'), $this->getFixture('auto_doc_after_changes.php')),
313+
$this->changeConfigFileCall('config/telescope.php', 'telescope_config.php', 'telescope_config_after_initialization.php'),
314+
$this->changeConfigFileCall('config/auto-doc.php', 'auto_doc.php', 'auto_doc_after_changes.php'),
355315
);
356316

357317
$this->mockNativeFunction(
@@ -449,20 +409,12 @@ public function testRunWithAdminAndPartialReadmeCreation()
449409

450410
public function testRunWithAdminAndFullReadmeCreationAndRemovingInitializatorInstallationMedia()
451411
{
452-
$this->mockNativeFunction(
453-
'\RonasIT\ProjectInitializator\Extensions\ConfigWriter',
454-
$this->callFileExists(base_path('config/telescope.php')),
455-
$this->callFileGetContent(base_path('config/telescope.php'), $this->getFixture('telescope_config.php')),
456-
$this->callFileExists(base_path('config/auto-doc.php')),
457-
$this->callFileGetContent(base_path('config/auto-doc.php'), $this->getFixture('auto_doc.php')),
458-
);
459-
460412
$this->mockNativeFunction(
461413
'\Winter\LaravelConfigWriter',
462414
$this->changeEnvFileCall('.env.example', 'env.example.yml', 'env.example_app_name_not_pascal_case.yml'),
463415
$this->changeEnvFileCall('.env.development', 'env.development.yml', 'env.development_app_name_not_pascal_case.yml'),
464-
$this->callFilePutContent(base_path('config/telescope.php'), $this->getFixture('telescope_config_after_initialization.php')),
465-
$this->callFilePutContent(base_path('config/auto-doc.php'), $this->getFixture('auto_doc_after_changes.php')),
416+
$this->changeConfigFileCall('config/telescope.php', 'telescope_config.php', 'telescope_config_after_initialization.php'),
417+
$this->changeConfigFileCall('config/auto-doc.php', 'auto_doc.php', 'auto_doc_after_changes.php'),
466418
);
467419

468420
$this->mockNativeFunction(
@@ -579,20 +531,12 @@ public function testRunWithAdminAndFullReadmeCreationAndRemovingInitializatorIns
579531

580532
public function testRunWithoutAdminAndUsingTelescope()
581533
{
582-
$this->mockNativeFunction(
583-
'\RonasIT\ProjectInitializator\Extensions\ConfigWriter',
584-
$this->callFileExists(base_path('config/telescope.php')),
585-
$this->callFileGetContent(base_path('config/telescope.php'), $this->getFixture('telescope_config.php')),
586-
$this->callFileExists(base_path('config/auto-doc.php')),
587-
$this->callFileGetContent(base_path('config/auto-doc.php'), $this->getFixture('auto_doc.php')),
588-
);
589-
590534
$this->mockNativeFunction(
591535
'\Winter\LaravelConfigWriter',
592536
$this->changeEnvFileCall('.env.example', 'env.example.yml', 'env.example_app_name_not_pascal_case.yml'),
593537
$this->changeEnvFileCall('.env.development', 'env.development.yml', 'env.development_app_name_not_pascal_case.yml'),
594-
$this->callFilePutContent(base_path('config/telescope.php'), $this->getFixture('telescope_config_after_initialization.php')),
595-
$this->callFilePutContent(base_path('config/auto-doc.php'), $this->getFixture('auto_doc_after_changes.php')),
538+
$this->changeConfigFileCall('config/telescope.php', 'telescope_config.php', 'telescope_config_after_initialization.php'),
539+
$this->changeConfigFileCall('config/auto-doc.php', 'auto_doc.php', 'auto_doc_after_changes.php'),
596540
);
597541

598542
$this->mockNativeFunction(
@@ -700,22 +644,14 @@ public function testRunWithoutAdminAndUsingTelescope()
700644

701645
public function testRunWithClerkMobileAppWithPintInstalled(): void
702646
{
703-
$this->mockNativeFunction(
704-
'\RonasIT\ProjectInitializator\Extensions\ConfigWriter',
705-
$this->callFileExists(base_path('config/telescope.php')),
706-
$this->callFileGetContent(base_path('config/telescope.php'), $this->getFixture('telescope_config.php')),
707-
$this->callFileExists(base_path('config/auto-doc.php')),
708-
$this->callFileGetContent(base_path('config/auto-doc.php'), $this->getFixture('auto_doc.php')),
709-
);
710-
711647
$this->mockNativeFunction(
712648
'\Winter\LaravelConfigWriter',
713649
$this->changeEnvFileCall('.env.example', 'env.example.yml', 'env.example_app_name_not_pascal_case.yml'),
714650
$this->changeEnvFileCall('.env.development', 'env.development.yml', 'env.development_app_name_not_pascal_case.yml'),
715651
$this->changeEnvFileCall('.env.development', 'env.development_app_name_not_pascal_case.yml', 'env.development_clerk_credentials_added_mobile_app.yml'),
716652
$this->changeEnvFileCall('.env.example', 'env.example_app_name_not_pascal_case.yml', 'env.example_clerk_credentials_added_mobile_app.yml'),
717-
$this->callFilePutContent(base_path('config/telescope.php'), $this->getFixture('telescope_config_after_initialization.php')),
718-
$this->callFilePutContent(base_path('config/auto-doc.php'), $this->getFixture('auto_doc_after_changes.php')),
653+
$this->changeConfigFileCall('config/telescope.php', 'telescope_config.php', 'telescope_config_after_initialization.php'),
654+
$this->changeConfigFileCall('config/auto-doc.php', 'auto_doc.php', 'auto_doc_after_changes.php'),
719655
);
720656

721657
$this->mockNativeFunction(
@@ -836,22 +772,14 @@ public function testRunWithClerkMobileAppWithPintInstalled(): void
836772

837773
public function testRunWithClerkAdditionalAdminsWithoutDefaultAdmin(): void
838774
{
839-
$this->mockNativeFunction(
840-
'\RonasIT\ProjectInitializator\Extensions\ConfigWriter',
841-
$this->callFileExists(base_path('config/telescope.php')),
842-
$this->callFileGetContent(base_path('config/telescope.php'), $this->getFixture('telescope_config.php')),
843-
$this->callFileExists(base_path('config/auto-doc.php')),
844-
$this->callFileGetContent(base_path('config/auto-doc.php'), $this->getFixture('auto_doc.php')),
845-
);
846-
847775
$this->mockNativeFunction(
848776
'\Winter\LaravelConfigWriter',
849777
$this->changeEnvFileCall('.env.example', 'env.example.yml', 'env.example_app_name_not_pascal_case.yml'),
850778
$this->changeEnvFileCall('.env.development', 'env.development.yml', 'env.development_app_name_not_pascal_case.yml'),
851779
$this->changeEnvFileCall('.env.development', 'env.development_app_name_not_pascal_case.yml', 'env.development_clerk_credentials_added.yml'),
852780
$this->changeEnvFileCall('.env.example', 'env.example.yml', 'env.example_clerk_credentials_added.yml'),
853-
$this->callFilePutContent(base_path('config/telescope.php'), $this->getFixture('telescope_config_after_initialization.php')),
854-
$this->callFilePutContent(base_path('config/auto-doc.php'), $this->getFixture('auto_doc_after_changes.php')),
781+
$this->changeConfigFileCall('config/telescope.php', 'telescope_config.php', 'telescope_config_after_initialization.php'),
782+
$this->changeConfigFileCall('config/auto-doc.php', 'auto_doc.php', 'auto_doc_after_changes.php'),
855783
);
856784

857785
$this->mockNativeFunction(

tests/Support/Traits/InitCommandMockTrait.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ protected function callShellExec(string $command, string $result = 'success'): a
3838
return $this->functionCall('shell_exec', [$command], $result);
3939
}
4040

41+
protected function callGlob(string $pattern, array $result): array
42+
{
43+
return $this->functionCall('glob', [$pattern], $result);
44+
}
45+
4146
protected function changeEnvFileCall(string $fileName, string $sourceFixture, string $resultFixture): array
4247
{
4348
return [
@@ -47,8 +52,12 @@ protected function changeEnvFileCall(string $fileName, string $sourceFixture, st
4752
];
4853
}
4954

50-
protected function callGlob(string $pattern, array $result): array
55+
protected function changeConfigFileCall(string $fileName, string $sourceFixture, string $resultFixture): array
5156
{
52-
return $this->functionCall('glob', [$pattern], $result);
57+
return [
58+
$this->callFileExists(base_path($fileName)),
59+
$this->callFileGetContent(base_path($fileName), $this->getFixture($sourceFixture)),
60+
$this->callFilePutContent(base_path($fileName), $this->getFixture($resultFixture)),
61+
];
5362
}
5463
}

0 commit comments

Comments
 (0)