Skip to content

Commit d7549b4

Browse files
authored
Merge branch 'main' into 38_change_telescope_middleware
2 parents 3f552e4 + eec24b3 commit d7549b4

File tree

3 files changed

+50
-66
lines changed

3 files changed

+50
-66
lines changed

src/Commands/InitCommand.php

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Illuminate\Contracts\View\View;
88
use Illuminate\Support\Arr;
99
use Illuminate\Support\Carbon;
10-
use Illuminate\Support\Facades\Artisan;
1110
use Illuminate\Support\Facades\Validator;
1211
use Illuminate\Support\Str;
1312
use RonasIT\ProjectInitializator\Enums\AppTypeEnum;
@@ -79,6 +78,12 @@ class InitCommand extends Command implements Isolatable
7978

8079
protected string $appName;
8180

81+
protected string $dbConnection = 'pgsql';
82+
protected string $dbHost = 'pgsql';
83+
protected string $dbPort = '5432';
84+
protected string $dbName = 'postgres';
85+
protected string $dbUserName = 'postgres';
86+
8287
protected AppTypeEnum $appType;
8388

8489
public function handle(): void
@@ -99,11 +104,11 @@ public function handle(): void
99104

100105
$this->updateEnvFile($envFile, [
101106
'APP_NAME' => $this->appName,
102-
'DB_CONNECTION' => 'pgsql',
103-
'DB_HOST' => 'pgsql',
104-
'DB_PORT' => '5432',
105-
'DB_DATABASE' => 'postgres',
106-
'DB_USERNAME' => 'postgres',
107+
'DB_CONNECTION' => $this->dbConnection,
108+
'DB_HOST' => $this->dbHost,
109+
'DB_PORT' => $this->dbPort,
110+
'DB_DATABASE' => $this->dbName,
111+
'DB_USERNAME' => $this->dbUserName,
107112
'DB_PASSWORD' => '',
108113
]);
109114

@@ -118,7 +123,7 @@ public function handle(): void
118123
'CACHE_STORE' => 'redis',
119124
'QUEUE_CONNECTION' => 'redis',
120125
'SESSION_DRIVER' => 'redis',
121-
'DB_CONNECTION' => 'pgsql',
126+
'DB_CONNECTION' => $this->dbConnection,
122127
]);
123128

124129
$this->info('Project initialized successfully!');
@@ -243,11 +248,11 @@ public function handle(): void
243248

244249
$this->publishWebLogin();
245250

246-
Artisan::call('migrate');
247-
248251
if ($this->shouldUninstallPackage) {
249-
shell_exec('composer remove --dev ronasit/laravel-project-initializator --no-script --ansi');
252+
shell_exec('composer remove --dev ronasit/laravel-project-initializator --ansi');
250253
}
254+
255+
$this->runMigrations();
251256
}
252257

253258
protected function setupComposerHooks(): void
@@ -288,6 +293,23 @@ protected function setAutoDocContactEmail(string $email): void
288293
$config->write();
289294
}
290295

296+
protected function runMigrations(): void
297+
{
298+
config([
299+
'database.default' => $this->dbConnection,
300+
'database.connections.pgsql' => [
301+
'driver' => $this->dbConnection,
302+
'host' => $this->dbHost,
303+
'port' => $this->dbPort,
304+
'database' => $this->dbName,
305+
'username' => $this->dbUserName,
306+
'password' => '',
307+
],
308+
]);
309+
310+
shell_exec('php artisan migrate --ansi');
311+
}
312+
291313
protected function createAdminUser(string $kebabName): void
292314
{
293315
$defaultPassword = substr(md5(uniqid()), 0, 8);
@@ -606,10 +628,7 @@ protected function enableClerk(): void
606628

607629
protected function publishWebLogin(): void
608630
{
609-
Artisan::call('vendor:publish', [
610-
'--tag' => 'initializator-web-login',
611-
'--force' => true,
612-
]);
631+
shell_exec('php artisan vendor:publish --tag=initializator-web-login --force');
613632

614633
file_put_contents(base_path('routes/web.php'), "\nAuth::routes();\n", FILE_APPEND);
615634
}

tests/InitCommandTest.php

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace RonasIT\ProjectInitializator\Tests;
44

5-
use Illuminate\Support\Facades\File;
65
use RonasIT\ProjectInitializator\Tests\Support\Traits\InitCommandMockTrait;
76

87
class InitCommandTest extends TestCase
@@ -51,6 +50,8 @@ public function testRunWithoutAdminAndReadmeCreationConvertAppNameToPascalCaseTe
5150
$this->callShellExec('composer require --dev brainmaestro/composer-git-hooks --ansi'),
5251
$this->callShellExec('./vendor/bin/cghooks update --ansi'),
5352
$this->callShellExec('php artisan lang:publish --ansi'),
53+
$this->callShellExec('php artisan vendor:publish --tag=initializator-web-login --force'),
54+
$this->callShellExec('php artisan migrate --ansi'),
5455
);
5556

