Skip to content

Commit

Permalink
Update cache tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspertey committed Oct 15, 2024
1 parent adb5d77 commit 02c75b0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
52 changes: 47 additions & 5 deletions tests/Command/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

use Illuminate\Support\Facades\Artisan;
use Lunarstorm\LaravelDDD\Support\DomainCache;
use Lunarstorm\LaravelDDD\Tests\Fixtures\Enums\Feature;

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

config(['cache.default' => 'file']);

DomainCache::clear();
Artisan::call('cache:clear');
Artisan::call('optimize:clear');
});

it('can cache discovered domain providers, commands, migrations', function () {
Expand Down Expand Up @@ -50,23 +56,59 @@
});

it('will not be cleared by laravel cache clearing', function () {
config(['cache.default' => 'file']);

expect(DomainCache::get('domain-providers'))->toBeNull();
expect(DomainCache::get('domain-commands'))->toBeNull();
expect(DomainCache::get('domain-migration-paths'))->toBeNull();

$this->artisan('ddd:cache')->execute();

expect(DomainCache::get('domain-providers'))->not->toBeNull();
expect(DomainCache::get('domain-commands'))->not->toBeNull();
expect(DomainCache::get('domain-migration-paths'))->not->toBeNull();

$this->artisan('cache:clear')->execute();

expect(DomainCache::get('domain-providers'))->not->toBeNull();
expect(DomainCache::get('domain-commands'))->not->toBeNull();
expect(DomainCache::get('domain-migration-paths'))->not->toBeNull();

$this->artisan('optimize:clear')->execute();
if (Feature::LaravelPackageOptimizeCommands->missing()) {
$this->artisan('optimize:clear')->execute();

expect(DomainCache::get('domain-providers'))->not->toBeNull();
expect(DomainCache::get('domain-commands'))->not->toBeNull();
expect(DomainCache::get('domain-providers'))->not->toBeNull();
expect(DomainCache::get('domain-commands'))->not->toBeNull();
expect(DomainCache::get('domain-migration-paths'))->not->toBeNull();
}
});

describe('laravel optimize', function () {
test('optimize will include ddd:cache', function () {
config(['cache.default' => 'file']);

expect(DomainCache::get('domain-providers'))->toBeNull();
expect(DomainCache::get('domain-commands'))->toBeNull();
expect(DomainCache::get('domain-migration-paths'))->toBeNull();

$this->artisan('optimize')->execute();

expect(DomainCache::get('domain-providers'))->not->toBeNull();
expect(DomainCache::get('domain-commands'))->not->toBeNull();
expect(DomainCache::get('domain-migration-paths'))->not->toBeNull();
});

test('optimize:clear will clear ddd cache', function () {
config(['cache.default' => 'file']);

$this->artisan('ddd:cache')->execute();

expect(DomainCache::get('domain-providers'))->not->toBeNull();
expect(DomainCache::get('domain-commands'))->not->toBeNull();
expect(DomainCache::get('domain-migration-paths'))->not->toBeNull();

$this->artisan('optimize:clear')->execute();

expect(DomainCache::get('domain-providers'))->toBeNull();
expect(DomainCache::get('domain-commands'))->toBeNull();
expect(DomainCache::get('domain-migration-paths'))->toBeNull();
});
})->skipOnLaravelVersionsBelow(Feature::LaravelPackageOptimizeCommands->value);
1 change: 1 addition & 0 deletions tests/Fixtures/Enums/Feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ enum Feature: string
case PromptForMissingInput = '9.49.0';
case IncludeFilepathInGeneratorCommandOutput = '9.32.0';
case LaravelPromptsPackage = '10.17';
case LaravelPackageOptimizeCommands = '11.27.1';

public function exists(): bool
{
Expand Down

0 comments on commit 02c75b0

Please sign in to comment.