diff --git a/composer.json b/composer.json index 9294e4e..a857a5f 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "php": "^8.1.0", "guzzlehttp/guzzle": "^7.5.1", "laravel/framework": "^10.9.0", - "gehrisandro/tailwind-merge-php": "^v0.0.1" + "gehrisandro/tailwind-merge-php": "dev-add-caching" }, "require-dev": { "laravel/pint": "^1.10.2", diff --git a/src/TailwindMergeServiceProvider.php b/src/TailwindMergeServiceProvider.php index 817bb17..e8b3efe 100644 --- a/src/TailwindMergeServiceProvider.php +++ b/src/TailwindMergeServiceProvider.php @@ -16,6 +16,7 @@ public function register(): void { $this->app->singleton(TailwindMergeContract::class, static fn (): TailwindMerge => TailwindMerge::factory() ->withConfiguration(config('tailwind-merge', [])) + ->withCache(app('cache')->store()) // @phpstan-ignore-line ->make()); $this->app->alias(TailwindMergeContract::class, 'tailwind-merge'); diff --git a/tests/Arch.php b/tests/Arch.php index fd0aba6..0296238 100644 --- a/tests/Arch.php +++ b/tests/Arch.php @@ -18,6 +18,7 @@ 'TailwindMerge', // helpers... + 'app', 'config', 'config_path', 'resolve', diff --git a/tests/Feature/CacheTest.php b/tests/Feature/CacheTest.php new file mode 100644 index 0000000..05d6f08 --- /dev/null +++ b/tests/Feature/CacheTest.php @@ -0,0 +1,22 @@ +app->get(TailwindMerge::class); + + expect($twMerge->merge('h-4 h-6'))->toBe('h-6'); + + Event::assertDispatched(\Illuminate\Cache\Events\CacheMissed::class, 1); + Event::assertNotDispatched(\Illuminate\Cache\Events\CacheHit::class); + + expect($twMerge->merge('h-4 h-6'))->toBe('h-6'); + + Event::assertDispatched(\Illuminate\Cache\Events\CacheMissed::class, 1); + Event::assertDispatched(\Illuminate\Cache\Events\CacheHit::class, 2); +}); diff --git a/tests/Pest.php b/tests/Pest.php index 48c2b95..797de52 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -7,4 +7,4 @@ \Illuminate\Foundation\Testing\Concerns\InteractsWithViews::class, \Tests\TestCase::class, ) - ->in('Feature'); + ->in(__DIR__);