Skip to content

Commit

Permalink
More config/optimize fixes and config laravel 10 test clause
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspertey committed Nov 18, 2024
1 parent 2fcc296 commit 1dd94d9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
6 changes: 6 additions & 0 deletions src/Commands/ConfigCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ protected function layers()

protected function wizard(): int
{
if (! app('ddd')->laravelVersion(11)) {
$this->error('This command is only available in Laravel 11 and above.');

return self::FAILURE;
}

$namespaces = collect($this->composer->getPsr4Namespaces());

$layers = $namespaces->map(fn ($path, $namespace) => new Layer($namespace, $path));
Expand Down
15 changes: 14 additions & 1 deletion tests/Command/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
// ->give(fn() => $this->app->basePath('stubs'));

$this->originalComposerContents = file_get_contents(base_path('composer.json'));

// $this->artisan('clear-compiled')->assertSuccessful()->execute();
// $this->artisan('optimize:clear')->assertSuccessful()->execute();
});

afterEach(function () {
Expand All @@ -33,6 +36,8 @@
'Infrastructure' => 'src/Infrastructure',
]);

$this->reloadApplication();

$configPath = config_path('ddd.php');

$this->artisan('ddd:config')
Expand Down Expand Up @@ -61,7 +66,15 @@
$this->artisan('config:clear')->assertSuccessful()->execute();

unlink($configPath);
});
})->skipOnLaravelVersionsBelow(11);

it('requires laravel 11 to run the wizard', function () {
$this->artisan('ddd:config')
->expectsQuestion('Laravel-DDD Config Utility', 'wizard')
->expectsOutput('This command is only available in Laravel 11 and above.')
->assertFailure()
->execute();
})->onlyOnLaravelVersionsBelow(11);

it('can update and merge ddd.php with latest package version', function () {
$configPath = config_path('ddd.php');
Expand Down
8 changes: 4 additions & 4 deletions tests/Command/OptimizeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@

$this->originalComposerContents = file_get_contents(base_path('composer.json'));

$this->artisan('clear-compiled')->assertSuccessful()->execute();
$this->artisan('optimize:clear')->assertSuccessful()->execute();
// $this->artisan('clear-compiled')->assertSuccessful()->execute();
// $this->artisan('optimize:clear')->assertSuccessful()->execute();
});

afterEach(function () {
DomainCache::clear();

file_put_contents(base_path('composer.json'), $this->originalComposerContents);

$this->artisan('clear-compiled')->assertSuccessful()->execute();
$this->artisan('optimize:clear')->assertSuccessful()->execute();
// $this->artisan('clear-compiled')->assertSuccessful()->execute();
// $this->artisan('optimize:clear')->assertSuccessful()->execute();
});

it('can optimize discovered domain providers, commands, migrations', function () {
Expand Down
9 changes: 9 additions & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ function skipOnLaravelVersionsBelow($minimumVersion)
}
}

function onlyOnLaravelVersionsBelow($minimumVersion)
{
$version = app()->version();

if (! version_compare($version, $minimumVersion, '<')) {
test()->markTestSkipped("Does not apply to Laravel {$minimumVersion}+ (Current version: {$version}).");
}
}

function setConfigValues(array $values)
{
TestCase::configValues($values);
Expand Down
7 changes: 0 additions & 7 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,10 @@ protected function setUp(): void
});

parent::setUp();

// if (in_array(BootsTestApplication::class, class_uses_recursive($this))) {
// $this->composerReload();
// }
}

protected function tearDown(): void
{
$this->artisan('clear-compiled')->assertSuccessful()->execute();
$this->artisan('optimize:clear')->assertSuccessful()->execute();

$basePath = $this->getBasePath();

$this->cleanSlate();
Expand Down

0 comments on commit 1dd94d9

Please sign in to comment.