diff --git a/src/Commands/InitCommand.php b/src/Commands/InitCommand.php index 23cd2f5..9b0f5cc 100644 --- a/src/Commands/InitCommand.php +++ b/src/Commands/InitCommand.php @@ -7,7 +7,6 @@ use Illuminate\Contracts\View\View; use Illuminate\Support\Arr; use Illuminate\Support\Carbon; -use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Validator; use Illuminate\Support\Str; use RonasIT\ProjectInitializator\Enums\AuthTypeEnum; @@ -79,6 +78,12 @@ class InitCommand extends Command implements Isolatable protected string $appName; + protected string $dbConnection = 'pgsql'; + protected string $dbHost = 'pgsql'; + protected string $dbPort = '5432'; + protected string $dbName = 'postgres'; + protected string $dbUserName = 'postgres'; + protected AppTypeEnum $appType; public function handle(): void @@ -99,11 +104,11 @@ public function handle(): void $this->updateEnvFile($envFile, [ 'APP_NAME' => $this->appName, - 'DB_CONNECTION' => 'pgsql', - 'DB_HOST' => 'pgsql', - 'DB_PORT' => '5432', - 'DB_DATABASE' => 'postgres', - 'DB_USERNAME' => 'postgres', + 'DB_CONNECTION' => $this->dbConnection, + 'DB_HOST' => $this->dbHost, + 'DB_PORT' => $this->dbPort, + 'DB_DATABASE' => $this->dbName, + 'DB_USERNAME' => $this->dbUserName, 'DB_PASSWORD' => '', ]); @@ -118,7 +123,7 @@ public function handle(): void 'CACHE_STORE' => 'redis', 'QUEUE_CONNECTION' => 'redis', 'SESSION_DRIVER' => 'redis', - 'DB_CONNECTION' => 'pgsql', + 'DB_CONNECTION' => $this->dbConnection, ]); $this->info('Project initialized successfully!'); @@ -241,11 +246,11 @@ public function handle(): void $this->publishWebLogin(); - Artisan::call('migrate'); - if ($this->shouldUninstallPackage) { - shell_exec('composer remove --dev ronasit/laravel-project-initializator --no-script --ansi'); + shell_exec('composer remove --dev ronasit/laravel-project-initializator --ansi'); } + + $this->runMigrations(); } protected function setupComposerHooks(): void @@ -286,6 +291,23 @@ protected function setAutoDocContactEmail(string $email): void $config->write(); } + protected function runMigrations(): void + { + config([ + 'database.default' => $this->dbConnection, + 'database.connections.pgsql' => [ + 'driver' => $this->dbConnection, + 'host' => $this->dbHost, + 'port' => $this->dbPort, + 'database' => $this->dbName, + 'username' => $this->dbUserName, + 'password' => '', + ], + ]); + + shell_exec('php artisan migrate --ansi'); + } + protected function createAdminUser(string $kebabName): void { $defaultPassword = substr(md5(uniqid()), 0, 8); @@ -604,10 +626,7 @@ protected function enableClerk(): void protected function publishWebLogin(): void { - Artisan::call('vendor:publish', [ - '--tag' => 'initializator-web-login', - '--force' => true, - ]); + shell_exec('php artisan vendor:publish --tag=initializator-web-login --force'); file_put_contents(base_path('routes/web.php'), "\nAuth::routes();\n", FILE_APPEND); } diff --git a/tests/InitCommandTest.php b/tests/InitCommandTest.php index 77c8152..cf85abd 100644 --- a/tests/InitCommandTest.php +++ b/tests/InitCommandTest.php @@ -2,7 +2,6 @@ namespace RonasIT\ProjectInitializator\Tests; -use Illuminate\Support\Facades\File; use RonasIT\ProjectInitializator\Tests\Support\Traits\InitCommandMockTrait; class InitCommandTest extends TestCase @@ -42,6 +41,8 @@ public function testRunWithoutAdminAndReadmeCreationConvertAppNameToPascalCaseTe $this->callShellExec('composer require --dev brainmaestro/composer-git-hooks --ansi'), $this->callShellExec('./vendor/bin/cghooks update --ansi'), $this->callShellExec('php artisan lang:publish --ansi'), + $this->callShellExec('php artisan vendor:publish --tag=initializator-web-login --force'), + $this->callShellExec('php artisan migrate --ansi'), ); $this @@ -58,8 +59,6 @@ public function testRunWithoutAdminAndReadmeCreationConvertAppNameToPascalCaseTe ->expectsConfirmation('Do you want to install media package?') ->expectsConfirmation('Do you want to uninstall project-initializator package?') ->assertExitCode(0); - - $this->assertWebLoginPublished(); } public function testRunWithoutAdminAndReadmeCreation() @@ -94,6 +93,8 @@ public function testRunWithoutAdminAndReadmeCreation() $this->callShellExec('php artisan lang:publish --ansi'), $this->callShellExec('composer require ronasit/laravel-telescope-extension --ansi'), $this->callShellExec('php artisan telescope:install --ansi'), + $this->callShellExec('php artisan vendor:publish --tag=initializator-web-login --force'), + $this->callShellExec('php artisan migrate --ansi'), ); $this @@ -110,8 +111,6 @@ public function testRunWithoutAdminAndReadmeCreation() ->expectsConfirmation('Do you want to install media package?') ->expectsConfirmation('Do you want to uninstall project-initializator package?') ->assertExitCode(0); - - $this->assertWebLoginPublished(); } public function testRunWithAdminAndWithoutReadmeCreation() @@ -146,6 +145,8 @@ public function testRunWithAdminAndWithoutReadmeCreation() $this->callShellExec('php artisan lang:publish --ansi'), $this->callShellExec('composer require ronasit/laravel-telescope-extension --ansi'), $this->callShellExec('php artisan telescope:install --ansi'), + $this->callShellExec('php artisan vendor:publish --tag=initializator-web-login --force'), + $this->callShellExec('php artisan migrate --ansi'), ); $this @@ -166,8 +167,6 @@ public function testRunWithAdminAndWithoutReadmeCreation() ->expectsConfirmation('Do you want to install media package?') ->expectsConfirmation('Do you want to uninstall project-initializator package?') ->assertExitCode(0); - - $this->assertWebLoginPublished(); } public function testRunWithAdminAndDefaultReadmeCreation() @@ -222,6 +221,8 @@ public function testRunWithAdminAndDefaultReadmeCreation() $this->callShellExec('php artisan laravel-clerk:install --ansi'), $this->callShellExec('composer require ronasit/laravel-telescope-extension --ansi'), $this->callShellExec('php artisan telescope:install --ansi'), + $this->callShellExec('php artisan vendor:publish --tag=initializator-web-login --force'), + $this->callShellExec('php artisan migrate --ansi'), ); $this @@ -292,8 +293,6 @@ public function testRunWithAdminAndDefaultReadmeCreation() ->expectsConfirmation('Do you want to install media package?') ->expectsConfirmation('Do you want to uninstall project-initializator package?') ->assertExitCode(0); - - $this->assertWebLoginPublished(); } public function testRunWithAdminAndPartialReadmeCreation() @@ -334,6 +333,8 @@ public function testRunWithAdminAndPartialReadmeCreation() $this->callShellExec('php artisan lang:publish --ansi'), $this->callShellExec('composer require ronasit/laravel-telescope-extension --ansi'), $this->callShellExec('php artisan telescope:install --ansi'), + $this->callShellExec('php artisan vendor:publish --tag=initializator-web-login --force'), + $this->callShellExec('php artisan migrate --ansi'), ); $this @@ -394,8 +395,6 @@ public function testRunWithAdminAndPartialReadmeCreation() ->expectsConfirmation('Do you want to install media package?') ->expectsConfirmation('Do you want to uninstall project-initializator package?') ->assertExitCode(0); - - $this->assertWebLoginPublished(); } public function testRunWithAdminAndFullReadmeCreationAndRemovingInitializatorInstallationMedia() @@ -444,7 +443,9 @@ public function testRunWithAdminAndFullReadmeCreationAndRemovingInitializatorIns $this->callShellExec('composer require ronasit/laravel-telescope-extension --ansi'), $this->callShellExec('php artisan telescope:install --ansi'), $this->callShellExec('composer require ronasit/laravel-media --ansi'), - $this->callShellExec('composer remove --dev ronasit/laravel-project-initializator --no-script --ansi'), + $this->callShellExec('php artisan vendor:publish --tag=initializator-web-login --force'), + $this->callShellExec('composer remove --dev ronasit/laravel-project-initializator --ansi'), + $this->callShellExec('php artisan migrate --ansi'), ); $this @@ -512,8 +513,6 @@ public function testRunWithAdminAndFullReadmeCreationAndRemovingInitializatorIns ->expectsConfirmation('Do you want to install media package?', 'yes') ->expectsConfirmation('Do you want to uninstall project-initializator package?', 'yes') ->assertExitCode(0); - - $this->assertWebLoginPublished(); } public function testRunWithoutAdminAndUsingTelescope() @@ -554,6 +553,8 @@ public function testRunWithoutAdminAndUsingTelescope() $this->callShellExec('php artisan lang:publish --ansi'), $this->callShellExec('composer require ronasit/laravel-telescope-extension --ansi'), $this->callShellExec('php artisan telescope:install --ansi'), + $this->callShellExec('php artisan vendor:publish --tag=initializator-web-login --force'), + $this->callShellExec('php artisan migrate --ansi'), ); $this @@ -618,8 +619,6 @@ public function testRunWithoutAdminAndUsingTelescope() ->expectsConfirmation('Do you want to install media package?') ->expectsConfirmation('Do you want to uninstall project-initializator package?') ->assertExitCode(0); - - $this->assertWebLoginPublished(); } public function testRunWithClerkMobileAppWithPintInstalled(): void @@ -674,6 +673,8 @@ public function testRunWithClerkMobileAppWithPintInstalled(): void $this->callShellExec('php artisan laravel-clerk:install --ansi'), $this->callShellExec('composer require ronasit/laravel-telescope-extension --ansi'), $this->callShellExec('php artisan telescope:install --ansi'), + $this->callShellExec('php artisan vendor:publish --tag=initializator-web-login --force'), + $this->callShellExec('php artisan migrate --ansi'), ); $this @@ -744,21 +745,5 @@ public function testRunWithClerkMobileAppWithPintInstalled(): void ->expectsConfirmation('Do you want to install media package?') ->expectsConfirmation('Do you want to uninstall project-initializator package?') ->assertExitCode(0); - - $this->assertWebLoginPublished(); - } - - protected function assertWebLoginPublished(): void - { - $this->assertFileEqualsFixture('login_controller.php', app_path('Http/Controllers/Auth/LoginController.php')); - $this->assertFileEqualsFixture('app.css', public_path('app.css')); - $this->assertFileEqualsFixture('app.js', public_path('app.js')); - $this->assertFileEqualsFixture('app.blade.php', resource_path('views/layouts/app.blade.php')); - $this->assertFileEqualsFixture('login.blade.php', resource_path('views/auth/login.blade.php')); - - File::deleteDirectory(app_path()); - File::deleteDirectory(public_path()); - File::deleteDirectory(resource_path('views/layouts')); - File::deleteDirectory(resource_path('views/auth')); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 59b8b4a..6e2889b 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -31,26 +31,6 @@ protected function getPackageProviders($app): array ]; } - protected function assertFileEqualsFixture(string $fixture, string $fileName, bool $exportMode = false): void - { - $this->assertFileExists($fileName); - - $data = File::get($fileName); - - if ($this->globalExportMode || $exportMode) { - $this->exportContent($data, $fixture); - } - - $fixturePath = $this->prepareFixtureName($this->getFixturePath($fixture)); - $assertFailedMessage = "Failed asserting that the provided file {$fileName} equal to fixture: {$fixturePath}"; - - $this->assertEquals( - expected: $this->getFixture($fixture), - actual: $data, - message: $assertFailedMessage, - ); - } - protected function getReadmeTemplateContent(string $templateName): string { return file_get_contents(base_path("/resources/md/readme/{$templateName}"));