Skip to content

Commit

Permalink
Add cache support
Browse files Browse the repository at this point in the history
  • Loading branch information
gehrisandro committed Sep 12, 2023
1 parent 2d6d974 commit d9062b9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/TailwindMergeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
1 change: 1 addition & 0 deletions tests/Arch.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'TailwindMerge',

// helpers...
'app',
'config',
'config_path',
'resolve',
Expand Down
22 changes: 22 additions & 0 deletions tests/Feature/CacheTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

use Illuminate\Support\Facades\Event;
use TailwindMerge\TailwindMerge;

it('uses caching', function () {
Event::fake();

$twMerge = $this->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);
});
2 changes: 1 addition & 1 deletion tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
\Illuminate\Foundation\Testing\Concerns\InteractsWithViews::class,
\Tests\TestCase::class,
)
->in('Feature');
->in(__DIR__);

0 comments on commit d9062b9

Please sign in to comment.