Skip to content

Commit

Permalink
verify layer paths during autoload
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspertey committed Nov 17, 2024
1 parent b3f6577 commit e40ea3d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/Autoload/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Illuminate\Support\Facades\Artisan;
use Lunarstorm\LaravelDDD\Support\AutoloadManager;
use Lunarstorm\LaravelDDD\Support\DomainCache;
use Lunarstorm\LaravelDDD\Support\Path;
use Lunarstorm\LaravelDDD\Tests\BootsTestApplication;

uses(BootsTestApplication::class);
Expand Down Expand Up @@ -44,6 +45,12 @@
$mock = AutoloadManager::partialMock();
$mock->run();

expect($mock->getAllLayerPaths())->toEqualCanonicalizing([
Path::normalize(base_path('src/Domain')),
Path::normalize(base_path('src/Application')),
Path::normalize(base_path('src/Infrastructure')),
]);

$expected = array_values($this->commands);
$registered = array_values($mock->getRegisteredCommands());
expect($expected)->each(fn ($item) => $item->toBeIn($registered));
Expand All @@ -60,6 +67,12 @@
$mock = AutoloadManager::partialMock();
$mock->run();

expect($mock->getAllLayerPaths())->toEqualCanonicalizing([
Path::normalize(base_path('src/Domain')),
Path::normalize(base_path('src/Application')),
Path::normalize(base_path('src/Infrastructure')),
]);

$registered = array_values($mock->getRegisteredCommands());
expect($registered)->toHaveCount(0);
});
Expand All @@ -73,6 +86,12 @@
$mock = AutoloadManager::partialMock();
$mock->run();

expect($mock->getAllLayerPaths())->toEqualCanonicalizing([
Path::normalize(base_path('src/Domain')),
Path::normalize(base_path('src/Application')),
Path::normalize(base_path('src/Infrastructure')),
]);

$expected = array_values($this->commands);
$registered = array_values($mock->getRegisteredCommands());
expect($expected)->each(fn ($item) => $item->toBeIn($registered));
Expand Down
7 changes: 7 additions & 0 deletions tests/Autoload/IgnoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Support\Str;
use Lunarstorm\LaravelDDD\Facades\DDD;
use Lunarstorm\LaravelDDD\Support\DomainCache;
use Lunarstorm\LaravelDDD\Support\Path;
use Lunarstorm\LaravelDDD\Tests\BootsTestApplication;
use Symfony\Component\Finder\SplFileInfo;

Expand Down Expand Up @@ -35,6 +36,12 @@
'policies' => true,
'migrations' => true,
]);

expect(DDD::autoloader()->getAllLayerPaths())->toEqualCanonicalizing([
Path::normalize(base_path('src/Domain')),
Path::normalize(base_path('src/Application')),
Path::normalize(base_path('src/Infrastructure')),
]);
});

afterEach(function () {
Expand Down
31 changes: 31 additions & 0 deletions tests/Autoload/ProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Illuminate\Support\Facades\Artisan;
use Lunarstorm\LaravelDDD\Support\AutoloadManager;
use Lunarstorm\LaravelDDD\Support\DomainCache;
use Lunarstorm\LaravelDDD\Support\Path;
use Lunarstorm\LaravelDDD\Tests\BootsTestApplication;

uses(BootsTestApplication::class);
Expand Down Expand Up @@ -40,6 +41,12 @@
$mock = AutoloadManager::partialMock();
$mock->run();

expect($mock->getAllLayerPaths())->toEqualCanonicalizing([
Path::normalize(base_path('src/Domain')),
Path::normalize(base_path('src/Application')),
Path::normalize(base_path('src/Infrastructure')),
]);

expect($mock->getRegisteredProviders())->toBeEmpty();
});
});
Expand All @@ -51,6 +58,12 @@
$mock = AutoloadManager::partialMock();
$mock->shouldReceive('handleProviders')->once();
$mock->run();

expect($mock->getAllLayerPaths())->toEqualCanonicalizing([
Path::normalize(base_path('src/Domain')),
Path::normalize(base_path('src/Application')),
Path::normalize(base_path('src/Infrastructure')),
]);
});

it('registers the providers', function () {
Expand All @@ -59,6 +72,12 @@
$mock = AutoloadManager::partialMock();
$mock->run();

expect($mock->getAllLayerPaths())->toEqualCanonicalizing([
Path::normalize(base_path('src/Domain')),
Path::normalize(base_path('src/Application')),
Path::normalize(base_path('src/Infrastructure')),
]);

$expected = array_values($this->providers);
$registered = array_values($mock->getRegisteredProviders());
expect($expected)->each(fn ($item) => $item->toBeIn($registered));
Expand All @@ -75,6 +94,12 @@
$mock = AutoloadManager::partialMock();
$mock->run();

expect($mock->getAllLayerPaths())->toEqualCanonicalizing([
Path::normalize(base_path('src/Domain')),
Path::normalize(base_path('src/Application')),
Path::normalize(base_path('src/Infrastructure')),
]);

$registered = array_values($mock->getRegisteredProviders());
expect($registered)->toHaveCount(0);
});
Expand All @@ -88,6 +113,12 @@
$mock = AutoloadManager::partialMock();
$mock->run();

expect($mock->getAllLayerPaths())->toEqualCanonicalizing([
Path::normalize(base_path('src/Domain')),
Path::normalize(base_path('src/Application')),
Path::normalize(base_path('src/Infrastructure')),
]);

$expected = array_values($this->providers);
$registered = array_values($mock->getRegisteredProviders());
expect($expected)->each(fn ($item) => $item->toBeIn($registered));
Expand Down

0 comments on commit e40ea3d

Please sign in to comment.