diff --git a/.github/workflows/run-tests.yaml b/.github/workflows/run-tests.yaml index 5e32d5fc..6339a599 100644 --- a/.github/workflows/run-tests.yaml +++ b/.github/workflows/run-tests.yaml @@ -1,37 +1,45 @@ name: Run Tests -on: [push, pull_request, workflow_dispatch] +on: ['push', 'pull_request'] jobs: - phpunit: - runs-on: ubuntu-latest + test: + runs-on: ${{ matrix.os }} strategy: fail-fast: true matrix: - php: [8.2] - laravel: [9.*] + os: [ubuntu-latest] + php: [8.2, 8.3] + laravel: [10.*, 11.*] stability: [prefer-lowest, prefer-stable] include: - - laravel: 9.* - testbench: ^7.1 + - laravel: 10.* + testbench: 8.* + - laravel: 11.* + testbench: 9.* - name: PHP ${{ matrix.php }} – Laravel ${{ matrix.laravel }} - ${{ matrix.stability }} + name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - 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 + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo coverage: none + - name: Setup problem matchers + run: | + echo "::add-matcher::${{ runner.tool_cache }}/php.json" + echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + - name: Install dependencies run: | composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update composer update --${{ matrix.stability }} --prefer-dist --no-interaction - - name: Run tests + - name: Execute tests run: vendor/bin/phpunit diff --git a/composer.json b/composer.json index a279c5e5..a476dd14 100644 --- a/composer.json +++ b/composer.json @@ -17,18 +17,18 @@ ], "require": { "php": "^8.2", - "laravel/framework": "^9.0 || ^10.0", + "laravel/framework": "^10.0 || ^11.0", "spatie/browsershot": "^4.0", "spatie/image": "^3.4", "spatie/laravel-ray": "^1.32", "spatie/schema-org": "^3.14", - "statamic/cms": "^4.27", + "statamic/cms": "^5.3", "whitecube/lingua": "^1.1" }, "require-dev": { - "nunomaduro/collision": "^6.1", - "orchestra/testbench": "7.1", - "phpunit/phpunit": "^9.5" + "nunomaduro/collision": "^7.0 || ^8.0", + "orchestra/testbench": "^8.0 || ^9.0", + "phpunit/phpunit": "^10.0" }, "autoload": { "psr-4": { diff --git a/phpunit.xml b/phpunit.xml index ed0a692e..697731d0 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,33 +1,24 @@ - - - - ./tests - - - - - ./app - - - - - - - - - - - - - + + + + ./tests + + + + + + + + + + + + + + + + ./app + + diff --git a/src/Data/SeoDefaultSet.php b/src/Data/SeoDefaultSet.php index 81d4750b..749303a6 100644 --- a/src/Data/SeoDefaultSet.php +++ b/src/Data/SeoDefaultSet.php @@ -105,7 +105,7 @@ public function fileData(): array 'title' => $this->title(), ]; - if (! Site::hasMultiple()) { + if (! Site::multiEnabled()) { $data['data'] = Arr::removeNullValues( $this->inDefaultSite()->data()->all() ); diff --git a/src/Data/SeoVariables.php b/src/Data/SeoVariables.php index be9cde48..bd26651e 100644 --- a/src/Data/SeoVariables.php +++ b/src/Data/SeoVariables.php @@ -73,7 +73,7 @@ public function path(): string { return vsprintf('%s/%s%s.yaml', [ Stache::store('seo')->store($this->type())->directory(), - Site::hasMultiple() ? $this->locale().'/' : '', + Site::multiEnabled() ? $this->locale().'/' : '', $this->handle(), ]); } @@ -100,7 +100,7 @@ protected function cpUrl($route) { $params = [$this->handle()]; - if (Site::hasMultiple()) { + if (Site::multiEnabled()) { $params['site'] = $this->locale(); } @@ -162,7 +162,7 @@ public function fileData(): array // We only want to keep values of fields that exist in the blueprint. $data = $this->data()->only($this->blueprintFields())->all(); - if (Site::hasMultiple() && $this->hasOrigin()) { + if (Site::multiEnabled() && $this->hasOrigin()) { $data['origin'] = $this->origin()->locale(); } diff --git a/src/Fields/BaseFields.php b/src/Fields/BaseFields.php index 0619e36e..0cef9a52 100644 --- a/src/Fields/BaseFields.php +++ b/src/Fields/BaseFields.php @@ -5,6 +5,7 @@ use Aerni\AdvancedSeo\Contracts\Fields; use Aerni\AdvancedSeo\Data\DefaultsData; use Aerni\AdvancedSeo\Support\Helpers; +use Illuminate\Support\Arr; abstract class BaseFields implements Fields { @@ -26,7 +27,7 @@ public function get(): array { return [ [ - 'fields' => array_flatten($this->sections(), 1), + 'fields' => Arr::flatten($this->sections(), 1), ], ]; } diff --git a/src/Fields/ContentDefaultsFields.php b/src/Fields/ContentDefaultsFields.php index 003c62d6..7575d4a4 100644 --- a/src/Fields/ContentDefaultsFields.php +++ b/src/Fields/ContentDefaultsFields.php @@ -8,6 +8,7 @@ use Aerni\AdvancedSeo\Features\SocialImagesGenerator; use Aerni\AdvancedSeo\Models\Defaults; use Aerni\AdvancedSeo\Models\SocialImageTheme; +use Illuminate\Support\Str; class ContentDefaultsFields extends BaseFields { @@ -300,7 +301,7 @@ protected function canonicalUrl(): array 'display' => $this->trans('seo_canonical_type.display'), 'instructions' => $this->trans('seo_canonical_type.default_instructions'), 'options' => [ - 'current' => $this->trans('seo_canonical_type.current', ['type' => ucfirst(str_singular($this->typePlaceholder()))]), + 'current' => $this->trans('seo_canonical_type.current', ['type' => ucfirst(Str::singular($this->typePlaceholder()))]), 'other' => $this->trans('seo_canonical_type.other'), 'custom' => $this->trans('seo_canonical_type.custom'), ], diff --git a/src/Fields/OnPageSeoFields.php b/src/Fields/OnPageSeoFields.php index 8421f7bd..e75d0f70 100644 --- a/src/Fields/OnPageSeoFields.php +++ b/src/Fields/OnPageSeoFields.php @@ -7,6 +7,7 @@ use Aerni\AdvancedSeo\Features\Sitemap; use Aerni\AdvancedSeo\Features\SocialImagesGenerator; use Aerni\AdvancedSeo\Models\SocialImageTheme; +use Illuminate\Support\Str; class OnPageSeoFields extends BaseFields { @@ -401,7 +402,7 @@ protected function canonicalUrl(): array 'field' => [ 'type' => 'button_group', 'options' => [ - 'current' => $this->trans('seo_canonical_type.current', ['type' => ucfirst(str_singular($this->typePlaceholder()))]), + 'current' => $this->trans('seo_canonical_type.current', ['type' => ucfirst(Str::singular($this->typePlaceholder()))]), 'other' => $this->trans('seo_canonical_type.other'), 'custom' => $this->trans('seo_canonical_type.custom'), ], diff --git a/src/GraphQL/Fields/ContentDefaultsField.php b/src/GraphQL/Fields/ContentDefaultsField.php index 9a180c14..11106344 100644 --- a/src/GraphQL/Fields/ContentDefaultsField.php +++ b/src/GraphQL/Fields/ContentDefaultsField.php @@ -7,6 +7,8 @@ use Aerni\AdvancedSeo\GraphQL\Types\ContentDefaultsType; use GraphQL\Type\Definition\ResolveInfo; use GraphQL\Type\Definition\Type; +use Illuminate\Support\Arr; +use Illuminate\Support\Str; use Rebing\GraphQL\Support\Field; use Statamic\Facades\GraphQL; @@ -37,7 +39,7 @@ public function type(): Type protected function resolve($root, $args, $context, ResolveInfo $info): ?SeoVariables { - $set = Seo::find(str_plural($info->fieldName), $args['handle']); + $set = Seo::find(Str::plural($info->fieldName), $args['handle']); if (! $set) { return null; @@ -47,7 +49,7 @@ protected function resolve($root, $args, $context, ResolveInfo $info): ?SeoVaria return null; } - return array_has($args, 'site') + return Arr::has($args, 'site') ? $set->in($args['site']) : $set->inDefaultSite(); } diff --git a/src/GraphQL/Types/SiteDefaultsType.php b/src/GraphQL/Types/SiteDefaultsType.php index c8b8fc65..d43347a9 100644 --- a/src/GraphQL/Types/SiteDefaultsType.php +++ b/src/GraphQL/Types/SiteDefaultsType.php @@ -5,6 +5,8 @@ use Aerni\AdvancedSeo\Data\SeoVariables; use Aerni\AdvancedSeo\Facades\Seo; use GraphQL\Type\Definition\ResolveInfo; +use Illuminate\Support\Arr; +use Illuminate\Support\Str; use Rebing\GraphQL\Support\Type; use Statamic\Facades\GraphQL; @@ -46,7 +48,7 @@ public function fields(): array private function resolver(): callable { return function ($root, $args, $context, ResolveInfo $info): ?SeoVariables { - $set = Seo::find('site', snake_case($info->fieldName)); + $set = Seo::find('site', Str::snake($info->fieldName)); if (! $set) { return null; @@ -56,7 +58,7 @@ private function resolver(): callable return null; } - return array_has($root, 'site') + return Arr::has($root, 'site') ? $set->in($root['site']) : $set->inDefaultSite(); }; diff --git a/src/Http/Controllers/Cp/SeoDefaultsController.php b/src/Http/Controllers/Cp/SeoDefaultsController.php index 60e5cc37..46c01f86 100644 --- a/src/Http/Controllers/Cp/SeoDefaultsController.php +++ b/src/Http/Controllers/Cp/SeoDefaultsController.php @@ -11,6 +11,7 @@ use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Support\Collection; +use Illuminate\Support\Str; use Statamic\CP\Breadcrumbs; use Statamic\Exceptions\NotFoundHttpException; use Statamic\Facades\Site; @@ -173,7 +174,7 @@ protected function defaults(): Collection protected function flashDefaultsUnavailable(): void { session()->now('error', __('There are no :type defaults available for the selected site.', [ - 'type' => str_singular($this->type()), + 'type' => Str::singular($this->type()), ])); throw new NotFoundHttpException(); @@ -184,7 +185,7 @@ protected function redirectToIndex(SeoDefaultSet $set, string $site): RedirectRe return redirect(cp_route("advanced-seo.{$set->type()}.index")) ->with('error', __('The :set :type is not available in the selected site.', [ 'set' => $set->title(), - 'type' => str_singular($this->type()), + 'type' => Str::singular($this->type()), ])); } diff --git a/src/Stache/SeoDefaultsStore.php b/src/Stache/SeoDefaultsStore.php index b68e6d83..cc337fcc 100644 --- a/src/Stache/SeoDefaultsStore.php +++ b/src/Stache/SeoDefaultsStore.php @@ -5,6 +5,7 @@ use Aerni\AdvancedSeo\Data\SeoDefaultSet; use Aerni\AdvancedSeo\Data\SeoVariables; use Aerni\AdvancedSeo\Facades\Seo; +use Illuminate\Support\Str; use Statamic\Facades\File; use Statamic\Facades\Path; use Statamic\Facades\Site; @@ -28,7 +29,7 @@ public function makeItemFromFile($path, $contents): SeoDefaultSet { $data = YAML::file($path)->parse($contents); - return Site::hasMultiple() + return Site::multiEnabled() ? $this->makeMultiSiteDefaultFromFile($path) : $this->makeSingleSiteDefaultFromFile($path, $data); } @@ -91,7 +92,7 @@ protected function makeVariables(SeoDefaultSet $set, string $site): ?SeoVariable protected function extractAttributesFromPath(string $path): array { - $relative = str_after($path, $this->parent->directory()); + $relative = Str::after($path, $this->parent->directory()); $type = pathinfo($relative, PATHINFO_DIRNAME); $handle = pathinfo($relative, PATHINFO_FILENAME); @@ -102,7 +103,7 @@ public function save($set): void { parent::save($set); - if (Site::hasMultiple()) { + if (Site::multiEnabled()) { Site::all()->each(function ($site) use ($set) { $site = $site->handle(); $set->existsIn($site) ? $set->in($site)->writeFile() : $set->makeLocalization($site)->deleteFile(); @@ -114,7 +115,7 @@ public function delete($set): void { parent::delete($set); - if (Site::hasMultiple()) { + if (Site::multiEnabled()) { $set->localizations()->each(function ($localization) { $localization->deleteFile(); });