From aca1091a97605d1ea215bb0237c35701beacdefa Mon Sep 17 00:00:00 2001 From: Marco Rieser Date: Mon, 13 May 2024 13:02:31 +0200 Subject: [PATCH] Statamic v5 (#3) * Add support for Statamic v5 * Add basic test coverage --- .github/workflows/tests.yml | 35 +++++++++++++++++++++++++++++++++++ .gitignore | 1 + composer.json | 23 +++++++++++++++++++---- phpunit.xml | 21 +++++++++++++++++++++ tests/ModifierTest.php | 35 +++++++++++++++++++++++++++++++++++ tests/TestCase.php | 22 ++++++++++++++++++++++ 6 files changed, 133 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/tests.yml create mode 100644 phpunit.xml create mode 100644 tests/ModifierTest.php create mode 100644 tests/TestCase.php diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..f3b2846 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,35 @@ +name: Test Suite + +on: + push: + pull_request: + +jobs: + php_tests: + strategy: + matrix: + php: [8.2, 8.3] + laravel: [11.*] + os: [ubuntu-latest] + + name: ${{ matrix.php }} - ${{ matrix.laravel }} + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v1 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick + + - name: Install dependencies + run: | + composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update + composer install --no-interaction + + - name: Run PHPUnit + run: vendor/bin/phpunit diff --git a/.gitignore b/.gitignore index cacad21..c68951c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules vendor mix-manifest.json composer.lock +.phpunit.result.cache diff --git a/composer.json b/composer.json index 6adaa11..a3dc83c 100644 --- a/composer.json +++ b/composer.json @@ -6,6 +6,23 @@ "MarcoRieser\\TailwindMergeStatamic\\": "src" } }, + "autoload-dev": { + "psr-4": { + "MarcoRieser\\TailwindMergeStatamic\\Tests\\": "tests" + } + }, + "require": { + "gehrisandro/tailwind-merge-laravel": "^1.0.0", + "statamic/cms": "^4.0|^5.0" + }, + "require-dev": { + "orchestra/testbench": "^9.0" + }, + "config": { + "allow-plugins": { + "pixelfear/composer-dist-plugin": true + } + }, "extra": { "statamic": { "name": "Tailwind Merge Statamic", @@ -17,8 +34,6 @@ ] } }, - "require": { - "gehrisandro/tailwind-merge-laravel": "^1.0.0", - "statamic/cms": "^4.0" - } + "minimum-stability": "dev", + "prefer-stable": true } diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..ffc14b6 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,21 @@ + + + + + + ./tests + + + + + + + + + + + + + + + diff --git a/tests/ModifierTest.php b/tests/ModifierTest.php new file mode 100644 index 0000000..4bc292b --- /dev/null +++ b/tests/ModifierTest.php @@ -0,0 +1,35 @@ +assertSame( + 'h-10 rounded-full bg-blue-500 w-8', + (string)Statamic::modify("w-10 h-10 rounded-full bg-red-500 bg-blue-500 w-8")->twMerge() + ); + + $this->assertSame( + 'h-10 rounded-full bg-blue-500 w-8', + (string)Statamic::modify(['w-10 h-10 rounded-full bg-red-500', 'bg-blue-500 w-8'])->twMerge() + ); + + $this->assertSame( + 'h-10 rounded-full bg-blue-500 w-8', + (string)Statamic::modify(['w-10 h-10 rounded-full bg-red-500', ['bg-blue-500 w-8']])->twMerge() + ); + } + + public function test_that_modifier_works_with_params(): void + { + $this->assertSame( + 'h-10 rounded-full bg-blue-500 w-8', + (string)Statamic::modify("w-10 h-10 rounded-full bg-red-500")->context(['classes_to_merge' => 'bg-blue-500 w-8'])->twMerge('classes_to_merge') + ); + } + +} diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..3b889cf --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,22 @@ +