Skip to content

Commit

Permalink
Ensure domain path in composer.json is restored to factory state.
Browse files Browse the repository at this point in the history
  • Loading branch information
JasperTey authored Sep 3, 2024
1 parent 48f9818 commit 35b701e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [main]
pull_request:
branches: [main, next]
branches: [main, next, develop]

jobs:
test:
Expand Down
7 changes: 2 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
3 changes: 3 additions & 0 deletions tests/.skeleton/bootstrap/providers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

return [];
7 changes: 7 additions & 0 deletions tests/Command/InstallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

use Illuminate\Support\Facades\Config;

beforeEach(function () {
$this->setupTestApplication();
});

it('publishes config', function () {
$path = config_path('ddd.php');

Expand Down Expand Up @@ -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'],
Expand Down
10 changes: 7 additions & 3 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -154,27 +153,32 @@ 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()
{
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: [
[['autoload', 'psr-4', $domainNamespace.'\\'], $domainPath],
],
);

if ($reload) {
$this->composerReload();
}

return $this;
}
}

0 comments on commit 35b701e

Please sign in to comment.