Skip to content

Commit

Permalink
Merge pull request #12 from ampedweb/main
Browse files Browse the repository at this point in the history
Allow merge method to accept null as argument to prevent exception
  • Loading branch information
ker0x authored Aug 7, 2024
2 parents 21eded1 + f8173fa commit a3cb864
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/TailwindRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(?CacheInterface $cache = null)
$this->factory = TailwindMerge::factory()->withCache(new Psr16Cache($cache));
}

public function merge(string|array $classes, array $configuration = []): string
public function merge(string|array|null $classes, array $configuration = []): string
{
return $this->factory
->withConfiguration($configuration)
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/filters/tailwind_merge.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{{ "block inline"|tailwind_merge }}
{{ classes|tailwind_merge }}
{{ "tw-text-red-500 tw-text-blue-500"|tailwind_merge({prefix: 'tw-'}) }}
{{ null|tailwind_merge }}
--DATA--
return [
'classes' => ['h-10', 'h-20'],
Expand Down
7 changes: 7 additions & 0 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,11 @@ public function testItCanMergeWithConfiguration(): void

$this->assertSame('tw-text-blue-500', $runtime->merge(['tw-text-red-500', 'tw-text-blue-500'], ['prefix' => 'tw-']));
}

public function testItWillReturnEmptyStringIfSuppliedNull(): void
{
$runtime = new TailwindRuntime();

$this->assertSame('', $runtime->merge(null));
}
}

0 comments on commit a3cb864

Please sign in to comment.