From 1dd94d9bc901e4132a7ca559152f39cb13ff22e2 Mon Sep 17 00:00:00 2001 From: Jasper Tey Date: Sun, 17 Nov 2024 19:14:23 -0500 Subject: [PATCH] More config/optimize fixes and config laravel 10 test clause --- src/Commands/ConfigCommand.php | 6 ++++++ tests/Command/ConfigTest.php | 15 ++++++++++++++- tests/Command/OptimizeTest.php | 8 ++++---- tests/Pest.php | 9 +++++++++ tests/TestCase.php | 7 ------- 5 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/Commands/ConfigCommand.php b/src/Commands/ConfigCommand.php index 581389c..046b91f 100644 --- a/src/Commands/ConfigCommand.php +++ b/src/Commands/ConfigCommand.php @@ -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)); diff --git a/tests/Command/ConfigTest.php b/tests/Command/ConfigTest.php index 7bef034..ae99a42 100644 --- a/tests/Command/ConfigTest.php +++ b/tests/Command/ConfigTest.php @@ -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 () { @@ -33,6 +36,8 @@ 'Infrastructure' => 'src/Infrastructure', ]); + $this->reloadApplication(); + $configPath = config_path('ddd.php'); $this->artisan('ddd:config') @@ -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'); diff --git a/tests/Command/OptimizeTest.php b/tests/Command/OptimizeTest.php index 6391e95..c8a0d4d 100644 --- a/tests/Command/OptimizeTest.php +++ b/tests/Command/OptimizeTest.php @@ -13,8 +13,8 @@ $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 () { @@ -22,8 +22,8 @@ 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 () { diff --git a/tests/Pest.php b/tests/Pest.php index d31d21e..da75808 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -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); diff --git a/tests/TestCase.php b/tests/TestCase.php index 54f6f89..c86b26d 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -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();