From aa77134405dabc75693f6a1a53e744159a0f3dc6 Mon Sep 17 00:00:00 2001 From: Chris Powell Date: Tue, 6 Aug 2024 12:32:15 +0100 Subject: [PATCH 1/3] Allow merge method to accept null and return empty string. --- src/TailwindRuntime.php | 2 +- tests/Fixtures/filters/tailwind_merge.test | 1 + tests/FunctionalTest.php | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/TailwindRuntime.php b/src/TailwindRuntime.php index 4b7c6aa..7cc89f6 100644 --- a/src/TailwindRuntime.php +++ b/src/TailwindRuntime.php @@ -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) diff --git a/tests/Fixtures/filters/tailwind_merge.test b/tests/Fixtures/filters/tailwind_merge.test index 0ab093f..143e493 100644 --- a/tests/Fixtures/filters/tailwind_merge.test +++ b/tests/Fixtures/filters/tailwind_merge.test @@ -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'], diff --git a/tests/FunctionalTest.php b/tests/FunctionalTest.php index 9af7a97..a14eb4e 100644 --- a/tests/FunctionalTest.php +++ b/tests/FunctionalTest.php @@ -31,4 +31,12 @@ 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() + { + $runtime = new TailwindRuntime(); + + $this->assertSame('',$runtime->merge(null)); + } } From b6ecca17c82919b4bb310ad3b0ae537c3867645b Mon Sep 17 00:00:00 2001 From: Chris Powell Date: Tue, 6 Aug 2024 12:46:39 +0100 Subject: [PATCH 2/3] Add space. --- tests/FunctionalTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/FunctionalTest.php b/tests/FunctionalTest.php index a14eb4e..8d8eb0c 100644 --- a/tests/FunctionalTest.php +++ b/tests/FunctionalTest.php @@ -37,6 +37,6 @@ public function testItWillReturnEmptyStringIfSuppliedNull() { $runtime = new TailwindRuntime(); - $this->assertSame('',$runtime->merge(null)); + $this->assertSame('', $runtime->merge(null)); } } From f8173fa2e319a94812a5151d4468a09138360065 Mon Sep 17 00:00:00 2001 From: Chris Powell Date: Tue, 6 Aug 2024 12:48:01 +0100 Subject: [PATCH 3/3] Add void return type --- tests/FunctionalTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/FunctionalTest.php b/tests/FunctionalTest.php index 8d8eb0c..2d81ea0 100644 --- a/tests/FunctionalTest.php +++ b/tests/FunctionalTest.php @@ -32,8 +32,7 @@ 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() + public function testItWillReturnEmptyStringIfSuppliedNull(): void { $runtime = new TailwindRuntime();