From 35b701ed0cd4a18edf5b73812eca845fa2107e01 Mon Sep 17 00:00:00 2001 From: Jasper Tey Date: Mon, 2 Sep 2024 22:03:48 -0400 Subject: [PATCH] Ensure domain path in composer.json is restored to factory state. --- .github/workflows/run-tests.yml | 2 +- composer.json | 7 ++----- tests/.skeleton/bootstrap/providers.php | 3 +++ tests/Command/InstallTest.php | 7 +++++++ tests/TestCase.php | 10 +++++++--- 5 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 tests/.skeleton/bootstrap/providers.php diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index afe477a..5698f95 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -4,7 +4,7 @@ on: push: branches: [main] pull_request: - branches: [main, next] + branches: [main, next, develop] jobs: test: diff --git a/composer.json b/composer.json index 6e3da31..243d503 100644 --- a/composer.json +++ b/composer.json @@ -53,11 +53,8 @@ "scripts": { "post-autoload-dump": "@php ./vendor/bin/testbench package:discover --ansi", "analyse": "vendor/bin/phpstan analyse", - "test": [ - "@composer dump-autoload", - "vendor/bin/pest" - ], - "test-coverage": "vendor/bin/pest --coverage", + "test": "@composer dump-autoload && vendor/bin/pest", + "test-coverage": "@composer dump-autoload && vendor/bin/pest --coverage", "format": "vendor/bin/pint", "lint": "vendor/bin/pint" }, diff --git a/tests/.skeleton/bootstrap/providers.php b/tests/.skeleton/bootstrap/providers.php new file mode 100644 index 0000000..0b67a5f --- /dev/null +++ b/tests/.skeleton/bootstrap/providers.php @@ -0,0 +1,3 @@ +setupTestApplication(); +}); + it('publishes config', function () { $path = config_path('ddd.php'); @@ -47,6 +51,9 @@ expect($after)->toEqual(config('ddd.domain_path')); unlink(config_path('ddd.php')); + + // Reset composer back to the factory state + $this->setDomainPathInComposer('Domain', 'src/Domain', reload: true); })->with([ ['src/Domain', 'Domain'], ['src/Domains', 'Domains'], diff --git a/tests/TestCase.php b/tests/TestCase.php index 05348a2..fb69cab 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -7,7 +7,6 @@ use Illuminate\Support\Arr; use Illuminate\Support\Facades\File; use Lunarstorm\LaravelDDD\LaravelDDDServiceProvider; -use Lunarstorm\LaravelDDD\Support\DomainCache; use Orchestra\Testbench\TestCase as Orchestra; use Symfony\Component\Process\Process; @@ -154,7 +153,7 @@ protected function cleanSlate() File::deleteDirectory(base_path('src/Domains')); File::deleteDirectory(app_path('Models')); - DomainCache::clear(); + File::deleteDirectory(base_path('bootstrap/cache/ddd')); } protected function setupTestApplication() @@ -162,12 +161,13 @@ protected function setupTestApplication() File::copyDirectory(__DIR__.'/.skeleton/app', app_path()); File::copyDirectory(__DIR__.'/.skeleton/database', base_path('database')); File::copyDirectory(__DIR__.'/.skeleton/src/Domain', base_path('src/Domain')); + File::copy(__DIR__.'/.skeleton/bootstrap/providers.php', base_path('bootstrap/providers.php')); File::ensureDirectoryExists(app_path('Models')); $this->setDomainPathInComposer('Domain', 'src/Domain'); } - protected function setDomainPathInComposer($domainNamespace, $domainPath) + protected function setDomainPathInComposer($domainNamespace, $domainPath, bool $reload = true) { $this->updateComposer( set: [ @@ -175,6 +175,10 @@ protected function setDomainPathInComposer($domainNamespace, $domainPath) ], ); + if ($reload) { + $this->composerReload(); + } + return $this; } }