Skip to content

Commit aca1091

Browse files
authored
Statamic v5 (#3)
* Add support for Statamic v5 * Add basic test coverage
1 parent 95ca2f0 commit aca1091

File tree

6 files changed

+133
-4
lines changed

6 files changed

+133
-4
lines changed

.github/workflows/tests.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Test Suite
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
php_tests:
9+
strategy:
10+
matrix:
11+
php: [8.2, 8.3]
12+
laravel: [11.*]
13+
os: [ubuntu-latest]
14+
15+
name: ${{ matrix.php }} - ${{ matrix.laravel }}
16+
17+
runs-on: ${{ matrix.os }}
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v1
22+
23+
- name: Setup PHP
24+
uses: shivammathur/setup-php@v2
25+
with:
26+
php-version: ${{ matrix.php }}
27+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
28+
29+
- name: Install dependencies
30+
run: |
31+
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
32+
composer install --no-interaction
33+
34+
- name: Run PHPUnit
35+
run: vendor/bin/phpunit

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules
22
vendor
33
mix-manifest.json
44
composer.lock
5+
.phpunit.result.cache

composer.json

+19-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@
66
"MarcoRieser\\TailwindMergeStatamic\\": "src"
77
}
88
},
9+
"autoload-dev": {
10+
"psr-4": {
11+
"MarcoRieser\\TailwindMergeStatamic\\Tests\\": "tests"
12+
}
13+
},
14+
"require": {
15+
"gehrisandro/tailwind-merge-laravel": "^1.0.0",
16+
"statamic/cms": "^4.0|^5.0"
17+
},
18+
"require-dev": {
19+
"orchestra/testbench": "^9.0"
20+
},
21+
"config": {
22+
"allow-plugins": {
23+
"pixelfear/composer-dist-plugin": true
24+
}
25+
},
926
"extra": {
1027
"statamic": {
1128
"name": "Tailwind Merge Statamic",
@@ -17,8 +34,6 @@
1734
]
1835
}
1936
},
20-
"require": {
21-
"gehrisandro/tailwind-merge-laravel": "^1.0.0",
22-
"statamic/cms": "^4.0"
23-
}
37+
"minimum-stability": "dev",
38+
"prefer-stable": true
2439
}

phpunit.xml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<coverage/>
4+
<testsuites>
5+
<testsuite name="Test Suite">
6+
<directory suffix="Test.php">./tests</directory>
7+
</testsuite>
8+
</testsuites>
9+
<php>
10+
<env name="APP_ENV" value="testing"/>
11+
<env name="APP_KEY" value="base64:ybcI9MKuhLnESRSuWDfnJQuohOXMBaynfbTC5Y5i1FE="/>
12+
<env name="BCRYPT_ROUNDS" value="4"/>
13+
<env name="CACHE_DRIVER" value="array"/>
14+
<!-- <env name="DB_CONNECTION" value="sqlite"/> -->
15+
<!-- <env name="DB_DATABASE" value=":memory:"/> -->
16+
<env name="MAIL_MAILER" value="array"/>
17+
<env name="QUEUE_CONNECTION" value="sync"/>
18+
<env name="SESSION_DRIVER" value="array"/>
19+
<env name="TELESCOPE_ENABLED" value="false"/>
20+
</php>
21+
</phpunit>

tests/ModifierTest.php

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace MarcoRieser\TailwindMergeStatamic\Tests;
4+
5+
use Statamic\Statamic;
6+
7+
class ModifierTest extends TestCase
8+
{
9+
public function test_that_modifier_works_without_params(): void
10+
{
11+
$this->assertSame(
12+
'h-10 rounded-full bg-blue-500 w-8',
13+
(string)Statamic::modify("w-10 h-10 rounded-full bg-red-500 bg-blue-500 w-8")->twMerge()
14+
);
15+
16+
$this->assertSame(
17+
'h-10 rounded-full bg-blue-500 w-8',
18+
(string)Statamic::modify(['w-10 h-10 rounded-full bg-red-500', 'bg-blue-500 w-8'])->twMerge()
19+
);
20+
21+
$this->assertSame(
22+
'h-10 rounded-full bg-blue-500 w-8',
23+
(string)Statamic::modify(['w-10 h-10 rounded-full bg-red-500', ['bg-blue-500 w-8']])->twMerge()
24+
);
25+
}
26+
27+
public function test_that_modifier_works_with_params(): void
28+
{
29+
$this->assertSame(
30+
'h-10 rounded-full bg-blue-500 w-8',
31+
(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')
32+
);
33+
}
34+
35+
}

tests/TestCase.php

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace MarcoRieser\TailwindMergeStatamic\Tests;
4+
5+
use MarcoRieser\TailwindMergeStatamic\ServiceProvider;
6+
use Statamic\Providers\StatamicServiceProvider;
7+
use Statamic\Testing\AddonTestCase;
8+
use TailwindMerge\Laravel\TailwindMergeServiceProvider;
9+
10+
abstract class TestCase extends AddonTestCase
11+
{
12+
protected string $addonServiceProvider = ServiceProvider::class;
13+
14+
protected function getPackageProviders($app)
15+
{
16+
$serviceProviders = parent::getPackageProviders($app);
17+
18+
$serviceProviders[] = TailwindMergeServiceProvider::class;
19+
20+
return $serviceProviders;
21+
}
22+
}

0 commit comments

Comments
 (0)