Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 33 additions & 14 deletions src/Commands/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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' => '',
]);

Expand All @@ -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!');
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
49 changes: 17 additions & 32 deletions tests/InitCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace RonasIT\ProjectInitializator\Tests;

use Illuminate\Support\Facades\File;
use RonasIT\ProjectInitializator\Tests\Support\Traits\InitCommandMockTrait;

class InitCommandTest extends TestCase
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'));
}
}
20 changes: 0 additions & 20 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}"));
Expand Down