Skip to content

Commit

Permalink
Statamic v5 (#3)
Browse files Browse the repository at this point in the history
* Add support for Statamic v5
* Add basic test coverage
  • Loading branch information
marcorieser authored May 13, 2024
1 parent 95ca2f0 commit aca1091
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 4 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
vendor
mix-manifest.json
composer.lock
.phpunit.result.cache
23 changes: 19 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -17,8 +34,6 @@
]
}
},
"require": {
"gehrisandro/tailwind-merge-laravel": "^1.0.0",
"statamic/cms": "^4.0"
}
"minimum-stability": "dev",
"prefer-stable": true
}
21 changes: 21 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" beStrictAboutTestsThatDoNotTestAnything="false">
<coverage/>
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
<env name="APP_KEY" value="base64:ybcI9MKuhLnESRSuWDfnJQuohOXMBaynfbTC5Y5i1FE="/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="array"/>
<!-- <env name="DB_CONNECTION" value="sqlite"/> -->
<!-- <env name="DB_DATABASE" value=":memory:"/> -->
<env name="MAIL_MAILER" value="array"/>
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="TELESCOPE_ENABLED" value="false"/>
</php>
</phpunit>
35 changes: 35 additions & 0 deletions tests/ModifierTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace MarcoRieser\TailwindMergeStatamic\Tests;

use Statamic\Statamic;

class ModifierTest extends TestCase
{
public function test_that_modifier_works_without_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 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')
);
}

}
22 changes: 22 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace MarcoRieser\TailwindMergeStatamic\Tests;

use MarcoRieser\TailwindMergeStatamic\ServiceProvider;
use Statamic\Providers\StatamicServiceProvider;
use Statamic\Testing\AddonTestCase;
use TailwindMerge\Laravel\TailwindMergeServiceProvider;

abstract class TestCase extends AddonTestCase
{
protected string $addonServiceProvider = ServiceProvider::class;

protected function getPackageProviders($app)
{
$serviceProviders = parent::getPackageProviders($app);

$serviceProviders[] = TailwindMergeServiceProvider::class;

return $serviceProviders;
}
}

0 comments on commit aca1091

Please sign in to comment.