From c9c19194056c6d509b3bc751f003784d78bdce6c Mon Sep 17 00:00:00 2001 From: Marty Friedel <1491079+martyf@users.noreply.github.com> Date: Fri, 10 May 2024 07:42:26 +0930 Subject: [PATCH] Support for Statamic v5 --- README.md | 2 +- composer.json | 2 +- src/Fieldtypes/VariableNumberFieldtype.php | 3 +- tests/TestCase.php | 56 ++++++++++------------ 4 files changed, 30 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 1d8c5ed..cfc58df 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ -![Statamic 4+](https://img.shields.io/badge/Statamic-4.0-FF269E?style=for-the-badge&link=https://statamic.com) +![Statamic 5](https://img.shields.io/badge/Statamic-5.0-FF269E?style=for-the-badge&link=https://statamic.com) [![Variable Number Fieldtype for Statamic on Packagist](https://img.shields.io/packagist/v/mitydigital/statamic-variable-number-fieldtype?style=for-the-badge)](https://packagist.org/packages/mitydigital/statamic-variable-number-fieldtype/stats) --- diff --git a/composer.json b/composer.json index 19c7751..e19a932 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ }, "require": { "php": "^8.2", - "statamic/cms": "^4.25.0", + "statamic/cms": "^5.0", "ext-intl": "*" }, "require-dev": { diff --git a/src/Fieldtypes/VariableNumberFieldtype.php b/src/Fieldtypes/VariableNumberFieldtype.php index 4696f6c..29b25a9 100644 --- a/src/Fieldtypes/VariableNumberFieldtype.php +++ b/src/Fieldtypes/VariableNumberFieldtype.php @@ -3,6 +3,7 @@ namespace MityDigital\StatamicVariableNumberFieldtype\Fieldtypes; use Illuminate\Support\Facades\URL; +use Illuminate\Support\Str; use MityDigital\StatamicVariableNumberFieldtype\Facades\VariableNumber; use Statamic\Facades\Folder; use Statamic\Fields\Fieldtype; @@ -337,7 +338,7 @@ protected function configFieldItems(): array 'options' => collect(Folder::disk('resources') ->getFilesRecursively('views')) - ->map(fn ($view) => str_replace_first('views/', '', str_before($view, '.'))) + ->map(fn ($view) => Str::replaceFirst('views/', '', Str::before($view, '.'))) ->filter(fn ($view) => ( $view && ! str_starts_with($view, 'vendor/') && diff --git a/tests/TestCase.php b/tests/TestCase.php index ce4cd0f..0635f13 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -5,18 +5,19 @@ use Facades\Statamic\Version; use Illuminate\Support\Facades\File; use MityDigital\StatamicVariableNumberFieldtype\ServiceProvider; -use Orchestra\Testbench\TestCase as OrchestraTestCase; use Statamic\Console\Processes\Composer; -use Statamic\Extend\Manifest; use Statamic\Facades\Blueprint; -use Statamic\Providers\StatamicServiceProvider; +use Statamic\Facades\Site; use Statamic\Statamic; +use Statamic\Testing\AddonTestCase; -abstract class TestCase extends OrchestraTestCase +abstract class TestCase extends AddonTestCase { protected $shouldFakeVersion = true; - protected function setUp(): void + protected string $addonServiceProvider = ServiceProvider::class; + + protected function set2Up(): void { parent::setUp(); @@ -28,31 +29,21 @@ protected function setUp(): void } } - protected function getPackageProviders($app) - { - return [ - StatamicServiceProvider::class, - ServiceProvider::class, - ]; - } - - protected function getPackageAliases($app) - { - return [ - 'Statamic' => Statamic::class, - ]; - } - protected function getEnvironmentSetUp($app) { parent::getEnvironmentSetUp($app); - $app->make(Manifest::class)->manifest = [ - 'mitydigital/statamic-variable-number-fieldtype' => [ - 'id' => 'mitydigital/statamic-variable-number-fieldtype', - 'namespace' => 'MityDigital\\StatamicVariableNumberFieldtype', + config()->set('filesystems.disks', array_merge( + config('filesystems.disks'), + [ + 'fonts' => [ + 'driver' => 'local', + 'root' => __DIR__.'/fonts', + 'url' => env('APP_URL').'/storage', + 'visibility' => 'public', + ], ], - ]; + )); } protected function resolveApplicationConfiguration($app) @@ -61,24 +52,29 @@ protected function resolveApplicationConfiguration($app) $configs = [ 'forms', - 'sites', ]; foreach ($configs as $config) { $app['config']->set( "statamic.$config", - require(__DIR__."/../vendor/statamic/cms/config/{$config}.php") + require (__DIR__."/../vendor/statamic/cms/config/{$config}.php") ); } // set the forms folder $app['config']->set('statamic.forms.forms', __DIR__.'/__fixtures__/forms'); - // configure to be an AU site - $app['config']->set('statamic.sites.sites.default.locale', 'en_AU'); - Statamic::booted(function () { Blueprint::setDirectory(__DIR__.'/__fixtures__/blueprints'); + + // configure to be an AU site + Site::setSites([ + 'default' => [ + 'name' => config('app.name'), + 'locale' => 'en_AU', + 'url' => '/', + ], + ]); }); }