5657
$this
@@ -67,8 +68,6 @@ public function testRunWithoutAdminAndReadmeCreationConvertAppNameToPascalCaseTe
6768
->expectsConfirmation('Do you want to install media package?')
6869
->expectsConfirmation('Do you want to uninstall project-initializator package?')
6970
->assertExitCode(0);
70-
71-
$this->assertWebLoginPublished();
7271
}
7372

7473
public function testRunWithoutAdminAndReadmeCreation()
@@ -112,6 +111,8 @@ public function testRunWithoutAdminAndReadmeCreation()
112111
$this->callShellExec('php artisan lang:publish --ansi'),
113112
$this->callShellExec('composer require ronasit/laravel-telescope-extension --ansi'),
114113
$this->callShellExec('php artisan telescope:install --ansi'),
114+
$this->callShellExec('php artisan vendor:publish --tag=initializator-web-login --force'),
115+
$this->callShellExec('php artisan migrate --ansi'),
115116
);
116117

117118
$this
@@ -128,8 +129,6 @@ public function testRunWithoutAdminAndReadmeCreation()
128129
->expectsConfirmation('Do you want to install media package?')
129130
->expectsConfirmation('Do you want to uninstall project-initializator package?')
130131
->assertExitCode(0);
131-
132-
$this->assertWebLoginPublished();
133132
}
134133

135134
public function testRunWithAdminAndWithoutReadmeCreation()
@@ -173,6 +172,8 @@ public function testRunWithAdminAndWithoutReadmeCreation()
173172
$this->callShellExec('php artisan lang:publish --ansi'),
174173
$this->callShellExec('composer require ronasit/laravel-telescope-extension --ansi'),
175174
$this->callShellExec('php artisan telescope:install --ansi'),
175+
$this->callShellExec('php artisan vendor:publish --tag=initializator-web-login --force'),
176+
$this->callShellExec('php artisan migrate --ansi'),
176177
);
177178

178179
$this
@@ -193,8 +194,6 @@ public function testRunWithAdminAndWithoutReadmeCreation()
193194
->expectsConfirmation('Do you want to install media package?')
194195
->expectsConfirmation('Do you want to uninstall project-initializator package?')
195196
->assertExitCode(0);
196-
197-
$this->assertWebLoginPublished();
198197
}
199198

200199
public function testRunWithAdminAndDefaultReadmeCreation()
@@ -258,6 +257,8 @@ public function testRunWithAdminAndDefaultReadmeCreation()
258257
$this->callShellExec('php artisan laravel-clerk:install --ansi'),
259258
$this->callShellExec('composer require ronasit/laravel-telescope-extension --ansi'),
260259
$this->callShellExec('php artisan telescope:install --ansi'),
260+
$this->callShellExec('php artisan vendor:publish --tag=initializator-web-login --force'),
261+
$this->callShellExec('php artisan migrate --ansi'),
261262
);
262263

263264
$this
@@ -328,8 +329,6 @@ public function testRunWithAdminAndDefaultReadmeCreation()
328329
->expectsConfirmation('Do you want to install media package?')
329330
->expectsConfirmation('Do you want to uninstall project-initializator package?')
330331
->assertExitCode(0);
331-
332-
$this->assertWebLoginPublished();
333332
}
334333

335334
public function testRunWithAdminAndPartialReadmeCreation()
@@ -379,6 +378,8 @@ public function testRunWithAdminAndPartialReadmeCreation()
379378
$this->callShellExec('php artisan lang:publish --ansi'),
380379
$this->callShellExec('composer require ronasit/laravel-telescope-extension --ansi'),
381380
$this->callShellExec('php artisan telescope:install --ansi'),
381+
$this->callShellExec('php artisan vendor:publish --tag=initializator-web-login --force'),
382+
$this->callShellExec('php artisan migrate --ansi'),
382383
);
383384

384385
$this
@@ -439,8 +440,6 @@ public function testRunWithAdminAndPartialReadmeCreation()
439440
->expectsConfirmation('Do you want to install media package?')
440441
->expectsConfirmation('Do you want to uninstall project-initializator package?')
441442
->assertExitCode(0);
442-
443-
$this->assertWebLoginPublished();
444443
}
445444

446445
public function testRunWithAdminAndFullReadmeCreationAndRemovingInitializatorInstallationMedia()
@@ -498,7 +497,9 @@ public function testRunWithAdminAndFullReadmeCreationAndRemovingInitializatorIns
498497
$this->callShellExec('composer require ronasit/laravel-telescope-extension --ansi'),
499498
$this->callShellExec('php artisan telescope:install --ansi'),
500499
$this->callShellExec('composer require ronasit/laravel-media --ansi'),
501-
$this->callShellExec('composer remove --dev ronasit/laravel-project-initializator --no-script --ansi'),
500+
$this->callShellExec('php artisan vendor:publish --tag=initializator-web-login --force'),
501+
$this->callShellExec('composer remove --dev ronasit/laravel-project-initializator --ansi'),
502+
$this->callShellExec('php artisan migrate --ansi'),
502503
);
503504

504505
$this
@@ -566,8 +567,6 @@ public function testRunWithAdminAndFullReadmeCreationAndRemovingInitializatorIns
566567
->expectsConfirmation('Do you want to install media package?', 'yes')
567568
->expectsConfirmation('Do you want to uninstall project-initializator package?', 'yes')
568569
->assertExitCode(0);
569-
570-
$this->assertWebLoginPublished();
571570
}
572571

573572
public function testRunWithoutAdminAndUsingTelescope()
@@ -617,6 +616,8 @@ public function testRunWithoutAdminAndUsingTelescope()
617616
$this->callShellExec('php artisan lang:publish --ansi'),
618617
$this->callShellExec('composer require ronasit/laravel-telescope-extension --ansi'),
619618
$this->callShellExec('php artisan telescope:install --ansi'),
619+
$this->callShellExec('php artisan vendor:publish --tag=initializator-web-login --force'),
620+
$this->callShellExec('php artisan migrate --ansi'),
620621
);
621622

622623
$this
@@ -681,8 +682,6 @@ public function testRunWithoutAdminAndUsingTelescope()
681682
->expectsConfirmation('Do you want to install media package?')
682683
->expectsConfirmation('Do you want to uninstall project-initializator package?')
683684
->assertExitCode(0);
684-
685-
$this->assertWebLoginPublished();
686685
}
687686

688687
public function testRunWithClerkMobileAppWithPintInstalled(): void
@@ -746,6 +745,8 @@ public function testRunWithClerkMobileAppWithPintInstalled(): void
746745
$this->callShellExec('php artisan laravel-clerk:install --ansi'),
747746
$this->callShellExec('composer require ronasit/laravel-telescope-extension --ansi'),
748747
$this->callShellExec('php artisan telescope:install --ansi'),
748+
$this->callShellExec('php artisan vendor:publish --tag=initializator-web-login --force'),
749+
$this->callShellExec('php artisan migrate --ansi'),
749750
);
750751

751752
$this
@@ -816,21 +817,5 @@ public function testRunWithClerkMobileAppWithPintInstalled(): void
816817
->expectsConfirmation('Do you want to install media package?')
817818
->expectsConfirmation('Do you want to uninstall project-initializator package?')
818819
->assertExitCode(0);
819-
820-
$this->assertWebLoginPublished();
821-
}
822-
823-
protected function assertWebLoginPublished(): void
824-
{
825-
$this->assertFileEqualsFixture('login_controller.php', app_path('Http/Controllers/Auth/LoginController.php'));
826-
$this->assertFileEqualsFixture('app.css', public_path('app.css'));
827-
$this->assertFileEqualsFixture('app.js', public_path('app.js'));
828-
$this->assertFileEqualsFixture('app.blade.php', resource_path('views/layouts/app.blade.php'));
829-
$this->assertFileEqualsFixture('login.blade.php', resource_path('views/auth/login.blade.php'));
830-
831-
File::deleteDirectory(app_path());
832-
File::deleteDirectory(public_path());
833-
File::deleteDirectory(resource_path('views/layouts'));
834-
File::deleteDirectory(resource_path('views/auth'));
835820
}
836821
}

tests/TestCase.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,6 @@ protected function getPackageProviders($app): array
3131
];
3232
}
3333

34-
protected function assertFileEqualsFixture(string $fixture, string $fileName, bool $exportMode = false): void
35-
{
36-
$this->assertFileExists($fileName);
37-
38-
$data = File::get($fileName);
39-
40-
if ($this->globalExportMode || $exportMode) {
41-
$this->exportContent($data, $fixture);
42-
}
43-
44-
$fixturePath = $this->prepareFixtureName($this->getFixturePath($fixture));
45-
$assertFailedMessage = "Failed asserting that the provided file {$fileName} equal to fixture: {$fixturePath}";
46-
47-
$this->assertEquals(
48-
expected: $this->getFixture($fixture),
49-
actual: $data,
50-
message: $assertFailedMessage,
51-
);
52-
}
53-
5434
protected function getReadmeTemplateContent(string $templateName): string
5535
{
5636
return file_get_contents(base_path("/resources/md/readme/{$templateName}"));

0 commit comments

Comments
 (0)