From ba6cee4b8c2ea6cad713ebdc3fafd02156d76b36 Mon Sep 17 00:00:00 2001 From: Shift Date: Fri, 23 Feb 2024 16:47:56 +0000 Subject: [PATCH 01/31] Bump dependencies for Laravel 11 --- composer.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 6988335..2c2d4bc 100644 --- a/composer.json +++ b/composer.json @@ -31,15 +31,15 @@ }, "require": { "php": "^8.0", - "illuminate/contracts": "^8.0 || ^9.0 || ^10.0", - "illuminate/database": "^8.0 || ^9.0 || ^10.0", - "illuminate/support": "^8.0 || ^9.0 || ^10.0" + "illuminate/contracts": "^8.0 || ^9.0 || ^10.0 || ^11.0", + "illuminate/database": "^8.0 || ^9.0 || ^10.0 || ^11.0", + "illuminate/support": "^8.0 || ^9.0 || ^10.0 || ^11.0" }, "require-dev": { "laravel/legacy-factories": "^1.0.4", "mockery/mockery": "^1.3.3", - "orchestra/testbench": "^6.0 || ^7.0 || ^8.0", - "phpunit/phpunit": "^9.0" + "orchestra/testbench": "^6.0 || ^7.0 || ^8.0 || ^9.0", + "phpunit/phpunit": "^9.0 || ^10.5" }, "minimum-stability": "dev", "prefer-stable": true, From a3a8c0c96cb824b582b89d3acc75b23746f9275c Mon Sep 17 00:00:00 2001 From: Shift Date: Fri, 23 Feb 2024 16:47:56 +0000 Subject: [PATCH 02/31] Update GitHub Actions for Laravel 11 --- .github/workflows/run-tests.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index a89e9a1..7d1da2c 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -4,23 +4,28 @@ on: push: pull_request: schedule: - - cron: '0 0 * * *' + - cron: 0 0 * * * jobs: test: if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository + runs-on: ${{ matrix.os }} strategy: fail-fast: true matrix: - php: [8.0, 8.1] - laravel: [8.*, 9.*, 10.*] + php: [8.0, 8.1, '8.2'] + laravel: ['8.*', '9.*', '10.*', '11.*'] dependency-version: [prefer-stable] os: [ubuntu-latest] exclude: - laravel: 10.* php: 8.0 + - laravel: 11.* + php: 8.0 + - laravel: 11.* + php: 8.1 name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }} From dca3f63047cf63c9fadd2d44241dd977758b7e49 Mon Sep 17 00:00:00 2001 From: laravel-shift Date: Fri, 23 Feb 2024 16:48:31 +0000 Subject: [PATCH 03/31] Prettified Code! --- README.md | 2 +- docs/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ff36dd2..db868f4 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ If you discover any security related issues, please check [SECURITY](https://git ## Versions | Package | Laravel | PHP | -|:--------------------|:------------------------------| :-------- | +| :------------------ | :---------------------------- | :-------- | | **v11.12 - v11.12** | `8.* / 9.* / 10.*` | `^8.0` | | **v11.10 - v11.11** | `8.* / 9.*` | `^8.0` | | **v11.6 - v11.9** | `5.8.* / 6.* / 7.* / 8.*` | `>=7.2` | diff --git a/docs/README.md b/docs/README.md index ae0ab60..cd2a43f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -74,7 +74,7 @@ echo $post->translate('fr')->title; // Mon premier post ## Versions | Package | Laravel | PHP | -|:--------------------|:------------------------------| :-------- | +| :------------------ | :---------------------------- | :-------- | | **v11.12 - v11.12** | `8.* / 9.* / 10.*` | `^8.0` | | **v11.10 - v11.11** | `8.* / 9.*` | `^8.0` | | **v11.6 - v11.9** | `5.8.* / 6.* / 7.* / 8.*` | `>=7.2` | From ad60f1b691d7ed7cb5be6370946cf1e448ea1b66 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 17 Apr 2024 12:35:46 +0200 Subject: [PATCH 04/31] update CI --- .../workflows/{run-tests.yml => phpunit.yml} | 4 +- .github/workflows/pint.yml | 16 ++++++ .github/workflows/stale-issues.yml | 57 ------------------- .php_cs | 35 ------------ .styleci.yml | 3 - README.md | 4 +- composer.json | 6 +- 7 files changed, 22 insertions(+), 103 deletions(-) rename .github/workflows/{run-tests.yml => phpunit.yml} (97%) create mode 100644 .github/workflows/pint.yml delete mode 100644 .github/workflows/stale-issues.yml delete mode 100644 .php_cs delete mode 100644 .styleci.yml diff --git a/.github/workflows/run-tests.yml b/.github/workflows/phpunit.yml similarity index 97% rename from .github/workflows/run-tests.yml rename to .github/workflows/phpunit.yml index be5d7a4..8786e2d 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/phpunit.yml @@ -1,10 +1,8 @@ -name: run-tests +name: phpunit on: push: pull_request: - schedule: - - cron: 0 0 * * * jobs: test: diff --git a/.github/workflows/pint.yml b/.github/workflows/pint.yml new file mode 100644 index 0000000..79b0a9b --- /dev/null +++ b/.github/workflows/pint.yml @@ -0,0 +1,16 @@ +name: pint + +on: + push: + +jobs: + pint: + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@v3 + - uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 + - run: composer install --prefer-dist --no-interaction --no-suggest + - run: vendor/bin/pint --test diff --git a/.github/workflows/stale-issues.yml b/.github/workflows/stale-issues.yml deleted file mode 100644 index 5afb797..0000000 --- a/.github/workflows/stale-issues.yml +++ /dev/null @@ -1,57 +0,0 @@ -name: "Close stale issues" -on: - schedule: - - cron: "0 0 * * *" - -jobs: - default: - timeout-minutes: 1 - runs-on: ubuntu-latest - steps: - - uses: actions/stale@v6.0.1 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - stale-issue-message: 'This issue is stale because it has been open 21 days with no activity. Remove stale label or comment or this will be closed in 7 days' - stale-issue-label: 'stale' - exempt-issue-labels: 'bug,enhancement,documentation,help wanted,next release,next major release' - days-before-stale: 21 - days-before-close: 7 - - invalid: - timeout-minutes: 1 - runs-on: ubuntu-latest - steps: - - uses: actions/stale@v6.0.1 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - stale-issue-message: 'This issue is stale because it has been labeled as invalid.' - stale-issue-label: 'stale' - only-labels: 'invalid' - days-before-stale: 1 - days-before-close: 2 - - duplicate: - timeout-minutes: 1 - runs-on: ubuntu-latest - steps: - - uses: actions/stale@v6.0.1 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - stale-issue-message: 'This issue is stale because it has been labeled as duplicate.' - stale-issue-label: 'stale' - only-labels: 'duplicate' - days-before-stale: 1 - days-before-close: 2 - - wontfix: - timeout-minutes: 1 - runs-on: ubuntu-latest - steps: - - uses: actions/stale@v6.0.1 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - stale-issue-message: 'This issue is stale because it has been labeled as wontfix.' - stale-issue-label: 'stale' - only-labels: 'wontfix' - days-before-stale: 1 - days-before-close: 2 diff --git a/.php_cs b/.php_cs deleted file mode 100644 index f310dd9..0000000 --- a/.php_cs +++ /dev/null @@ -1,35 +0,0 @@ -in('src/Translatable'); - -return PhpCsFixer\Config::create() - ->setRules([ - 'ordered_class_elements' => [ - 'order' => [ - 'use_trait', - 'constant_public', - 'constant_protected', - 'constant_private', - 'property_public', - 'property_protected', - 'property_private', - 'construct', - 'method_public_static', - 'method_public', - 'method_protected_static', - 'method_protected', - 'method_private_static', - 'method_private', - 'destruct', - 'magic', - ], - 'sortAlgorithm' => 'alpha', - ], - 'yoda_style' => [ - 'equal' => false, - 'identical' => false, - 'less_and_greater' => null, - ], - ]) - ->setFinder($finder); diff --git a/.styleci.yml b/.styleci.yml deleted file mode 100644 index 6deb832..0000000 --- a/.styleci.yml +++ /dev/null @@ -1,3 +0,0 @@ -preset: laravel - -risky: true diff --git a/README.md b/README.md index db868f4..650025f 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,8 @@ [![Offset Earth](https://img.shields.io/badge/Treeware-%F0%9F%8C%B3-green?style=for-the-badge)](https://plant.treeware.earth/Astrotomic/laravel-translatable) [![Larabelles](https://img.shields.io/badge/Larabelles-%F0%9F%A6%84-lightpink?style=for-the-badge)](https://www.larabelles.com/) -[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/Astrotomic/laravel-translatable/run-tests?style=flat-square&logoColor=white&logo=github&label=Tests)](https://github.com/Astrotomic/laravel-translatable/actions?query=workflow%3Arun-tests) -[![StyleCI](https://styleci.io/repos/192333549/shield)](https://styleci.io/repos/192333549) +[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/Astrotomic/laravel-translatable/phpunit?style=flat-square&logoColor=white&logo=github&label=PHPunit)](https://github.com/Astrotomic/laravel-translatable/actions?query=workflow%3Aphpunit) +[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/Astrotomic/laravel-translatable/pint?style=flat-square&logoColor=white&logo=github&label=Pint)](https://github.com/Astrotomic/laravel-translatable/actions?query=workflow%3Apint) [![Codecov Coverage](https://img.shields.io/codecov/c/github/Astrotomic/laravel-translatable?logo=codecov&logoColor=white&label=Codecov&style=flat-square)](https://codecov.io/gh/Astrotomic/laravel-translatable) [![Total Downloads](https://img.shields.io/packagist/dt/astrotomic/laravel-translatable.svg?label=Downloads&style=flat-square)](https://packagist.org/packages/astrotomic/laravel-translatable) [![GitBook](https://img.shields.io/badge/GitBook-Astrotomic-7e57c2.svg?style=flat-square)](https://docs.astrotomic.info/laravel-translatable) diff --git a/composer.json b/composer.json index 2c2d4bc..1a8d0db 100644 --- a/composer.json +++ b/composer.json @@ -64,8 +64,8 @@ } }, "scripts": { - "csfix": "php-cs-fixer fix --using-cache=no", - "test": "vendor/bin/phpunit", - "test-coverage": "vendor/bin/phpunit --coverage-html=build" + "fix": "@php vendor/bin/pint", + "test": "@php vendor/bin/phpunit", + "test-coverage": "@php vendor/bin/phpunit --coverage-html=build" } } From c6a850c9dbd8a967992b9ccad263951ff7a06b05 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 17 Apr 2024 12:51:42 +0200 Subject: [PATCH 05/31] fix php cs --- composer.json | 1 + src/Translatable/Contracts/Translatable.php | 4 +- src/Translatable/Translatable.php | 6 +- src/Translatable/Validation/RuleFactory.php | 3 +- tests/Eloquent/Country.php | 3 +- tests/Eloquent/Person.php | 3 - tests/Eloquent/PersonTranslation.php | 1 + tests/Eloquent/StrictTranslation.php | 1 + tests/EloquentOverrideTest.php | 18 +- tests/LocalesTest.php | 80 ++--- tests/ScopesTest.php | 100 +++--- tests/TranslatableTest.php | 323 ++++++++++---------- tests/ValidationTest.php | 96 +++--- 13 files changed, 320 insertions(+), 319 deletions(-) diff --git a/composer.json b/composer.json index 1a8d0db..9c08161 100644 --- a/composer.json +++ b/composer.json @@ -37,6 +37,7 @@ }, "require-dev": { "laravel/legacy-factories": "^1.0.4", + "laravel/pint": "^1.15", "mockery/mockery": "^1.3.3", "orchestra/testbench": "^6.0 || ^7.0 || ^8.0 || ^9.0", "phpunit/phpunit": "^9.0 || ^10.5" diff --git a/src/Translatable/Contracts/Translatable.php b/src/Translatable/Contracts/Translatable.php index e824226..748546d 100644 --- a/src/Translatable/Contracts/Translatable.php +++ b/src/Translatable/Contracts/Translatable.php @@ -24,7 +24,7 @@ public function getDefaultLocale(): ?string; public function getNewTranslation(string $locale): Model; - public function getTranslation(?string $locale = null, bool $withFallback = null): ?Model; + public function getTranslation(?string $locale = null, ?bool $withFallback = null): ?Model; public function getTranslationOrNew(?string $locale = null): Model; @@ -34,7 +34,7 @@ public function hasTranslation(?string $locale = null): bool; public function isTranslationAttribute(string $key): bool; - public function replicateWithTranslations(array $except = null): Model; + public function replicateWithTranslations(?array $except = null): Model; public function setDefaultLocale(?string $locale); diff --git a/src/Translatable/Translatable.php b/src/Translatable/Translatable.php index 17800bd..41f5f8d 100644 --- a/src/Translatable/Translatable.php +++ b/src/Translatable/Translatable.php @@ -21,7 +21,7 @@ */ trait Translatable { - use Scopes, Relationship; + use Relationship, Scopes; protected static $autoloadTranslations = null; @@ -186,7 +186,7 @@ public function getNewTranslation(string $locale): Model return $translation; } - public function getTranslation(?string $locale = null, bool $withFallback = null): ?Model + public function getTranslation(?string $locale = null, ?bool $withFallback = null): ?Model { $configFallbackLocale = $this->getFallbackLocale(); $locale = $locale ?: $this->locale(); @@ -279,7 +279,7 @@ public function isTranslationAttribute(string $key): bool return in_array($key, $this->translatedAttributes); } - public function replicateWithTranslations(array $except = null): Model + public function replicateWithTranslations(?array $except = null): Model { $newInstance = $this->replicate($except); diff --git a/src/Translatable/Validation/RuleFactory.php b/src/Translatable/Validation/RuleFactory.php index bf0d30b..fee16db 100644 --- a/src/Translatable/Validation/RuleFactory.php +++ b/src/Translatable/Validation/RuleFactory.php @@ -9,6 +9,7 @@ class RuleFactory { const FORMAT_ARRAY = 1; + const FORMAT_KEY = 2; /** @@ -77,6 +78,7 @@ public function parse(array $input): array foreach ($input as $key => $value) { if (! $this->isTranslatable($key)) { $rules[$key] = $value; + continue; } @@ -94,7 +96,6 @@ protected function formatKey(string $locale, string $key): string } /** - * @param string $locale * @param string|string[]|mixed $rule * @return string|string[]|mixed */ diff --git a/tests/Eloquent/Country.php b/tests/Eloquent/Country.php index 4fb1849..01af2bb 100644 --- a/tests/Eloquent/Country.php +++ b/tests/Eloquent/Country.php @@ -29,8 +29,6 @@ class Country extends Eloquent implements TranslatableContract /** * This is the foreign key used to define the translation relationship. * Set this if you want to overwrite the laravel default for foreign keys. - * - * @var */ public $translationForeignKey; @@ -41,6 +39,7 @@ class Country extends Eloquent implements TranslatableContract * @var array */ public $fillable = []; + public $guarded = []; /** diff --git a/tests/Eloquent/Person.php b/tests/Eloquent/Person.php index 8463c26..3ab8407 100644 --- a/tests/Eloquent/Person.php +++ b/tests/Eloquent/Person.php @@ -31,8 +31,6 @@ class Person extends Eloquent implements TranslatableContract /** * This is the foreign key used to define the translation relationship. * Set this if you want to overwrite the laravel default for foreign keys. - * - * @var */ public $translationForeignKey; @@ -47,7 +45,6 @@ class Person extends Eloquent implements TranslatableContract /** * Mutate name attribute into upper-case. * - * @param $value * @return string */ public function getNameAttribute($value) diff --git a/tests/Eloquent/PersonTranslation.php b/tests/Eloquent/PersonTranslation.php index b757d57..3b55520 100644 --- a/tests/Eloquent/PersonTranslation.php +++ b/tests/Eloquent/PersonTranslation.php @@ -7,5 +7,6 @@ class PersonTranslation extends Eloquent { public $timestamps = false; + public $fillable = ['name']; } diff --git a/tests/Eloquent/StrictTranslation.php b/tests/Eloquent/StrictTranslation.php index 87cea1f..86b3626 100644 --- a/tests/Eloquent/StrictTranslation.php +++ b/tests/Eloquent/StrictTranslation.php @@ -7,5 +7,6 @@ class StrictTranslation extends Eloquent { public $timestamps = false; + protected $table = 'country_translations'; } diff --git a/tests/EloquentOverrideTest.php b/tests/EloquentOverrideTest.php index f74e082..771d9e5 100644 --- a/tests/EloquentOverrideTest.php +++ b/tests/EloquentOverrideTest.php @@ -11,8 +11,8 @@ public function to_array_returns_translated_attributes(): void { $vegetable = factory(Vegetable::class)->make(['name:en' => 'Peas']); - static::assertArrayHasKey('name', $vegetable->toArray()); - static::assertEquals('Peas', $vegetable->toArray()['name']); + self::assertArrayHasKey('name', $vegetable->toArray()); + self::assertEquals('Peas', $vegetable->toArray()['name']); } /** @test */ @@ -20,7 +20,7 @@ public function to_array_wont_break_if_no_translations_exist(): void { $vegetable = factory(Vegetable::class)->make(); - static::assertIsArray($vegetable->toArray()); + self::assertIsArray($vegetable->toArray()); } /** @test */ @@ -28,8 +28,8 @@ public function translated_attributes_can_be_accessed_as_properties(): void { $vegetable = factory(Vegetable::class)->make(['name:en' => 'Peas']); - static::assertTrue(isset($vegetable->name)); - static::assertEquals('Peas', $vegetable->name); + self::assertTrue(isset($vegetable->name)); + self::assertEquals('Peas', $vegetable->name); } /** @test */ @@ -37,11 +37,11 @@ public function it_can_hide_translated_attributes(): void { $vegetable = factory(Vegetable::class)->make(['name:en' => 'Peas']); - static::assertTrue(isset($vegetable->toArray()['name'])); + self::assertTrue(isset($vegetable->toArray()['name'])); $vegetable->setHidden(['name']); - static::assertFalse(isset($vegetable->toArray()['name'])); + self::assertFalse(isset($vegetable->toArray()['name'])); } /** @test */ @@ -49,7 +49,7 @@ public function it_finds_custom_primary_keys(): void { $vegetable = new Vegetable(); - static::assertEquals('vegetable_identity', $vegetable->getTranslationRelationKey()); + self::assertEquals('vegetable_identity', $vegetable->getTranslationRelationKey()); } /** @test */ @@ -57,6 +57,6 @@ public function setAttribute_returns_parent_setAttribute(): void { $vegetable = new Vegetable(); - static::assertSame($vegetable, $vegetable->setAttribute('name', 'China')); + self::assertSame($vegetable, $vegetable->setAttribute('name', 'China')); } } diff --git a/tests/LocalesTest.php b/tests/LocalesTest.php index 3fa842c..56be813 100644 --- a/tests/LocalesTest.php +++ b/tests/LocalesTest.php @@ -12,8 +12,8 @@ public function locales_is_declared_as_a_singleton_instance(): void { $singletonHash = spl_object_hash(app(Locales::class)); - static::assertEquals($singletonHash, spl_object_hash($this->app->make('translatable.locales'))); - static::assertEquals($singletonHash, spl_object_hash($this->app->make(Locales::class))); + self::assertEquals($singletonHash, spl_object_hash($this->app->make('translatable.locales'))); + self::assertEquals($singletonHash, spl_object_hash($this->app->make(Locales::class))); } /** @test */ @@ -23,15 +23,15 @@ public function it_loads_the_locales_from_the_configuration(): void 'de', ]); $this->app->make('translatable.locales')->load(); - static::assertEquals(['de'], $this->app->make('translatable.locales')->all()); + self::assertEquals(['de'], $this->app->make('translatable.locales')->all()); $this->app['config']->set('translatable.locales', [ 'de', 'en', ]); - static::assertEquals(['de'], $this->app->make('translatable.locales')->all()); + self::assertEquals(['de'], $this->app->make('translatable.locales')->all()); $this->app->make('translatable.locales')->load(); - static::assertEquals(['de', 'en'], $this->app->make('translatable.locales')->all()); + self::assertEquals(['de', 'en'], $this->app->make('translatable.locales')->all()); } /** @test */ @@ -55,7 +55,7 @@ public function all_language_locales_are_loaded_from_the_configuration(): void ]); $this->app->make('translatable.locales')->load(); - static::assertEquals(['el', 'en', 'fr', 'de', 'id'], $this->app->make('translatable.locales')->all()); + self::assertEquals(['el', 'en', 'fr', 'de', 'id'], $this->app->make('translatable.locales')->all()); } /** @test */ @@ -73,7 +73,7 @@ public function it_loads_locales_and_countries(): void ]); $this->app->make('translatable.locales')->load(); - static::assertEquals(['en', 'en-GB', 'en-US', 'de', 'de-DE', 'de-CH'], $this->app->make('translatable.locales')->all()); + self::assertEquals(['en', 'en-GB', 'en-US', 'de', 'de-DE', 'de-CH'], $this->app->make('translatable.locales')->all()); } /** @test */ @@ -88,7 +88,7 @@ public function can_return_locales_as_array(): void ]); $this->app->make('translatable.locales')->load(); - static::assertEquals(['el', 'en', 'fr', 'de', 'id'], $this->app->make('translatable.locales')->toArray()); + self::assertEquals(['el', 'en', 'fr', 'de', 'id'], $this->app->make('translatable.locales')->toArray()); } /** @test */ @@ -96,7 +96,7 @@ public function can_retrieve_current_configuration(): void { $this->app['config']->set('translatable.locale', 'de'); - static::assertEquals('de', $this->app->make('translatable.locales')->current()); + self::assertEquals('de', $this->app->make('translatable.locales')->current()); } /** @test */ @@ -105,7 +105,7 @@ public function current_can_return_the_translator_locale_if_configuration_is_emp $this->app['config']->set('translatable.locale', null); $this->app['translator']->setLocale('en'); - static::assertEquals('en', $this->app->make('translatable.locales')->current()); + self::assertEquals('en', $this->app->make('translatable.locales')->current()); } /** @test */ @@ -120,8 +120,8 @@ public function it_checks_if_it_has_a_locale(): void ]); $this->app->make('translatable.locales')->load(); - static::assertTrue($this->app->make('translatable.locales')->has('de')); - static::assertFalse($this->app->make('translatable.locales')->has('jp')); + self::assertTrue($this->app->make('translatable.locales')->has('de')); + self::assertFalse($this->app->make('translatable.locales')->has('jp')); } /** @test */ @@ -136,8 +136,8 @@ public function can_access_as_an_array(): void ]); $this->app->make('translatable.locales')->load(); - static::assertTrue(isset($this->app->make('translatable.locales')['de'])); - static::assertFalse(isset($this->app->make('translatable.locales')['jp'])); + self::assertTrue(isset($this->app->make('translatable.locales')['de'])); + self::assertFalse(isset($this->app->make('translatable.locales')['jp'])); } /** @test */ @@ -152,8 +152,8 @@ public function can_retrieve_a_specific_locale_by_get(): void ]); $this->app->make('translatable.locales')->load(); - static::assertEquals('de', $this->app->make('translatable.locales')->get('de')); - static::assertNull($this->app->make('translatable.locales')->get('jp')); + self::assertEquals('de', $this->app->make('translatable.locales')->get('de')); + self::assertNull($this->app->make('translatable.locales')->get('jp')); } /** @test */ @@ -168,8 +168,8 @@ public function missing_locale_returns_null_by_get(): void ]); $this->app->make('translatable.locales')->load(); - static::assertEquals('de', $this->app->make('translatable.locales')['de']); - static::assertNull($this->app->make('translatable.locales')['jp']); + self::assertEquals('de', $this->app->make('translatable.locales')['de']); + self::assertNull($this->app->make('translatable.locales')['jp']); } /** @test */ @@ -180,10 +180,10 @@ public function it_can_add_a_locale(): void ]); $this->app->make('translatable.locales')->load(); - static::assertTrue($this->app->make('translatable.locales')->has('de')); - static::assertFalse($this->app->make('translatable.locales')->has('en')); + self::assertTrue($this->app->make('translatable.locales')->has('de')); + self::assertFalse($this->app->make('translatable.locales')->has('en')); $this->app->make('translatable.locales')->add('en'); - static::assertTrue($this->app->make('translatable.locales')->has('en')); + self::assertTrue($this->app->make('translatable.locales')->has('en')); } /** @test */ @@ -194,10 +194,10 @@ public function locale_can_be_added_by_accessing_as_an_array(): void ]); $this->app->make('translatable.locales')->load(); - static::assertTrue($this->app->make('translatable.locales')->has('de')); - static::assertFalse($this->app->make('translatable.locales')->has('en')); + self::assertTrue($this->app->make('translatable.locales')->has('de')); + self::assertFalse($this->app->make('translatable.locales')->has('en')); $this->app->make('translatable.locales')[] = 'en'; - static::assertTrue($this->app->make('translatable.locales')->has('en')); + self::assertTrue($this->app->make('translatable.locales')->has('en')); } /** @test */ @@ -208,10 +208,10 @@ public function locale_country_can_be_added_by_accessing_as_an_array(): void ]); $this->app->make('translatable.locales')->load(); - static::assertTrue($this->app->make('translatable.locales')->has('de')); - static::assertFalse($this->app->make('translatable.locales')->has('de-AT')); + self::assertTrue($this->app->make('translatable.locales')->has('de')); + self::assertFalse($this->app->make('translatable.locales')->has('de-AT')); $this->app->make('translatable.locales')['de'] = 'AT'; - static::assertTrue($this->app->make('translatable.locales')->has('de-AT')); + self::assertTrue($this->app->make('translatable.locales')->has('de-AT')); } /** @test */ @@ -223,10 +223,10 @@ public function can_forget_a_locale(): void ]); $this->app->make('translatable.locales')->load(); - static::assertTrue($this->app->make('translatable.locales')->has('de')); - static::assertTrue($this->app->make('translatable.locales')->has('en')); + self::assertTrue($this->app->make('translatable.locales')->has('de')); + self::assertTrue($this->app->make('translatable.locales')->has('en')); $this->app->make('translatable.locales')->forget('en'); - static::assertFalse($this->app->make('translatable.locales')->has('en')); + self::assertFalse($this->app->make('translatable.locales')->has('en')); } /** @test */ @@ -238,10 +238,10 @@ public function can_forget_a_locale_using_unset_as_an_array(): void ]); $this->app->make('translatable.locales')->load(); - static::assertTrue($this->app->make('translatable.locales')->has('de')); - static::assertTrue($this->app->make('translatable.locales')->has('en')); + self::assertTrue($this->app->make('translatable.locales')->has('de')); + self::assertTrue($this->app->make('translatable.locales')->has('en')); unset($this->app->make('translatable.locales')['en']); - static::assertFalse($this->app->make('translatable.locales')->has('en')); + self::assertFalse($this->app->make('translatable.locales')->has('en')); } /** @test */ @@ -249,7 +249,7 @@ public function can_retrieve_the_locale_country_separator(): void { $this->app['config']->set('translatable.locale_separator', '_'); - static::assertEquals('_', $this->app->make('translatable.locales')->getLocaleSeparator()); + self::assertEquals('_', $this->app->make('translatable.locales')->getLocaleSeparator()); } /** @test */ @@ -257,26 +257,26 @@ public function can_set_a_default_locale_country_separator_if_configuration_is_m { $this->app['config']->set('translatable.locale_separator', null); - static::assertEquals('-', $this->app->make('translatable.locales')->getLocaleSeparator()); + self::assertEquals('-', $this->app->make('translatable.locales')->getLocaleSeparator()); } /** @test */ public function can_get_a_country_locale_formatted_with_separator(): void { - static::assertEquals('de-AT', $this->app->make('translatable.locales')->getCountryLocale('de', 'AT')); + self::assertEquals('de-AT', $this->app->make('translatable.locales')->getCountryLocale('de', 'AT')); } /** @test */ public function can_determine_if_a_locale_is_country_based(): void { - static::assertTrue($this->app->make('translatable.locales')->isLocaleCountryBased('de-AT')); - static::assertFalse($this->app->make('translatable.locales')->isLocaleCountryBased('de')); + self::assertTrue($this->app->make('translatable.locales')->isLocaleCountryBased('de-AT')); + self::assertFalse($this->app->make('translatable.locales')->isLocaleCountryBased('de')); } /** @test */ public function can_get_a_locale_from_the_country_locale(): void { - static::assertEquals('de', $this->app->make('translatable.locales')->getLanguageFromCountryBasedLocale('de-AT')); - static::assertEquals('de', $this->app->make('translatable.locales')->getLanguageFromCountryBasedLocale('de')); + self::assertEquals('de', $this->app->make('translatable.locales')->getLanguageFromCountryBasedLocale('de-AT')); + self::assertEquals('de', $this->app->make('translatable.locales')->getLanguageFromCountryBasedLocale('de')); } } diff --git a/tests/ScopesTest.php b/tests/ScopesTest.php index 900ad26..dd6b309 100644 --- a/tests/ScopesTest.php +++ b/tests/ScopesTest.php @@ -13,7 +13,7 @@ public function translated_in_scope_returns_only_translated_records_for_this_loc factory(Country::class)->create(['code' => 'ca', 'name:ca' => 'Català']); factory(Country::class)->create(['code' => 'fr', 'name:fr' => 'Français']); - static::assertEquals(1, Country::translatedIn('fr')->count()); + self::assertEquals(1, Country::translatedIn('fr')->count()); } /** @test */ @@ -23,8 +23,8 @@ public function translated_in_scope_works_with_default_locale(): void factory(Country::class)->create(['code' => 'ca', 'name:ca' => 'Català']); factory(Country::class)->create(['code' => 'el', 'name:de' => 'Griechenland']); - static::assertEquals(1, Country::translatedIn()->count()); - static::assertEquals('Griechenland', Country::translatedIn()->first()->name); + self::assertEquals(1, Country::translatedIn()->count()); + self::assertEquals('Griechenland', Country::translatedIn()->first()->name); } /** @test */ @@ -36,9 +36,9 @@ public function not_translated_in_scope_returns_only_not_translated_records_for_ $notTranslated = Country::notTranslatedIn('en')->get(); - static::assertEquals(2, $notTranslated->count()); - static::assertFalse($notTranslated->first()->hasTranslation('en')); - static::assertFalse($notTranslated->last()->hasTranslation('en')); + self::assertEquals(2, $notTranslated->count()); + self::assertFalse($notTranslated->first()->hasTranslation('en')); + self::assertFalse($notTranslated->last()->hasTranslation('en')); } /** @test */ @@ -50,8 +50,8 @@ public function not_translated_in_scope_works_with_default_locale(): void factory(Country::class)->create(['code' => 'en', 'name:es' => 'Inglés']); $notTranslated = Country::notTranslatedIn()->get(); - static::assertEquals(2, $notTranslated->count()); - static::assertFalse($notTranslated->first()->hasTranslation('en')); + self::assertEquals(2, $notTranslated->count()); + self::assertFalse($notTranslated->first()->hasTranslation('en')); } /** @test */ @@ -60,8 +60,8 @@ public function translated_scope_returns_records_with_at_least_one_translation() factory(Country::class)->create(['code' => 'ca']); factory(Country::class)->create(['code' => 'en', 'name:en' => 'English']); - static::assertEquals(1, Country::translated()->count()); - static::assertEquals('English', Country::with('translations')->translated()->first()->{'name:en'}); + self::assertEquals(1, Country::translated()->count()); + self::assertEquals('English', Country::with('translations')->translated()->first()->{'name:en'}); } /** @test */ @@ -75,9 +75,9 @@ public function lists_of_translated_fields(): void $countries = Country::listsTranslations('name')->get(); - static::assertEquals(1, $countries->count()); - static::assertEquals(1, $countries->first()->id); - static::assertEquals('Griechenland', $countries->first()->name); + self::assertEquals(1, $countries->count()); + self::assertEquals(1, $countries->first()->id); + self::assertEquals('Griechenland', $countries->first()->name); } /** @test */ @@ -95,11 +95,11 @@ public function lists_of_translated_fields_with_fallback(): void $countries = $country->listsTranslations('name')->get(); - static::assertEquals(2, $countries->count()); + self::assertEquals(2, $countries->count()); - static::assertEquals(1, $countries->first()->id); - static::assertEquals('Griechenland', $countries->first()->name); - static::assertEquals('France', $countries->last()->name); + self::assertEquals(1, $countries->first()->id); + self::assertEquals('Griechenland', $countries->first()->name); + self::assertEquals('France', $countries->last()->name); } /** @test */ @@ -112,7 +112,7 @@ public function lists_of_translated_fields_disable_autoload_translations(): void Country::disableAutoloadTranslations(); - static::assertEquals([['id' => 1, 'name' => 'Griechenland']], Country::listsTranslations('name')->get()->toArray()); + self::assertEquals([['id' => 1, 'name' => 'Griechenland']], Country::listsTranslations('name')->get()->toArray()); Country::defaultAutoloadTranslations(); } @@ -126,7 +126,7 @@ public function lists_of_translated_fields_enable_autoload_translations(): void Country::enableAutoloadTranslations(); - static::assertEquals([[ + self::assertEquals([[ 'id' => 1, 'name' => 'Griechenland', 'translations' => [[ @@ -146,8 +146,8 @@ public function scope_withTranslation_without_fallback(): void $result = Country::withTranslation()->first(); - static::assertCount(1, $result->translations); - static::assertSame('Greece', $result->translations->first()->name); + self::assertCount(1, $result->translations); + self::assertSame('Greece', $result->translations->first()->name); } /** @test */ @@ -159,9 +159,9 @@ public function scope_withTranslation_with_fallback(): void factory(Country::class)->create(['code' => 'el', 'name:en' => 'Greece', 'name:de' => 'Griechenland']); $result = Country::withTranslation()->first(); - static::assertEquals(2, $result->translations->count()); - static::assertEquals('Greece', $result->translations->where('locale', 'en')->first()->name); - static::assertEquals('Griechenland', $result->translations->where('locale', 'de')->first()->name); + self::assertEquals(2, $result->translations->count()); + self::assertEquals('Greece', $result->translations->where('locale', 'en')->first()->name); + self::assertEquals('Griechenland', $result->translations->where('locale', 'de')->first()->name); } /** @test */ @@ -178,22 +178,22 @@ public function scope_withTranslation_with_country_based_fallback(): void 'en-GB' => ['name' => 'Courgette'], ]); - static::assertEquals('Courgette', Vegetable::withTranslation()->first()->name); + self::assertEquals('Courgette', Vegetable::withTranslation()->first()->name); app()->setLocale('de-CH'); $translations = Vegetable::withTranslation()->first()->translations; - static::assertEquals(3, $translations->count()); + self::assertEquals(3, $translations->count()); - static::assertEquals('de', $translations[0]->locale); - static::assertEquals('Zucchini', $translations[0]->name); + self::assertEquals('de', $translations[0]->locale); + self::assertEquals('Zucchini', $translations[0]->name); - static::assertEquals('de-CH', $translations[1]->locale); - static::assertEquals('Zucchetti', $translations[1]->name); + self::assertEquals('de-CH', $translations[1]->locale); + self::assertEquals('Zucchetti', $translations[1]->name); - static::assertEquals('en', $translations[2]->locale); - static::assertEquals('Zucchini', $translations[2]->name); + self::assertEquals('en', $translations[2]->locale); + self::assertEquals('Zucchini', $translations[2]->name); } /** @test */ @@ -201,7 +201,7 @@ public function whereTranslation_filters_by_translation(): void { factory(Country::class)->create(['code' => 'gr', 'name:en' => 'Greece']); - static::assertSame('gr', Country::whereTranslation('name', 'Greece')->first()->code); + self::assertSame('gr', Country::whereTranslation('name', 'Greece')->first()->code); } /** @test */ @@ -212,9 +212,9 @@ public function orWhereTranslation_filters_by_translation(): void $result = Country::whereTranslation('name', 'Greece')->orWhereTranslation('name', 'France')->get(); - static::assertEquals(2, $result->count()); - static::assertSame('Greece', $result->first()->name); - static::assertSame('France', $result->last()->name); + self::assertEquals(2, $result->count()); + self::assertSame('Greece', $result->first()->name); + self::assertSame('France', $result->last()->name); } /** @test */ @@ -223,11 +223,11 @@ public function whereTranslation_filters_by_translation_and_locale(): void factory(Country::class)->create(['code' => 'gr', 'name:de' => 'Griechenland']); factory(Country::class)->create(['code' => 'some-code', 'name' => 'Griechenland']); - static::assertEquals(2, Country::whereTranslation('name', 'Griechenland')->count()); + self::assertEquals(2, Country::whereTranslation('name', 'Griechenland')->count()); $result = Country::whereTranslation('name', 'Griechenland', 'de')->get(); - static::assertSame(1, $result->count()); - static::assertSame('gr', $result->first()->code); + self::assertSame(1, $result->count()); + self::assertSame('gr', $result->first()->code); } /** @test */ @@ -235,7 +235,7 @@ public function whereTranslationLike_filters_by_translation(): void { factory(Country::class)->create(['code' => 'gr', 'name:en' => 'Greece']); - static::assertSame('gr', Country::whereTranslationLike('name', '%Greec%')->first()->code); + self::assertSame('gr', Country::whereTranslationLike('name', '%Greec%')->first()->code); } /** @test */ @@ -246,9 +246,9 @@ public function orWhereTranslationLike_filters_by_translation(): void $result = Country::whereTranslationLike('name', '%eece%')->orWhereTranslationLike('name', '%ance%')->get(); - static::assertEquals(2, $result->count()); - static::assertSame('Greece', $result->first()->name); - static::assertSame('France', $result->last()->name); + self::assertEquals(2, $result->count()); + self::assertSame('Greece', $result->first()->name); + self::assertSame('France', $result->last()->name); } /** @test */ @@ -257,11 +257,11 @@ public function whereTranslationLike_filters_by_translation_and_locale(): void factory(Country::class)->create(['code' => 'gr', 'name:de' => 'Griechenland']); factory(Country::class)->create(['code' => 'some-code', 'name:en' => 'Griechenland']); - static::assertEquals(2, Country::whereTranslationLike('name', 'Griechen%')->count()); + self::assertEquals(2, Country::whereTranslationLike('name', 'Griechen%')->count()); $result = Country::whereTranslationLike('name', '%riechenlan%', 'de')->get(); - static::assertEquals(1, $result->count()); - static::assertEquals('gr', $result->first()->code); + self::assertEquals(1, $result->count()); + self::assertEquals('gr', $result->first()->code); } /** @test */ @@ -270,7 +270,7 @@ public function orderByTranslation_sorts_by_key_asc(): void factory(Country::class)->create(['code' => 'el', 'name' => 'Greece']); factory(Country::class)->create(['code' => 'fr', 'name' => 'France']); - static::assertEquals('fr', Country::orderByTranslation('name')->get()->first()->code); + self::assertEquals('fr', Country::orderByTranslation('name')->get()->first()->code); } /** @test */ @@ -279,7 +279,7 @@ public function orderByTranslation_sorts_by_key_desc(): void factory(Country::class)->create(['code' => 'el', 'name' => 'Greece']); factory(Country::class)->create(['code' => 'fr', 'name' => 'France']); - static::assertEquals('el', Country::orderByTranslation('name', 'desc')->get()->first()->code); + self::assertEquals('el', Country::orderByTranslation('name', 'desc')->get()->first()->code); } /** @test */ @@ -290,10 +290,10 @@ public function test_orderByTranslation_sorts_by_key_asc_even_if_locale_is_missi factory(Vegetable::class)->create([]); $orderInEnglish = Vegetable::orderByTranslation('name')->get(); - static::assertEquals([null, 'Potatoes', 'Strawberries'], $orderInEnglish->pluck('name')->toArray()); + self::assertEquals([null, 'Potatoes', 'Strawberries'], $orderInEnglish->pluck('name')->toArray()); app()->setLocale('fr'); $orderInFrench = Vegetable::orderByTranslation('name', 'desc')->get(); - static::assertEquals(['Pommes de Terre', 'Fraises', null], $orderInFrench->pluck('name')->toArray()); + self::assertEquals(['Pommes de Terre', 'Fraises', null], $orderInFrench->pluck('name')->toArray()); } } diff --git a/tests/TranslatableTest.php b/tests/TranslatableTest.php index a5b2162..877aaa7 100644 --- a/tests/TranslatableTest.php +++ b/tests/TranslatableTest.php @@ -19,7 +19,7 @@ final class TranslatableTest extends TestCase /** @test */ public function it_finds_the_default_translation_class(): void { - static::assertEquals( + self::assertEquals( VegetableTranslation::class, (new Vegetable())->getTranslationModelNameDefault() ); @@ -30,7 +30,7 @@ public function it_finds_the_translation_class_with_namespace_set(): void { $this->app->make('config')->set('translatable.translation_model_namespace', 'App\Models\Translations'); - static::assertEquals( + self::assertEquals( 'App\Models\Translations\VegetableTranslation', (new Vegetable())->getTranslationModelNameDefault() ); @@ -41,7 +41,7 @@ public function it_finds_the_translation_class_with_suffix_set(): void { $this->app->make('config')->set('translatable.translation_suffix', 'Trans'); - static::assertEquals( + self::assertEquals( 'Astrotomic\Translatable\Tests\Eloquent\VegetableTrans', (new Vegetable())->getTranslationModelName() ); @@ -52,13 +52,13 @@ public function it_returns_custom_TranslationModelName(): void { $vegetable = new Vegetable(); - static::assertEquals( + self::assertEquals( $vegetable->getTranslationModelNameDefault(), $vegetable->getTranslationModelName() ); $vegetable->translationModel = 'MyAwesomeVegetableTranslation'; - static::assertEquals( + self::assertEquals( 'MyAwesomeVegetableTranslation', $vegetable->getTranslationModelName() ); @@ -68,10 +68,10 @@ public function it_returns_custom_TranslationModelName(): void public function it_returns_relation_key(): void { $vegetable = new Vegetable(); - static::assertEquals('vegetable_identity', $vegetable->getRelationKey()); + self::assertEquals('vegetable_identity', $vegetable->getRelationKey()); $vegetable->translationForeignKey = 'my_awesome_key'; - static::assertEquals('my_awesome_key', $vegetable->getRelationKey()); + self::assertEquals('my_awesome_key', $vegetable->getRelationKey()); } /** @test */ @@ -79,15 +79,15 @@ public function it_returns_the_translation(): void { $vegetable = factory(Vegetable::class)->create(['name:el' => 'Αρακάς', 'name:en' => 'Peas']); - static::assertEquals('Αρακάς', $vegetable->translate('el')->name); + self::assertEquals('Αρακάς', $vegetable->translate('el')->name); - static::assertEquals('Peas', $vegetable->translate('en')->name); + self::assertEquals('Peas', $vegetable->translate('en')->name); $this->app->setLocale('el'); - static::assertEquals('Αρακάς', $vegetable->translate()->name); + self::assertEquals('Αρακάς', $vegetable->translate()->name); $this->app->setLocale('en'); - static::assertEquals('Peas', $vegetable->translate()->name); + self::assertEquals('Peas', $vegetable->translate()->name); } /** @test */ @@ -95,8 +95,8 @@ public function it_returns_the_translation_with_accessor(): void { $vegetable = factory(Vegetable::class)->create(['name:el' => 'Αρακάς', 'name:en' => 'Peas']); - static::assertEquals('Αρακάς', $vegetable->{'name:el'}); - static::assertEquals('Peas', $vegetable->{'name:en'}); + self::assertEquals('Αρακάς', $vegetable->{'name:el'}); + self::assertEquals('Peas', $vegetable->{'name:en'}); } /** @test */ @@ -104,7 +104,7 @@ public function it_returns_null_when_the_locale_doesnt_exist(): void { $vegetable = factory(Vegetable::class)->create(['name:el' => 'Αρακάς']); - static::assertSame(null, $vegetable->{'name:unknown-locale'}); + self::assertSame(null, $vegetable->{'name:unknown-locale'}); } /** @test */ @@ -112,13 +112,13 @@ public function it_saves_translations(): void { $vegetable = factory(Vegetable::class)->create(['name:el' => 'Αρακάς', 'name:en' => 'Peas']); - static::assertEquals('Peas', $vegetable->name); + self::assertEquals('Peas', $vegetable->name); $vegetable->name = 'Pea'; $vegetable->save(); $vegetable->refresh(); - static::assertEquals('Pea', $vegetable->name); + self::assertEquals('Pea', $vegetable->name); } /** @test */ @@ -132,10 +132,10 @@ public function it_saves_translations_with_mutator(): void $vegetable->refresh(); $this->app->setLocale('en'); - static::assertEquals('Pea', $vegetable->translate()->name); + self::assertEquals('Pea', $vegetable->translate()->name); $this->app->setLocale('el'); - static::assertEquals('Μπιζέλι', $vegetable->translate()->name); + self::assertEquals('Μπιζέλι', $vegetable->translate()->name); } /** @test */ @@ -144,20 +144,20 @@ public function it_does_not_lazy_load_translations_when_updating_non_translated_ DB::enableQueryLog(); $vegetable = factory(Vegetable::class)->create(); - static::assertFalse($vegetable->relationLoaded('translations')); - static::assertCount(1, DB::getQueryLog()); + self::assertFalse($vegetable->relationLoaded('translations')); + self::assertCount(1, DB::getQueryLog()); DB::flushQueryLog(); $vegetable->update(['quantity' => 5]); - static::assertFalse($vegetable->relationLoaded('translations')); - static::assertCount(1, DB::getQueryLog()); + self::assertFalse($vegetable->relationLoaded('translations')); + self::assertCount(1, DB::getQueryLog()); DB::flushQueryLog(); $vegetable->update(['name' => 'Germany']); - static::assertTrue($vegetable->relationLoaded('translations')); - static::assertCount(2, DB::getQueryLog()); + self::assertTrue($vegetable->relationLoaded('translations')); + self::assertCount(2, DB::getQueryLog()); DB::disableQueryLog(); } @@ -169,11 +169,11 @@ public function it_uses_default_locale_to_return_translations(): void $vegetable->translate('el')->name = 'Μπιζέλι'; $this->app->setLocale('el'); - static::assertEquals('Μπιζέλι', $vegetable->name); + self::assertEquals('Μπιζέλι', $vegetable->name); $vegetable->save(); $vegetable->refresh(); - static::assertEquals('Μπιζέλι', $vegetable->translate('el')->name); + self::assertEquals('Μπιζέλι', $vegetable->translate('el')->name); } /** @test */ @@ -185,8 +185,8 @@ public function it_creates_translations_using_the_shortcut(): void $vegetable->save(); $vegetable = Vegetable::first(); - static::assertEquals('Peas', $vegetable->name); - static::assertDatabaseHas('vegetable_translations', [ + self::assertEquals('Peas', $vegetable->name); + self::assertDatabaseHas('vegetable_translations', [ 'vegetable_identity' => $vegetable->identity, 'locale' => 'en', 'name' => 'Peas', @@ -201,8 +201,8 @@ public function it_creates_translations_using_mass_assignment(): void 'name' => 'Peas', ]); - static::assertEquals(5, $vegetable->quantity); - static::assertEquals('Peas', $vegetable->name); + self::assertEquals(5, $vegetable->quantity); + self::assertEquals('Peas', $vegetable->name); } /** @test */ @@ -210,17 +210,17 @@ public function it_creates_translations_using_mass_assignment_and_locales(): voi { $vegetable = Vegetable::create([ 'quantity' => 5, - 'en' => ['name' => 'Peas'], - 'fr' => ['name' => 'Pois'], + 'en' => ['name' => 'Peas'], + 'fr' => ['name' => 'Pois'], ]); - static::assertEquals(5, $vegetable->quantity); - static::assertEquals('Peas', $vegetable->translate('en')->name); - static::assertEquals('Pois', $vegetable->translate('fr')->name); + self::assertEquals(5, $vegetable->quantity); + self::assertEquals('Peas', $vegetable->translate('en')->name); + self::assertEquals('Pois', $vegetable->translate('fr')->name); $vegetable = Vegetable::first(); - static::assertEquals('Peas', $vegetable->translate('en')->name); - static::assertEquals('Pois', $vegetable->translate('fr')->name); + self::assertEquals('Peas', $vegetable->translate('en')->name); + self::assertEquals('Pois', $vegetable->translate('fr')->name); } /** @test */ @@ -229,13 +229,13 @@ public function it_skips_mass_assignment_if_attributes_non_fillable(): void $this->expectException(MassAssignmentException::class); $country = CountryStrict::create([ 'code' => 'be', - 'en' => ['name' => 'Belgium'], - 'fr' => ['name' => 'Belgique'], + 'en' => ['name' => 'Belgium'], + 'fr' => ['name' => 'Belgique'], ]); - static::assertEquals('be', $country->code); - static::assertNull($country->translate('en')); - static::assertNull($country->translate('fr')); + self::assertEquals('be', $country->code); + self::assertNull($country->translate('en')); + self::assertNull($country->translate('fr')); } /** @test */ @@ -243,8 +243,8 @@ public function it_returns_if_object_has_translation(): void { $vegetable = factory(Vegetable::class)->create(['name:en' => 'Peas']); - static::assertTrue($vegetable->hasTranslation('en')); - static::assertFalse($vegetable->hasTranslation('some-code')); + self::assertTrue($vegetable->hasTranslation('en')); + self::assertFalse($vegetable->hasTranslation('some-code')); } /** @test */ @@ -254,12 +254,12 @@ public function it_returns_default_translation(): void $vegetable = factory(Vegetable::class)->create(['name:de' => 'Erbsen']); - static::assertEquals('Erbsen', $vegetable->getTranslation('ch', true)->name); - static::assertEquals('Erbsen', $vegetable->translateOrDefault('ch')->name); - static::assertNull($vegetable->getTranslation('ch', false)); + self::assertEquals('Erbsen', $vegetable->getTranslation('ch', true)->name); + self::assertEquals('Erbsen', $vegetable->translateOrDefault('ch')->name); + self::assertNull($vegetable->getTranslation('ch', false)); $this->app->setLocale('ch'); - static::assertSame('Erbsen', $vegetable->translateOrDefault()->name); + self::assertSame('Erbsen', $vegetable->translateOrDefault()->name); } /** @test */ @@ -268,16 +268,16 @@ public function fallback_option_in_config_overrides_models_fallback_option(): vo $this->app->make('config')->set('translatable.fallback_locale', 'de'); $vegetable = factory(Vegetable::class)->create(['name:de' => 'Erbsen']); - static::assertEquals('de', $vegetable->getTranslation('ch', true)->locale); + self::assertEquals('de', $vegetable->getTranslation('ch', true)->locale); $vegetable->useTranslationFallback = false; - static::assertEquals('de', $vegetable->getTranslation('ch', true)->locale); + self::assertEquals('de', $vegetable->getTranslation('ch', true)->locale); $vegetable->useTranslationFallback = true; - static::assertEquals('de', $vegetable->getTranslation('ch')->locale); + self::assertEquals('de', $vegetable->getTranslation('ch')->locale); $vegetable->useTranslationFallback = false; - static::assertNull($vegetable->getTranslation('ch')); + self::assertNull($vegetable->getTranslation('ch')); } /** @test */ @@ -288,7 +288,7 @@ public function configuration_defines_if_fallback_is_used(): void $vegetable = factory(Vegetable::class)->create(['name:de' => 'Erbsen']); - static::assertEquals('de', $vegetable->getTranslation('ch')->locale); + self::assertEquals('de', $vegetable->getTranslation('ch')->locale); } /** @test */ @@ -300,7 +300,7 @@ public function useTranslationFallback_overrides_configuration(): void $vegetable = factory(Vegetable::class)->create(['name:en' => 'Peas']); $vegetable->useTranslationFallback = false; - static::assertNull($vegetable->getTranslation('ch')); + self::assertNull($vegetable->getTranslation('ch')); } /** @test */ @@ -310,7 +310,7 @@ public function it_returns_null_if_fallback_is_not_defined(): void $vegetable = factory(Vegetable::class)->create(['name:en' => 'Peas']); - static::assertNull($vegetable->getTranslation('pl', true)); + self::assertNull($vegetable->getTranslation('pl', true)); } /** @test */ @@ -321,11 +321,11 @@ public function it_fills_a_non_default_language_with_fallback_set(): void $vegetable = new Vegetable(); $vegetable->fill([ 'quantity' => 5, - 'en' => ['name' => 'Peas'], - 'de' => ['name' => 'Erbsen'], + 'en' => ['name' => 'Peas'], + 'de' => ['name' => 'Erbsen'], ]); - static::assertEquals('Peas', $vegetable->translate('en')->name); + self::assertEquals('Peas', $vegetable->translate('en')->name); } /** @test */ @@ -337,7 +337,7 @@ public function it_creates_a_new_translation(): void $vegetable->getNewTranslation('en')->name = 'Peas'; $vegetable->save(); - static::assertEquals('Peas', $vegetable->translate('en')->name); + self::assertEquals('Peas', $vegetable->translate('en')->name); } /** @test */ @@ -345,7 +345,7 @@ public function the_locale_key_is_locale_by_default(): void { $vegetable = new Vegetable(); - static::assertEquals('locale', $vegetable->getLocaleKey()); + self::assertEquals('locale', $vegetable->getLocaleKey()); } /** @test */ @@ -354,7 +354,7 @@ public function the_locale_key_can_be_overridden_in_configuration(): void $this->app->make('config')->set('translatable.locale_key', 'language_id'); $vegetable = new Vegetable(); - static::assertEquals('language_id', $vegetable->getLocaleKey()); + self::assertEquals('language_id', $vegetable->getLocaleKey()); } /** @test */ @@ -362,7 +362,7 @@ public function the_locale_key_can_be_customized_per_model(): void { $vegetable = new Vegetable(); $vegetable->localeKey = 'language_id'; - static::assertEquals('language_id', $vegetable->getLocaleKey()); + self::assertEquals('language_id', $vegetable->getLocaleKey()); } public function test_the_translation_model_can_be_customized(): void @@ -373,16 +373,16 @@ public function test_the_translation_model_can_be_customized(): void 'name:en' => 'Spain', 'name:de' => 'Spanien', ]); - static::assertTrue($country->exists()); - static::assertEquals($country->translate('en')->name, 'Spain'); - static::assertEquals($country->translate('de')->name, 'Spanien'); + self::assertTrue($country->exists()); + self::assertEquals($country->translate('en')->name, 'Spain'); + self::assertEquals($country->translate('de')->name, 'Spanien'); CountryStrict::reguard(); } /** @test */ public function it_reads_the_configuration(): void { - static::assertEquals('Translation', $this->app->make('config')->get('translatable.translation_suffix')); + self::assertEquals('Translation', $this->app->make('config')->get('translatable.translation_suffix')); } /** @test */ @@ -390,7 +390,7 @@ public function getting_translation_does_not_create_translation(): void { $vegetable = factory(Vegetable::class)->create(); - static::assertNull($vegetable->getTranslation('en', false)); + self::assertNull($vegetable->getTranslation('en', false)); } /** @test */ @@ -399,17 +399,17 @@ public function getting_translated_field_does_not_create_translation(): void $this->app->setLocale('en'); $vegetable = factory(Vegetable::class)->create(); - static::assertNull($vegetable->getTranslation('en')); + self::assertNull($vegetable->getTranslation('en')); } /** @test */ public function it_has_methods_that_return_always_a_translation(): void { $vegetable = factory(Vegetable::class)->create(); - static::assertEquals('abc', $vegetable->translateOrNew('abc')->locale); + self::assertEquals('abc', $vegetable->translateOrNew('abc')->locale); $this->app->setLocale('xyz'); - static::assertEquals('xyz', $vegetable->translateOrNew()->locale); + self::assertEquals('xyz', $vegetable->translateOrNew()->locale); } /** @test */ @@ -421,7 +421,7 @@ public function it_throws_an_exception_if_translation_does_not_exist(): void $vegetable = Vegetable::create([ 'en' => ['name' => 'Peas'], ]); - static::assertEquals('en', $vegetable->translateOrFail('en')->locale); + self::assertEquals('en', $vegetable->translateOrFail('en')->locale); $vegetable->translateOrFail('xyz'); } @@ -431,8 +431,8 @@ public function it_returns_if_attribute_is_translated(): void { $vegetable = new Vegetable(); - static::assertTrue($vegetable->isTranslationAttribute('name')); - static::assertFalse($vegetable->isTranslationAttribute('some-field')); + self::assertTrue($vegetable->isTranslationAttribute('name')); + self::assertFalse($vegetable->isTranslationAttribute('some-field')); } /** @test */ @@ -441,7 +441,7 @@ public function config_overrides_apps_locale(): void $veegtable = factory(Vegetable::class)->create(['name:de' => 'Erbsen']); App::make('config')->set('translatable.locale', 'de'); - static::assertEquals('Erbsen', $veegtable->name); + self::assertEquals('Erbsen', $veegtable->name); } /** @test */ @@ -450,14 +450,14 @@ public function locales_as_array_keys_are_properly_detected(): void $this->app->config->set('translatable.locales', ['en' => ['US', 'GB']]); $vegetable = Vegetable::create([ - 'en' => ['name' => 'Peas'], + 'en' => ['name' => 'Peas'], 'en-US' => ['name' => 'US Peas'], 'en-GB' => ['name' => 'GB Peas'], ]); - static::assertEquals('Peas', $vegetable->getTranslation('en')->name); - static::assertEquals('GB Peas', $vegetable->getTranslation('en-GB')->name); - static::assertEquals('US Peas', $vegetable->getTranslation('en-US')->name); + self::assertEquals('Peas', $vegetable->getTranslation('en')->name); + self::assertEquals('GB Peas', $vegetable->getTranslation('en-GB')->name); + self::assertEquals('US Peas', $vegetable->getTranslation('en-US')->name); } /** @test */ @@ -470,7 +470,7 @@ public function locale_separator_can_be_configured(): void 'en_GB' => ['name' => 'Peas'], ]); - static::assertEquals('Peas', $vegetable->getTranslation('en_GB')->name); + self::assertEquals('Peas', $vegetable->getTranslation('en_GB')->name); } /** @test */ @@ -483,12 +483,12 @@ public function fallback_for_country_based_locales(): void $this->app->make('translatable.locales')->load(); $vegetable = factory(Vegetable::class)->create([ - 'fr' => ['name' => 'Frites'], + 'fr' => ['name' => 'Frites'], 'en-GB' => ['name' => 'Chips'], - 'en' => ['name' => 'French fries'], + 'en' => ['name' => 'French fries'], ]); - static::assertEquals('French fries', $vegetable->getTranslation('en-US')->name); + self::assertEquals('French fries', $vegetable->getTranslation('en-US')->name); } /** @test */ @@ -501,11 +501,11 @@ public function fallback_for_country_based_locales_with_no_base_locale(): void $this->app->make('translatable.locales')->load(); $vegetable = factory(Vegetable::class)->create([ - 'en' => ['name' => 'Chips'], + 'en' => ['name' => 'Chips'], 'pt-PT' => ['name' => 'Batatas fritas'], ]); - static::assertEquals('Chips', $vegetable->getTranslation('pt-BR')->name); + self::assertEquals('Chips', $vegetable->getTranslation('pt-BR')->name); } /** @test */ @@ -520,7 +520,7 @@ public function to_array_and_fallback_with_country_based_locales_enabled(): void $vegetable = factory(Vegetable::class)->create(['name:fr' => 'Frites']); - static::assertEquals('Frites', $vegetable['name']); + self::assertEquals('Frites', $vegetable['name']); } /** @test */ @@ -531,7 +531,7 @@ public function it_skips_translations_in_to_array_when_config_is_set(): void factory(Vegetable::class)->create(['name' => 'Peas']); $vegetable = Vegetable::first()->toArray(); - static::assertFalse(isset($vegetable['name'])); + self::assertFalse(isset($vegetable['name'])); } /** @test */ @@ -542,7 +542,7 @@ public function it_returns_translations_in_to_array_when_config_is_set_but_trans $vegetable = Vegetable::with('translations')->first()->toArray(); - static::assertTrue(isset($vegetable['name'])); + self::assertTrue(isset($vegetable['name'])); } /** @test */ @@ -551,7 +551,7 @@ public function it_should_mutate_the_translated_attribute_if_a_mutator_is_set_on $person = new Person(['name' => 'john doe']); $person->save(); $person = Person::find(1); - static::assertEquals('John Doe', $person->name); + self::assertEquals('John Doe', $person->name); } /** @test */ @@ -559,11 +559,11 @@ public function it_deletes_all_translations(): void { $vegetable = factory(Vegetable::class)->create(['name:es' => 'Guisantes', 'name:en' => 'Peas']); - static::assertEquals(2, count($vegetable->translations)); + self::assertEquals(2, count($vegetable->translations)); $vegetable->deleteTranslations(); - static::assertEquals(0, count($vegetable->translations)); + self::assertEquals(0, count($vegetable->translations)); } /** @test */ @@ -571,11 +571,11 @@ public function it_deletes_translations_for_given_locales(): void { $vegetable = factory(Vegetable::class)->create(['name:es' => 'Guisantes', 'name:en' => 'Peas']); - static::assertEquals(2, count($vegetable->translations)); + self::assertEquals(2, count($vegetable->translations)); $vegetable->deleteTranslations('es'); - static::assertEquals(1, count($vegetable->translations)); + self::assertEquals(1, count($vegetable->translations)); } /** @test */ @@ -583,11 +583,11 @@ public function passing_an_empty_array_should_not_delete_translations(): void { $vegetable = factory(Vegetable::class)->create(['name:es' => 'Guisantes', 'name:en' => 'Peas']); - static::assertEquals(2, count($vegetable->translations)); + self::assertEquals(2, count($vegetable->translations)); $vegetable->deleteTranslations([]); - static::assertEquals(2, count($vegetable->translations)); + self::assertEquals(2, count($vegetable->translations)); } /** @test */ @@ -598,13 +598,13 @@ public function fill_with_translation_key(): void 'name:en' => 'Peas', 'name:de' => 'Erbsen', ]); - static::assertEquals('Peas', $vegetable->translate('en')->name); - static::assertEquals('Erbsen', $vegetable->translate('de')->name); + self::assertEquals('Peas', $vegetable->translate('en')->name); + self::assertEquals('Erbsen', $vegetable->translate('de')->name); $vegetable->save(); $vegetable = Vegetable::first(); - static::assertEquals('Peas', $vegetable->translate('en')->name); - static::assertEquals('Erbsen', $vegetable->translate('de')->name); + self::assertEquals('Peas', $vegetable->translate('en')->name); + self::assertEquals('Erbsen', $vegetable->translate('de')->name); } /** @test */ @@ -615,18 +615,18 @@ public function it_uses_the_default_locale_from_the_model(): void 'name:en' => 'Peas', 'name:fr' => 'Pois', ]); - static::assertEquals('Peas', $vegetable->name); + self::assertEquals('Peas', $vegetable->name); $vegetable->setDefaultLocale('fr'); - static::assertEquals('Pois', $vegetable->name); + self::assertEquals('Pois', $vegetable->name); $vegetable->setDefaultLocale(null); $vegetable->save(); $vegetable = Vegetable::first(); - static::assertEquals('Peas', $vegetable->name); + self::assertEquals('Peas', $vegetable->name); $vegetable->setDefaultLocale('fr'); - static::assertEquals('Pois', $vegetable->name); + self::assertEquals('Pois', $vegetable->name); } /** @test */ @@ -643,19 +643,19 @@ public function replicate_entity(): void $replicated = $vegetable->replicateWithTranslations(); $replicated->save(); - static::assertNotNull($replicated->identity); - static::assertNotEquals($replicated->identity, $vegetable->identity); - static::assertEquals($replicated->translate('fr')->name, $vegetable->translate('fr')->name); - static::assertEquals($replicated->translate('en')->name, $vegetable->translate('en')->name); - static::assertEquals($replicated->translate('de')->name, $vegetable->translate('de')->name); + self::assertNotNull($replicated->identity); + self::assertNotEquals($replicated->identity, $vegetable->identity); + self::assertEquals($replicated->translate('fr')->name, $vegetable->translate('fr')->name); + self::assertEquals($replicated->translate('en')->name, $vegetable->translate('en')->name); + self::assertEquals($replicated->translate('de')->name, $vegetable->translate('de')->name); - static::assertNotNull($replicated->translate('fr')->vegetable_identity); - static::assertNotEquals($replicated->translate('fr')->vegetable_identity, $vegetable->identity); - static::assertEquals($replicated->translate('fr')->vegetable_identity, $replicated->identity); - static::assertNotEquals($replicated->translate('en')->vegetable_identity, $vegetable->identity); - static::assertEquals($replicated->translate('en')->vegetable_identity, $replicated->identity); - static::assertNotEquals($replicated->translate('de')->vegetable_identity, $vegetable->identity); - static::assertEquals($replicated->translate('de')->vegetable_identity, $replicated->identity); + self::assertNotNull($replicated->translate('fr')->vegetable_identity); + self::assertNotEquals($replicated->translate('fr')->vegetable_identity, $vegetable->identity); + self::assertEquals($replicated->translate('fr')->vegetable_identity, $replicated->identity); + self::assertNotEquals($replicated->translate('en')->vegetable_identity, $vegetable->identity); + self::assertEquals($replicated->translate('en')->vegetable_identity, $replicated->identity); + self::assertNotEquals($replicated->translate('de')->vegetable_identity, $vegetable->identity); + self::assertEquals($replicated->translate('de')->vegetable_identity, $replicated->identity); } /** @test */ @@ -667,7 +667,7 @@ public function can_get_translations_as_array(): void 'name:de' => 'Erbsen', ]); - static::assertEquals([ + self::assertEquals([ 'de' => ['name' => 'Erbsen'], 'en' => ['name' => 'Peas'], 'fr' => ['name' => 'Pois'], @@ -681,17 +681,17 @@ public function fill_will_ignore_unkown_locales(): void $vegetable = new Vegetable(); $vegetable->fill([ - 'en' => ['name' => 'Peas'], - 'ua' => ['name' => 'Unkown'], + 'en' => ['name' => 'Peas'], + 'ua' => ['name' => 'Unkown'], ]); $vegetable->save(); - static::assertDatabaseHas('vegetable_translations', [ + self::assertDatabaseHas('vegetable_translations', [ 'locale' => 'en', 'name' => 'Peas', ]); - static::assertDatabaseMissing('vegetable_translations', ['locale' => 'ua']); + self::assertDatabaseMissing('vegetable_translations', ['locale' => 'ua']); } /** @test */ @@ -707,12 +707,12 @@ public function fill_will_ignore_unkown_locales_with_translations(): void $vegetable->save(); - static::assertDatabaseHas('vegetable_translations', [ + self::assertDatabaseHas('vegetable_translations', [ 'locale' => 'en', 'name' => 'Peas', ]); - static::assertDatabaseMissing('vegetable_translations', ['locale' => 'ua']); + self::assertDatabaseMissing('vegetable_translations', ['locale' => 'ua']); } /** @test */ @@ -728,9 +728,9 @@ public function it_uses_fallback_locale_if_default_is_empty(): void ]); $this->app->setLocale('en'); - static::assertEquals('Peas', $vegetable->name); + self::assertEquals('Peas', $vegetable->name); $this->app->setLocale('fr'); - static::assertEquals('Peas', $vegetable->name); + self::assertEquals('Peas', $vegetable->name); } /** @test */ @@ -747,10 +747,10 @@ public function it_uses_value_when_fallback_is_not_available(): void // verify translated attributed is correctly returned when empty (non-existing fallback is ignored) $this->app->setLocale('en'); - static::assertEquals('', $vegetable->getAttribute('name')); + self::assertEquals('', $vegetable->getAttribute('name')); $this->app->setLocale('de'); - static::assertEquals('Erbsen', $vegetable->getAttribute('name')); + self::assertEquals('Erbsen', $vegetable->getAttribute('name')); } /** @test */ @@ -759,7 +759,7 @@ public function empty_translated_attribute(): void $this->app->setLocale('invalid'); $vegetable = factory(Vegetable::class)->create(); - static::assertNull($vegetable->name); + self::assertNull($vegetable->name); } /** @test */ @@ -771,6 +771,7 @@ public function numeric_translated_attribute(): void $vegetable = new class extends Vegetable { protected $table = 'vegetables'; + public $translationModel = VegetableTranslation::class; protected function isEmptyTranslatableAttribute(string $key, $value): bool @@ -791,10 +792,10 @@ protected function isEmptyTranslatableAttribute(string $key, $value): bool $vegetable->save(); $this->app->setLocale('en'); - static::assertSame('0', $vegetable->name); + self::assertSame('0', $vegetable->name); $this->app->setLocale('fr'); - static::assertSame('1', $vegetable->name); + self::assertSame('1', $vegetable->name); } /** @test */ @@ -809,8 +810,8 @@ public function translation_relation(): void 'name:fr' => 'Pois', ]); - static::assertInstanceOf(VegetableTranslation::class, $peas->translation); - static::assertEquals('en', $peas->translation->locale); + self::assertInstanceOf(VegetableTranslation::class, $peas->translation); + self::assertEquals('en', $peas->translation->locale); } /** @test */ @@ -822,8 +823,8 @@ public function translation_relation_can_use_fallback_locale(): void $peas = factory(Vegetable::class)->create(['name:fr' => 'Pois']); - static::assertInstanceOf(VegetableTranslation::class, $peas->translation); - static::assertEquals('fr', $peas->translation->locale); + self::assertInstanceOf(VegetableTranslation::class, $peas->translation); + self::assertEquals('fr', $peas->translation->locale); } /** @test */ @@ -835,7 +836,7 @@ public function translation_relation_returns_null_if_no_available_locale_was_fou $peas = factory(Vegetable::class)->create(['name:en' => 'Peas']); - static::assertNull($peas->translation); + self::assertNull($peas->translation); } /** @test */ @@ -860,9 +861,9 @@ public function can_fill_conflicting_attribute_locale(): void $country->save(); - static::assertEquals(100, $country->getKey()); - static::assertEquals('id:my country', $country->getTranslation('id', false)->name); - static::assertEquals('en:my country', $country->getTranslation('en', false)->name); + self::assertEquals(100, $country->getKey()); + self::assertEquals('id:my country', $country->getTranslation('id', false)->name); + self::assertEquals('en:my country', $country->getTranslation('en', false)->name); } /** @test */ @@ -904,17 +905,17 @@ public function it_returns_first_existing_translation_as_fallback(): void 'name' => 'Griechenland', ]); - static::assertNull($country->getTranslation(null, false)); + self::assertNull($country->getTranslation(null, false)); // returns first existing locale $translation = $country->getTranslation(); - static::assertInstanceOf(CountryTranslation::class, $translation); - static::assertEquals('en', $translation->locale); + self::assertInstanceOf(CountryTranslation::class, $translation); + self::assertEquals('en', $translation->locale); // still returns simple locale for country based locale $translation = $country->getTranslation($helper->getCountryLocale('de', 'AT')); - static::assertInstanceOf(CountryTranslation::class, $translation); - static::assertEquals('de', $translation->locale); + self::assertInstanceOf(CountryTranslation::class, $translation); + self::assertEquals('de', $translation->locale); $this->app->make('config')->set('translatable.locales', [ 'xyz', @@ -930,16 +931,16 @@ public function it_returns_first_existing_translation_as_fallback(): void // returns simple locale before country based locale $translation = $country->getTranslation(); - static::assertInstanceOf(CountryTranslation::class, $translation); - static::assertEquals('de', $translation->locale); + self::assertInstanceOf(CountryTranslation::class, $translation); + self::assertEquals('de', $translation->locale); $country->translations()->where('locale', 'de')->delete(); $country->unsetRelation('translations'); // returns country based locale before next simple one $translation = $country->getTranslation(); - static::assertInstanceOf(CountryTranslation::class, $translation); - static::assertEquals($helper->getCountryLocale('de', 'DE'), $translation->locale); + self::assertInstanceOf(CountryTranslation::class, $translation); + self::assertEquals($helper->getCountryLocale('de', 'DE'), $translation->locale); } /** @test */ @@ -953,13 +954,13 @@ public function it_uses_translation_relation_if_locale_matches(): void $country = Country::first(); $country->load('translation'); - static::assertTrue($country->relationLoaded('translation')); - static::assertFalse($country->relationLoaded('translations')); + self::assertTrue($country->relationLoaded('translation')); + self::assertFalse($country->relationLoaded('translations')); $translation = $country->getTranslation(); - static::assertInstanceOf(CountryTranslation::class, $translation); - static::assertEquals('de', $translation->locale); - static::assertFalse($country->relationLoaded('translations')); + self::assertInstanceOf(CountryTranslation::class, $translation); + self::assertEquals('de', $translation->locale); + self::assertFalse($country->relationLoaded('translations')); } /** @test */ @@ -973,14 +974,14 @@ public function it_uses_translations_relation_if_locale_does_not_match(): void $country = Country::first(); $country->load('translation'); - static::assertTrue($country->relationLoaded('translation')); - static::assertFalse($country->relationLoaded('translations')); + self::assertTrue($country->relationLoaded('translation')); + self::assertFalse($country->relationLoaded('translations')); $this->app->setLocale('en'); $translation = $country->getTranslation(); - static::assertInstanceOf(CountryTranslation::class, $translation); - static::assertEquals('en', $translation->locale); - static::assertTrue($country->relationLoaded('translations')); + self::assertInstanceOf(CountryTranslation::class, $translation); + self::assertEquals('en', $translation->locale); + self::assertTrue($country->relationLoaded('translations')); } /** @test */ @@ -992,14 +993,14 @@ public function it_does_not_load_translation_relation_if_not_already_loaded(): v /** @var Country $country */ $country = Country::first(); - static::assertFalse($country->relationLoaded('translation')); - static::assertFalse($country->relationLoaded('translations')); + self::assertFalse($country->relationLoaded('translation')); + self::assertFalse($country->relationLoaded('translations')); $translation = $country->getTranslation(); - static::assertInstanceOf(CountryTranslation::class, $translation); - static::assertEquals('de', $translation->locale); - static::assertFalse($country->relationLoaded('translation')); - static::assertTrue($country->relationLoaded('translations')); + self::assertInstanceOf(CountryTranslation::class, $translation); + self::assertEquals('de', $translation->locale); + self::assertFalse($country->relationLoaded('translation')); + self::assertTrue($country->relationLoaded('translations')); } /** @test */ diff --git a/tests/ValidationTest.php b/tests/ValidationTest.php index 889fef4..b3e7179 100644 --- a/tests/ValidationTest.php +++ b/tests/ValidationTest.php @@ -21,7 +21,7 @@ public function it_does_not_touch_untranslated_keys(): void ], ]; - static::assertEquals($rules, RuleFactory::make($rules)); + self::assertEquals($rules, RuleFactory::make($rules)); } /** @test */ @@ -32,7 +32,7 @@ public function format_array_it_replaces_single_key(): void '%content%' => 'required', ]; - static::assertEquals([ + self::assertEquals([ 'title' => 'required', 'en.content' => 'required', 'de.content' => 'required', @@ -49,7 +49,7 @@ public function format_array_it_replaces_sub_key(): void 'translations.%content%' => 'required', ]; - static::assertEquals([ + self::assertEquals([ 'title' => 'required', 'translations.en.content' => 'required', 'translations.de.content' => 'required', @@ -66,7 +66,7 @@ public function format_array_it_replaces_middle_key(): void 'translations.%content%.body' => 'required', ]; - static::assertEquals([ + self::assertEquals([ 'title' => 'required', 'translations.en.content.body' => 'required', 'translations.de.content.body' => 'required', @@ -83,7 +83,7 @@ public function format_array_it_replaces_middle_key_with_custom_prefix(): void 'translations.{content%.body' => 'required', ]; - static::assertEquals([ + self::assertEquals([ 'title' => 'required', 'translations.en.content.body' => 'required', 'translations.de.content.body' => 'required', @@ -100,7 +100,7 @@ public function format_array_it_replaces_middle_key_with_custom_suffix(): void 'translations.%content}.body' => 'required', ]; - static::assertEquals([ + self::assertEquals([ 'title' => 'required', 'translations.en.content.body' => 'required', 'translations.de.content.body' => 'required', @@ -117,7 +117,7 @@ public function format_array_it_replaces_middle_key_with_custom_delimiters(): vo 'translations.{content}.body' => 'required', ]; - static::assertEquals([ + self::assertEquals([ 'title' => 'required', 'translations.en.content.body' => 'required', 'translations.de.content.body' => 'required', @@ -134,7 +134,7 @@ public function format_array_it_replaces_middle_key_with_custom_regex_delimiters 'translations.$content$.body' => 'required', ]; - static::assertEquals([ + self::assertEquals([ 'title' => 'required', 'translations.en.content.body' => 'required', 'translations.de.content.body' => 'required', @@ -158,7 +158,7 @@ public function format_array_it_uses_config_as_default(): void '%content%' => 'required', ]; - static::assertEquals([ + self::assertEquals([ 'title' => 'required', '%content%' => 'required', 'en.content' => 'required', @@ -176,7 +176,7 @@ public function format_key_it_replaces_single_key(): void '%content%' => 'required', ]; - static::assertEquals([ + self::assertEquals([ 'title' => 'required', 'content:en' => 'required', 'content:de' => 'required', @@ -193,7 +193,7 @@ public function format_key_it_replaces_sub_key(): void 'translations.%content%' => 'required', ]; - static::assertEquals([ + self::assertEquals([ 'title' => 'required', 'translations.content:en' => 'required', 'translations.content:de' => 'required', @@ -210,7 +210,7 @@ public function format_key_it_replaces_middle_key(): void 'translations.%content%.body' => 'required', ]; - static::assertEquals([ + self::assertEquals([ 'title' => 'required', 'translations.content:en.body' => 'required', 'translations.content:de.body' => 'required', @@ -234,7 +234,7 @@ public function format_key_it_uses_config_as_default(): void '%content%' => 'required', ]; - static::assertEquals([ + self::assertEquals([ 'title' => 'required', '%content%' => 'required', 'content:en' => 'required', @@ -252,7 +252,7 @@ public function it_replaces_key_with_custom_locales(): void 'translations.%content%.body' => 'required', ]; - static::assertEquals([ + self::assertEquals([ 'title' => 'required', 'translations.en.content.body' => 'required', 'translations.de.content.body' => 'required', @@ -287,7 +287,7 @@ public function format_array_it_replaces_single_rule(): void '%content%' => 'required_with:%title%', ]; - static::assertEquals([ + self::assertEquals([ 'en.title' => 'sometimes|string', 'de.title' => 'sometimes|string', 'de-DE.title' => 'sometimes|string', @@ -308,7 +308,7 @@ public function format_array_it_replaces_imploded_rules(): void '%content%' => 'required_with:%title%|string', ]; - static::assertEquals([ + self::assertEquals([ 'en.title' => 'sometimes|string', 'de.title' => 'sometimes|string', 'de-DE.title' => 'sometimes|string', @@ -329,7 +329,7 @@ public function format_array_it_replaces_array_of_rules(): void '%content%' => ['required_with:%title%', 'string'], ]; - static::assertEquals([ + self::assertEquals([ 'en.title' => 'sometimes|string', 'de.title' => 'sometimes|string', 'de-DE.title' => 'sometimes|string', @@ -354,11 +354,11 @@ public function format_array_it_does_not_touch_non_string_rule(): void $formattedRules = RuleFactory::make($rules, RuleFactory::FORMAT_ARRAY); - static::assertEquals('required', $formattedRules['title']); - static::assertInstanceOf(RequiredIf::class, $formattedRules['en.content']); - static::assertInstanceOf(RequiredIf::class, $formattedRules['de.content']); - static::assertInstanceOf(RequiredIf::class, $formattedRules['de-DE.content']); - static::assertInstanceOf(RequiredIf::class, $formattedRules['de-AT.content']); + self::assertEquals('required', $formattedRules['title']); + self::assertInstanceOf(RequiredIf::class, $formattedRules['en.content']); + self::assertInstanceOf(RequiredIf::class, $formattedRules['de.content']); + self::assertInstanceOf(RequiredIf::class, $formattedRules['de-DE.content']); + self::assertInstanceOf(RequiredIf::class, $formattedRules['de-AT.content']); } /** @test */ @@ -376,15 +376,15 @@ public function format_array_it_does_not_touch_non_string_rule_in_array(): void $formattedRules = RuleFactory::make($rules, RuleFactory::FORMAT_ARRAY); - static::assertEquals('required', $formattedRules['title']); - static::assertEquals('required_with:en.title', $formattedRules['en.content'][0]); - static::assertEquals('required_with:de.title', $formattedRules['de.content'][0]); - static::assertEquals('required_with:de-DE.title', $formattedRules['de-DE.content'][0]); - static::assertEquals('required_with:de-AT.title', $formattedRules['de-AT.content'][0]); - static::assertInstanceOf(RequiredIf::class, $formattedRules['en.content'][1]); - static::assertInstanceOf(RequiredIf::class, $formattedRules['de.content'][1]); - static::assertInstanceOf(RequiredIf::class, $formattedRules['de-DE.content'][1]); - static::assertInstanceOf(RequiredIf::class, $formattedRules['de-AT.content'][1]); + self::assertEquals('required', $formattedRules['title']); + self::assertEquals('required_with:en.title', $formattedRules['en.content'][0]); + self::assertEquals('required_with:de.title', $formattedRules['de.content'][0]); + self::assertEquals('required_with:de-DE.title', $formattedRules['de-DE.content'][0]); + self::assertEquals('required_with:de-AT.title', $formattedRules['de-AT.content'][0]); + self::assertInstanceOf(RequiredIf::class, $formattedRules['en.content'][1]); + self::assertInstanceOf(RequiredIf::class, $formattedRules['de.content'][1]); + self::assertInstanceOf(RequiredIf::class, $formattedRules['de-DE.content'][1]); + self::assertInstanceOf(RequiredIf::class, $formattedRules['de-AT.content'][1]); } /** @test */ @@ -395,7 +395,7 @@ public function format_key_it_replaces_single_rule(): void '%content%' => 'required_with:"%title%"', ]; - static::assertEquals([ + self::assertEquals([ 'title:en' => 'sometimes|string', 'title:de' => 'sometimes|string', 'title:de-DE' => 'sometimes|string', @@ -416,7 +416,7 @@ public function format_key_it_replaces_imploded_rules(): void '%content%' => 'required_with:"%title%"|string', ]; - static::assertEquals([ + self::assertEquals([ 'title:en' => 'sometimes|string', 'title:de' => 'sometimes|string', 'title:de-DE' => 'sometimes|string', @@ -437,7 +437,7 @@ public function format_key_it_replaces_array_of_rules(): void '%content%' => ['required_with:"%title%"', 'string'], ]; - static::assertEquals([ + self::assertEquals([ 'title:en' => 'sometimes|string', 'title:de' => 'sometimes|string', 'title:de-DE' => 'sometimes|string', @@ -462,11 +462,11 @@ public function format_key_it_does_not_touch_non_string_rule(): void $formattedRules = RuleFactory::make($rules, RuleFactory::FORMAT_KEY); - static::assertEquals('required', $formattedRules['title']); - static::assertInstanceOf(RequiredIf::class, $formattedRules['content:en']); - static::assertInstanceOf(RequiredIf::class, $formattedRules['content:de']); - static::assertInstanceOf(RequiredIf::class, $formattedRules['content:de-DE']); - static::assertInstanceOf(RequiredIf::class, $formattedRules['content:de-AT']); + self::assertEquals('required', $formattedRules['title']); + self::assertInstanceOf(RequiredIf::class, $formattedRules['content:en']); + self::assertInstanceOf(RequiredIf::class, $formattedRules['content:de']); + self::assertInstanceOf(RequiredIf::class, $formattedRules['content:de-DE']); + self::assertInstanceOf(RequiredIf::class, $formattedRules['content:de-AT']); } /** @test */ @@ -484,15 +484,15 @@ public function format_key_it_does_not_touch_non_string_rule_in_array(): void $formattedRules = RuleFactory::make($rules, RuleFactory::FORMAT_KEY); - static::assertEquals('required', $formattedRules['title']); - static::assertEquals('required_with:"title:en"', $formattedRules['content:en'][0]); - static::assertEquals('required_with:"title:de"', $formattedRules['content:de'][0]); - static::assertEquals('required_with:"title:de-DE"', $formattedRules['content:de-DE'][0]); - static::assertEquals('required_with:"title:de-AT"', $formattedRules['content:de-AT'][0]); - static::assertInstanceOf(RequiredIf::class, $formattedRules['content:en'][1]); - static::assertInstanceOf(RequiredIf::class, $formattedRules['content:de'][1]); - static::assertInstanceOf(RequiredIf::class, $formattedRules['content:de-DE'][1]); - static::assertInstanceOf(RequiredIf::class, $formattedRules['content:de-AT'][1]); + self::assertEquals('required', $formattedRules['title']); + self::assertEquals('required_with:"title:en"', $formattedRules['content:en'][0]); + self::assertEquals('required_with:"title:de"', $formattedRules['content:de'][0]); + self::assertEquals('required_with:"title:de-DE"', $formattedRules['content:de-DE'][0]); + self::assertEquals('required_with:"title:de-AT"', $formattedRules['content:de-AT'][0]); + self::assertInstanceOf(RequiredIf::class, $formattedRules['content:en'][1]); + self::assertInstanceOf(RequiredIf::class, $formattedRules['content:de'][1]); + self::assertInstanceOf(RequiredIf::class, $formattedRules['content:de-DE'][1]); + self::assertInstanceOf(RequiredIf::class, $formattedRules['content:de-AT'][1]); } protected function setUp(): void From 79f464603d751a2070218a38ec66fffe8d347754 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 17 Apr 2024 12:55:24 +0200 Subject: [PATCH 06/31] upgrade phpunit --- .github/workflows/phpunit.yml | 2 +- phpunit.xml.dist | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 8786e2d..9a49f3e 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -11,7 +11,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: - fail-fast: true + fail-fast: false matrix: php: [8.0, 8.1, '8.2'] laravel: ['8.*', '9.*', '10.*', '11.*'] diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5b011d3..2a5dcd9 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,13 +1,13 @@ @@ -17,11 +17,11 @@ ./tests/models/ - - + + ./src/Translatable/ - - + + From 454fe456afba66488148f5e529799ba8c5f9556d Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 17 Apr 2024 13:21:39 +0200 Subject: [PATCH 07/31] reduce supported versions --- .github/workflows/phpunit.yml | 10 +++------- composer.json | 12 ++++++------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 9a49f3e..d7f464c 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -13,15 +13,11 @@ jobs: strategy: fail-fast: false matrix: - php: [8.0, 8.1, '8.2'] - laravel: ['8.*', '9.*', '10.*', '11.*'] + php: ['8.1', '8.2'] + laravel: ['10.*', '11.*'] dependency-version: [prefer-stable] os: [ubuntu-latest] exclude: - - laravel: 10.* - php: 8.0 - - laravel: 11.* - php: 8.0 - laravel: 11.* php: 8.1 @@ -29,7 +25,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4.1.2 + uses: actions/checkout@v4 - name: Cache dependencies uses: actions/cache@v4 diff --git a/composer.json b/composer.json index 9c08161..0de7d76 100644 --- a/composer.json +++ b/composer.json @@ -30,17 +30,17 @@ "docs": "https://docs.astrotomic.info/laravel-translatable" }, "require": { - "php": "^8.0", - "illuminate/contracts": "^8.0 || ^9.0 || ^10.0 || ^11.0", - "illuminate/database": "^8.0 || ^9.0 || ^10.0 || ^11.0", - "illuminate/support": "^8.0 || ^9.0 || ^10.0 || ^11.0" + "php": "^8.1", + "illuminate/contracts": "^10.0 || ^11.0", + "illuminate/database": "^10.0 || ^11.0", + "illuminate/support": "^10.0 || ^11.0" }, "require-dev": { "laravel/legacy-factories": "^1.0.4", "laravel/pint": "^1.15", "mockery/mockery": "^1.3.3", - "orchestra/testbench": "^6.0 || ^7.0 || ^8.0 || ^9.0", - "phpunit/phpunit": "^9.0 || ^10.5" + "orchestra/testbench": "^8.0 || ^9.0", + "phpunit/phpunit": "^10.5" }, "minimum-stability": "dev", "prefer-stable": true, From 0916bcea9694547816135cd47399fb25a2cd093e Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 17 Apr 2024 13:26:01 +0200 Subject: [PATCH 08/31] fix namespace --- .github/workflows/phpunit.yml | 12 +----------- README.md | 3 ++- composer.json | 2 +- tests/Eloquent/Country.php | 2 +- tests/Eloquent/CountryStrict.php | 4 ++-- tests/Eloquent/CountryTranslation.php | 2 +- tests/Eloquent/Person.php | 2 +- tests/Eloquent/PersonTranslation.php | 2 +- tests/Eloquent/StrictTranslation.php | 2 +- tests/Eloquent/Vegetable.php | 2 +- tests/Eloquent/VegetableTranslation.php | 2 +- tests/EloquentOverrideTest.php | 4 ++-- tests/LocalesTest.php | 2 +- tests/ScopesTest.php | 6 +++--- tests/TestCase.php | 2 +- tests/TranslatableTest.php | 16 ++++++++-------- tests/ValidationTest.php | 2 +- tests/factories/CountryFactory.php | 2 +- tests/factories/VegetableFactory.php | 2 +- 19 files changed, 31 insertions(+), 40 deletions(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index d7f464c..e963902 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - php: ['8.1', '8.2'] + php: ['8.1', '8.2', '8.3'] laravel: ['10.*', '11.*'] dependency-version: [prefer-stable] os: [ubuntu-latest] @@ -27,16 +27,6 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Cache dependencies - uses: actions/cache@v4 - with: - path: ~/.composer/cache/files - key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} - restore-keys: | - dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer- - dependencies-laravel-${{ matrix.laravel }}-php- - dependencies-laravel- - - name: Setup PHP uses: shivammathur/setup-php@v2 with: diff --git a/README.md b/README.md index 650025f..1ab3305 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,8 @@ If you discover any security related issues, please check [SECURITY](https://git ## Versions | Package | Laravel | PHP | -| :------------------ | :---------------------------- | :-------- | +|:--------------------|:------------------------------|:----------| +| **v11.13 - v11.13** | `10.* / 11.*` | `^8.1` | | **v11.12 - v11.12** | `8.* / 9.* / 10.*` | `^8.0` | | **v11.10 - v11.11** | `8.* / 9.*` | `^8.0` | | **v11.6 - v11.9** | `5.8.* / 6.* / 7.* / 8.*` | `>=7.2` | diff --git a/composer.json b/composer.json index 0de7d76..8f0d4ec 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,7 @@ }, "autoload-dev": { "psr-4": { - "Astrotomic\\Translatable\\Tests\\": "tests/" + "Tests\\": "tests/" } }, "config": { diff --git a/tests/Eloquent/Country.php b/tests/Eloquent/Country.php index 01af2bb..88a4bca 100644 --- a/tests/Eloquent/Country.php +++ b/tests/Eloquent/Country.php @@ -1,6 +1,6 @@ app->make('config')->set('translatable.translation_suffix', 'Trans'); self::assertEquals( - 'Astrotomic\Translatable\Tests\Eloquent\VegetableTrans', + 'Tests\Eloquent\VegetableTrans', (new Vegetable())->getTranslationModelName() ); } diff --git a/tests/ValidationTest.php b/tests/ValidationTest.php index b3e7179..1ffc03f 100644 --- a/tests/ValidationTest.php +++ b/tests/ValidationTest.php @@ -1,6 +1,6 @@ Date: Wed, 17 Apr 2024 11:26:19 +0000 Subject: [PATCH 09/31] Prettified Code! --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1ab3305..b7158c6 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ If you discover any security related issues, please check [SECURITY](https://git ## Versions | Package | Laravel | PHP | -|:--------------------|:------------------------------|:----------| +| :------------------ | :---------------------------- | :-------- | | **v11.13 - v11.13** | `10.* / 11.*` | `^8.1` | | **v11.12 - v11.12** | `8.* / 9.* / 10.*` | `^8.0` | | **v11.10 - v11.11** | `8.* / 9.*` | `^8.0` | From 00433e79fab24b164f57fb038a82c9c8d731f4fb Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 17 Apr 2024 13:29:14 +0200 Subject: [PATCH 10/31] fix phpunit.xml --- phpunit.xml.dist | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 2a5dcd9..a92657e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -11,10 +11,9 @@ > - ./tests/ + ./tests/ ./tests/factories/ - ./tests/migrations/ - ./tests/models/ + ./tests/Eloquent/ From d0f67d9757e610b237a0e29326fb350a486546dd Mon Sep 17 00:00:00 2001 From: Oleksandr Moik Date: Mon, 10 Apr 2023 23:57:11 +0300 Subject: [PATCH 11/31] add idea folders to git ignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index f792fcc..467d3d7 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ /.phpunit.result.cache /build/ /coverage.clover +/.idea +/.vscode +/.fleet From 3dda2bc7e88cde20f5c5298427e68737ad467e33 Mon Sep 17 00:00:00 2001 From: Oleksandr Moik Date: Sun, 17 Mar 2024 22:37:56 +0200 Subject: [PATCH 12/31] l11 --- .github/workflows/phpunit.yml | 28 ++++++++++++++++++++++++---- composer.json | 14 +++++++------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index e963902..540f9f4 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -13,13 +13,32 @@ jobs: strategy: fail-fast: false matrix: - php: ['8.1', '8.2', '8.3'] - laravel: ['10.*', '11.*'] + php: [8.0, 8.1, 8.2, 8.3] + laravel: [8.*, 9.*, 10.*, 11.*] dependency-version: [prefer-stable] os: [ubuntu-latest] + include: + - laravel: '8.*' + phpunit: '9.*' + - laravel: '9.*' + phpunit: '9.*' + - laravel: '10.*' + phpunit: '10.*' + - laravel: '10.*' + phpunit: '10.*' exclude: - - laravel: 11.* - php: 8.1 + - php: '8.0' + laravel: '10.*' + - php: '8.0' + laravel: '11.*' + - php: '8.2' + laravel: '8.*' + - php: '8.3' + laravel: '8.*' + - php: '8.3' + laravel: '9.*' + - php: '8.1' + laravel: '11.*' name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }} @@ -38,6 +57,7 @@ jobs: - name: Install dependencies run: | composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update + composer require "phpunit/phpunit:${{ matrix.phpunit }}" --dev --no-interaction --no-update composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest - name: Execute tests diff --git a/composer.json b/composer.json index 8f0d4ec..48565c1 100644 --- a/composer.json +++ b/composer.json @@ -30,17 +30,17 @@ "docs": "https://docs.astrotomic.info/laravel-translatable" }, "require": { - "php": "^8.1", - "illuminate/contracts": "^10.0 || ^11.0", - "illuminate/database": "^10.0 || ^11.0", - "illuminate/support": "^10.0 || ^11.0" + "php": "^8.0", + "illuminate/contracts": "^8.0 || ^9.0 || ^10.0 || ^11.0", + "illuminate/database": "^8.0 || ^9.0 || ^10.0 || ^11.0", + "illuminate/support": "^8.0 || ^9.0 || ^10.0 || ^11.0" }, "require-dev": { "laravel/legacy-factories": "^1.0.4", - "laravel/pint": "^1.15", + "laravel/pint": "^1.14", "mockery/mockery": "^1.3.3", - "orchestra/testbench": "^8.0 || ^9.0", - "phpunit/phpunit": "^10.5" + "orchestra/testbench": "^6.0 || ^7.0 || ^8.0 || ^9.0", + "phpunit/phpunit": "^9.0 || ^10.0" }, "minimum-stability": "dev", "prefer-stable": true, From de8279c27e363813ac522b5bf2b6d6347417a70b Mon Sep 17 00:00:00 2001 From: Oleksandr Moik Date: Sun, 17 Mar 2024 22:46:39 +0200 Subject: [PATCH 13/31] Switch php_cs to laravel/pint --- .gitattributes | 2 +- pint.json | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 pint.json diff --git a/.gitattributes b/.gitattributes index 65b9655..78cc4c7 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,6 +5,6 @@ /.gitattributes export-ignore /.gitignore export-ignore /.gitbook.yaml export-ignore -/.php_cs export-ignore /.styleci.yml export-ignore /.phpunit.xml.dist export-ignore +/pint.json export-ignore diff --git a/pint.json b/pint.json new file mode 100644 index 0000000..4373f2d --- /dev/null +++ b/pint.json @@ -0,0 +1,29 @@ +{ + "rules": { + "ordered_class_elements": { + "order": [ + "use_trait", + "constant_public", + "constant_protected", + "constant_private", + "property_public", + "property_protected", + "property_private", + "construct", + "method_public_static", + "method_public", + "method_protected_static", + "method_protected", + "method_private_static", + "method_private", + "destruct", + "magic" + ] + }, + "yoda_style": { + "equal": false, + "identical": false, + "less_and_greater": null + } + } +} From 99d8372080dd616da1da46a5d7459f31660d498b Mon Sep 17 00:00:00 2001 From: Oleksandr Moik Date: Sun, 17 Mar 2024 22:46:50 +0200 Subject: [PATCH 14/31] Apply style fixes --- src/Translatable/Traits/Relationship.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Translatable/Traits/Relationship.php b/src/Translatable/Traits/Relationship.php index 606368a..22832dc 100644 --- a/src/Translatable/Traits/Relationship.php +++ b/src/Translatable/Traits/Relationship.php @@ -73,15 +73,15 @@ public function translation(): HasOne }); } + public function translations(): HasMany + { + return $this->hasMany($this->getTranslationModelName(), $this->getTranslationRelationKey()); + } + protected function localeOrFallback() { return $this->useFallback() && ! $this->translations()->where($this->getLocaleKey(), $this->locale())->exists() ? $this->getFallbackLocale() : $this->locale(); } - - public function translations(): HasMany - { - return $this->hasMany($this->getTranslationModelName(), $this->getTranslationRelationKey()); - } } From de560c63bc0c03e7e0e7f53a5e978747252ed0af Mon Sep 17 00:00:00 2001 From: Shift Date: Sun, 17 Mar 2024 20:52:33 +0000 Subject: [PATCH 15/31] Bump PHPUnit dependencies --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 48565c1..9540b3a 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ "laravel/pint": "^1.14", "mockery/mockery": "^1.3.3", "orchestra/testbench": "^6.0 || ^7.0 || ^8.0 || ^9.0", - "phpunit/phpunit": "^9.0 || ^10.0" + "phpunit/phpunit": "^10.0" }, "minimum-stability": "dev", "prefer-stable": true, From a4a1977add95fb6db19896bcafd4e8fe491686ee Mon Sep 17 00:00:00 2001 From: Shift Date: Sun, 17 Mar 2024 20:52:33 +0000 Subject: [PATCH 16/31] Ignore PHPUnit cache folder --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 467d3d7..c9d4490 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ /vendor/ /composer.lock /coverage/ -/.phpunit.result.cache +/.phpunit.cache /build/ /coverage.clover /.idea From 24bf1853dbe9c999ab586d0b28a4d95b34d6f89f Mon Sep 17 00:00:00 2001 From: Shift Date: Sun, 17 Mar 2024 20:52:34 +0000 Subject: [PATCH 17/31] Adopt PHP attributes in test classes --- tests/EloquentOverrideTest.php | 13 ++-- tests/LocalesTest.php | 45 +++++------ tests/ScopesTest.php | 43 ++++++----- tests/TranslatableTest.php | 135 +++++++++++++++++---------------- tests/ValidationTest.php | 51 +++++++------ 5 files changed, 146 insertions(+), 141 deletions(-) diff --git a/tests/EloquentOverrideTest.php b/tests/EloquentOverrideTest.php index 671c36f..4875bff 100644 --- a/tests/EloquentOverrideTest.php +++ b/tests/EloquentOverrideTest.php @@ -2,11 +2,12 @@ namespace Tests; +use PHPUnit\Framework\Attributes\Test; use Tests\Eloquent\Vegetable; final class EloquentOverrideTest extends TestCase { - /** @test */ + #[Test] public function to_array_returns_translated_attributes(): void { $vegetable = factory(Vegetable::class)->make(['name:en' => 'Peas']); @@ -15,7 +16,7 @@ public function to_array_returns_translated_attributes(): void self::assertEquals('Peas', $vegetable->toArray()['name']); } - /** @test */ + #[Test] public function to_array_wont_break_if_no_translations_exist(): void { $vegetable = factory(Vegetable::class)->make(); @@ -23,7 +24,7 @@ public function to_array_wont_break_if_no_translations_exist(): void self::assertIsArray($vegetable->toArray()); } - /** @test */ + #[Test] public function translated_attributes_can_be_accessed_as_properties(): void { $vegetable = factory(Vegetable::class)->make(['name:en' => 'Peas']); @@ -32,7 +33,7 @@ public function translated_attributes_can_be_accessed_as_properties(): void self::assertEquals('Peas', $vegetable->name); } - /** @test */ + #[Test] public function it_can_hide_translated_attributes(): void { $vegetable = factory(Vegetable::class)->make(['name:en' => 'Peas']); @@ -44,7 +45,7 @@ public function it_can_hide_translated_attributes(): void self::assertFalse(isset($vegetable->toArray()['name'])); } - /** @test */ + #[Test] public function it_finds_custom_primary_keys(): void { $vegetable = new Vegetable(); @@ -52,7 +53,7 @@ public function it_finds_custom_primary_keys(): void self::assertEquals('vegetable_identity', $vegetable->getTranslationRelationKey()); } - /** @test */ + #[Test] public function setAttribute_returns_parent_setAttribute(): void { $vegetable = new Vegetable(); diff --git a/tests/LocalesTest.php b/tests/LocalesTest.php index 74c3365..b155ae1 100644 --- a/tests/LocalesTest.php +++ b/tests/LocalesTest.php @@ -2,12 +2,13 @@ namespace Tests; +use PHPUnit\Framework\Attributes\Test; use Astrotomic\Translatable\Exception\LocalesNotDefinedException; use Astrotomic\Translatable\Locales; final class LocalesTest extends TestCase { - /** @test */ + #[Test] public function locales_is_declared_as_a_singleton_instance(): void { $singletonHash = spl_object_hash(app(Locales::class)); @@ -16,7 +17,7 @@ public function locales_is_declared_as_a_singleton_instance(): void self::assertEquals($singletonHash, spl_object_hash($this->app->make(Locales::class))); } - /** @test */ + #[Test] public function it_loads_the_locales_from_the_configuration(): void { $this->app['config']->set('translatable.locales', [ @@ -34,7 +35,7 @@ public function it_loads_the_locales_from_the_configuration(): void self::assertEquals(['de', 'en'], $this->app->make('translatable.locales')->all()); } - /** @test */ + #[Test] public function it_throws_an_exception_if_there_are_no_locales(): void { $this->expectException(LocalesNotDefinedException::class); @@ -43,7 +44,7 @@ public function it_throws_an_exception_if_there_are_no_locales(): void $this->app->make('translatable.locales')->load(); } - /** @test */ + #[Test] public function all_language_locales_are_loaded_from_the_configuration(): void { $this->app['config']->set('translatable.locales', [ @@ -58,7 +59,7 @@ public function all_language_locales_are_loaded_from_the_configuration(): void self::assertEquals(['el', 'en', 'fr', 'de', 'id'], $this->app->make('translatable.locales')->all()); } - /** @test */ + #[Test] public function it_loads_locales_and_countries(): void { $this->app['config']->set('translatable.locales', [ @@ -76,7 +77,7 @@ public function it_loads_locales_and_countries(): void self::assertEquals(['en', 'en-GB', 'en-US', 'de', 'de-DE', 'de-CH'], $this->app->make('translatable.locales')->all()); } - /** @test */ + #[Test] public function can_return_locales_as_array(): void { $this->app['config']->set('translatable.locales', [ @@ -91,7 +92,7 @@ public function can_return_locales_as_array(): void self::assertEquals(['el', 'en', 'fr', 'de', 'id'], $this->app->make('translatable.locales')->toArray()); } - /** @test */ + #[Test] public function can_retrieve_current_configuration(): void { $this->app['config']->set('translatable.locale', 'de'); @@ -99,7 +100,7 @@ public function can_retrieve_current_configuration(): void self::assertEquals('de', $this->app->make('translatable.locales')->current()); } - /** @test */ + #[Test] public function current_can_return_the_translator_locale_if_configuration_is_empty(): void { $this->app['config']->set('translatable.locale', null); @@ -108,7 +109,7 @@ public function current_can_return_the_translator_locale_if_configuration_is_emp self::assertEquals('en', $this->app->make('translatable.locales')->current()); } - /** @test */ + #[Test] public function it_checks_if_it_has_a_locale(): void { $this->app['config']->set('translatable.locales', [ @@ -124,7 +125,7 @@ public function it_checks_if_it_has_a_locale(): void self::assertFalse($this->app->make('translatable.locales')->has('jp')); } - /** @test */ + #[Test] public function can_access_as_an_array(): void { $this->app['config']->set('translatable.locales', [ @@ -140,7 +141,7 @@ public function can_access_as_an_array(): void self::assertFalse(isset($this->app->make('translatable.locales')['jp'])); } - /** @test */ + #[Test] public function can_retrieve_a_specific_locale_by_get(): void { $this->app['config']->set('translatable.locales', [ @@ -156,7 +157,7 @@ public function can_retrieve_a_specific_locale_by_get(): void self::assertNull($this->app->make('translatable.locales')->get('jp')); } - /** @test */ + #[Test] public function missing_locale_returns_null_by_get(): void { $this->app['config']->set('translatable.locales', [ @@ -172,7 +173,7 @@ public function missing_locale_returns_null_by_get(): void self::assertNull($this->app->make('translatable.locales')['jp']); } - /** @test */ + #[Test] public function it_can_add_a_locale(): void { $this->app['config']->set('translatable.locales', [ @@ -186,7 +187,7 @@ public function it_can_add_a_locale(): void self::assertTrue($this->app->make('translatable.locales')->has('en')); } - /** @test */ + #[Test] public function locale_can_be_added_by_accessing_as_an_array(): void { $this->app['config']->set('translatable.locales', [ @@ -200,7 +201,7 @@ public function locale_can_be_added_by_accessing_as_an_array(): void self::assertTrue($this->app->make('translatable.locales')->has('en')); } - /** @test */ + #[Test] public function locale_country_can_be_added_by_accessing_as_an_array(): void { $this->app['config']->set('translatable.locales', [ @@ -214,7 +215,7 @@ public function locale_country_can_be_added_by_accessing_as_an_array(): void self::assertTrue($this->app->make('translatable.locales')->has('de-AT')); } - /** @test */ + #[Test] public function can_forget_a_locale(): void { $this->app['config']->set('translatable.locales', [ @@ -229,7 +230,7 @@ public function can_forget_a_locale(): void self::assertFalse($this->app->make('translatable.locales')->has('en')); } - /** @test */ + #[Test] public function can_forget_a_locale_using_unset_as_an_array(): void { $this->app['config']->set('translatable.locales', [ @@ -244,7 +245,7 @@ public function can_forget_a_locale_using_unset_as_an_array(): void self::assertFalse($this->app->make('translatable.locales')->has('en')); } - /** @test */ + #[Test] public function can_retrieve_the_locale_country_separator(): void { $this->app['config']->set('translatable.locale_separator', '_'); @@ -252,7 +253,7 @@ public function can_retrieve_the_locale_country_separator(): void self::assertEquals('_', $this->app->make('translatable.locales')->getLocaleSeparator()); } - /** @test */ + #[Test] public function can_set_a_default_locale_country_separator_if_configuration_is_missing(): void { $this->app['config']->set('translatable.locale_separator', null); @@ -260,20 +261,20 @@ public function can_set_a_default_locale_country_separator_if_configuration_is_m self::assertEquals('-', $this->app->make('translatable.locales')->getLocaleSeparator()); } - /** @test */ + #[Test] public function can_get_a_country_locale_formatted_with_separator(): void { self::assertEquals('de-AT', $this->app->make('translatable.locales')->getCountryLocale('de', 'AT')); } - /** @test */ + #[Test] public function can_determine_if_a_locale_is_country_based(): void { self::assertTrue($this->app->make('translatable.locales')->isLocaleCountryBased('de-AT')); self::assertFalse($this->app->make('translatable.locales')->isLocaleCountryBased('de')); } - /** @test */ + #[Test] public function can_get_a_locale_from_the_country_locale(): void { self::assertEquals('de', $this->app->make('translatable.locales')->getLanguageFromCountryBasedLocale('de-AT')); diff --git a/tests/ScopesTest.php b/tests/ScopesTest.php index 66e300d..98f51a9 100644 --- a/tests/ScopesTest.php +++ b/tests/ScopesTest.php @@ -2,12 +2,13 @@ namespace Tests; +use PHPUnit\Framework\Attributes\Test; use Tests\Eloquent\Country; use Tests\Eloquent\Vegetable; final class ScopesTest extends TestCase { - /** @test */ + #[Test] public function translated_in_scope_returns_only_translated_records_for_this_locale(): void { factory(Country::class)->create(['code' => 'ca', 'name:ca' => 'Català']); @@ -16,7 +17,7 @@ public function translated_in_scope_returns_only_translated_records_for_this_loc self::assertEquals(1, Country::translatedIn('fr')->count()); } - /** @test */ + #[Test] public function translated_in_scope_works_with_default_locale(): void { app()->setLocale('de'); @@ -27,7 +28,7 @@ public function translated_in_scope_works_with_default_locale(): void self::assertEquals('Griechenland', Country::translatedIn()->first()->name); } - /** @test */ + #[Test] public function not_translated_in_scope_returns_only_not_translated_records_for_this_locale(): void { factory(Country::class)->create(['code' => 'ca', 'name:ca' => 'Català']); @@ -41,7 +42,7 @@ public function not_translated_in_scope_returns_only_not_translated_records_for_ self::assertFalse($notTranslated->last()->hasTranslation('en')); } - /** @test */ + #[Test] public function not_translated_in_scope_works_with_default_locale(): void { app()->setLocale('en'); @@ -54,7 +55,7 @@ public function not_translated_in_scope_works_with_default_locale(): void self::assertFalse($notTranslated->first()->hasTranslation('en')); } - /** @test */ + #[Test] public function translated_scope_returns_records_with_at_least_one_translation(): void { factory(Country::class)->create(['code' => 'ca']); @@ -64,7 +65,7 @@ public function translated_scope_returns_records_with_at_least_one_translation() self::assertEquals('English', Country::with('translations')->translated()->first()->{'name:en'}); } - /** @test */ + #[Test] public function lists_of_translated_fields(): void { app()->setLocale('de'); @@ -80,7 +81,7 @@ public function lists_of_translated_fields(): void self::assertEquals('Griechenland', $countries->first()->name); } - /** @test */ + #[Test] public function lists_of_translated_fields_with_fallback(): void { app('config')->set('translatable.fallback_locale', 'en'); @@ -102,7 +103,7 @@ public function lists_of_translated_fields_with_fallback(): void self::assertEquals('France', $countries->last()->name); } - /** @test */ + #[Test] public function lists_of_translated_fields_disable_autoload_translations(): void { app()->setLocale('de'); @@ -116,7 +117,7 @@ public function lists_of_translated_fields_disable_autoload_translations(): void Country::defaultAutoloadTranslations(); } - /** @test */ + #[Test] public function lists_of_translated_fields_enable_autoload_translations(): void { app()->setLocale('de'); @@ -139,7 +140,7 @@ public function lists_of_translated_fields_enable_autoload_translations(): void Country::defaultAutoloadTranslations(); } - /** @test */ + #[Test] public function scope_withTranslation_without_fallback(): void { factory(Country::class)->create(['code' => 'el', 'name:en' => 'Greece']); @@ -150,7 +151,7 @@ public function scope_withTranslation_without_fallback(): void self::assertSame('Greece', $result->translations->first()->name); } - /** @test */ + #[Test] public function scope_withTranslation_with_fallback(): void { app('config')->set('translatable.fallback_locale', 'de'); @@ -164,7 +165,7 @@ public function scope_withTranslation_with_fallback(): void self::assertEquals('Griechenland', $result->translations->where('locale', 'de')->first()->name); } - /** @test */ + #[Test] public function scope_withTranslation_with_country_based_fallback(): void { app('config')->set('translatable.fallback_locale', 'en'); @@ -196,7 +197,7 @@ public function scope_withTranslation_with_country_based_fallback(): void self::assertEquals('Zucchini', $translations[2]->name); } - /** @test */ + #[Test] public function whereTranslation_filters_by_translation(): void { factory(Country::class)->create(['code' => 'gr', 'name:en' => 'Greece']); @@ -204,7 +205,7 @@ public function whereTranslation_filters_by_translation(): void self::assertSame('gr', Country::whereTranslation('name', 'Greece')->first()->code); } - /** @test */ + #[Test] public function orWhereTranslation_filters_by_translation(): void { factory(Country::class)->create(['code' => 'gr', 'name:en' => 'Greece']); @@ -217,7 +218,7 @@ public function orWhereTranslation_filters_by_translation(): void self::assertSame('France', $result->last()->name); } - /** @test */ + #[Test] public function whereTranslation_filters_by_translation_and_locale(): void { factory(Country::class)->create(['code' => 'gr', 'name:de' => 'Griechenland']); @@ -230,7 +231,7 @@ public function whereTranslation_filters_by_translation_and_locale(): void self::assertSame('gr', $result->first()->code); } - /** @test */ + #[Test] public function whereTranslationLike_filters_by_translation(): void { factory(Country::class)->create(['code' => 'gr', 'name:en' => 'Greece']); @@ -238,7 +239,7 @@ public function whereTranslationLike_filters_by_translation(): void self::assertSame('gr', Country::whereTranslationLike('name', '%Greec%')->first()->code); } - /** @test */ + #[Test] public function orWhereTranslationLike_filters_by_translation(): void { factory(Country::class)->create(['code' => 'gr', 'name:en' => 'Greece']); @@ -251,7 +252,7 @@ public function orWhereTranslationLike_filters_by_translation(): void self::assertSame('France', $result->last()->name); } - /** @test */ + #[Test] public function whereTranslationLike_filters_by_translation_and_locale(): void { factory(Country::class)->create(['code' => 'gr', 'name:de' => 'Griechenland']); @@ -264,7 +265,7 @@ public function whereTranslationLike_filters_by_translation_and_locale(): void self::assertEquals('gr', $result->first()->code); } - /** @test */ + #[Test] public function orderByTranslation_sorts_by_key_asc(): void { factory(Country::class)->create(['code' => 'el', 'name' => 'Greece']); @@ -273,7 +274,7 @@ public function orderByTranslation_sorts_by_key_asc(): void self::assertEquals('fr', Country::orderByTranslation('name')->get()->first()->code); } - /** @test */ + #[Test] public function orderByTranslation_sorts_by_key_desc(): void { factory(Country::class)->create(['code' => 'el', 'name' => 'Greece']); @@ -282,7 +283,7 @@ public function orderByTranslation_sorts_by_key_desc(): void self::assertEquals('el', Country::orderByTranslation('name', 'desc')->get()->first()->code); } - /** @test */ + #[Test] public function test_orderByTranslation_sorts_by_key_asc_even_if_locale_is_missing(): void { factory(Vegetable::class)->create(['en' => ['name' => 'Potatoes'], 'fr' => ['name' => 'Pommes de Terre']]); diff --git a/tests/TranslatableTest.php b/tests/TranslatableTest.php index 8afb940..ff83918 100644 --- a/tests/TranslatableTest.php +++ b/tests/TranslatableTest.php @@ -2,6 +2,7 @@ namespace Tests; +use PHPUnit\Framework\Attributes\Test; use Astrotomic\Translatable\Locales; use Tests\Eloquent\Country; use Tests\Eloquent\CountryStrict; @@ -16,7 +17,7 @@ final class TranslatableTest extends TestCase { - /** @test */ + #[Test] public function it_finds_the_default_translation_class(): void { self::assertEquals( @@ -25,7 +26,7 @@ public function it_finds_the_default_translation_class(): void ); } - /** @test */ + #[Test] public function it_finds_the_translation_class_with_namespace_set(): void { $this->app->make('config')->set('translatable.translation_model_namespace', 'App\Models\Translations'); @@ -36,7 +37,7 @@ public function it_finds_the_translation_class_with_namespace_set(): void ); } - /** @test */ + #[Test] public function it_finds_the_translation_class_with_suffix_set(): void { $this->app->make('config')->set('translatable.translation_suffix', 'Trans'); @@ -47,7 +48,7 @@ public function it_finds_the_translation_class_with_suffix_set(): void ); } - /** @test */ + #[Test] public function it_returns_custom_TranslationModelName(): void { $vegetable = new Vegetable(); @@ -64,7 +65,7 @@ public function it_returns_custom_TranslationModelName(): void ); } - /** @test */ + #[Test] public function it_returns_relation_key(): void { $vegetable = new Vegetable(); @@ -74,7 +75,7 @@ public function it_returns_relation_key(): void self::assertEquals('my_awesome_key', $vegetable->getRelationKey()); } - /** @test */ + #[Test] public function it_returns_the_translation(): void { $vegetable = factory(Vegetable::class)->create(['name:el' => 'Αρακάς', 'name:en' => 'Peas']); @@ -90,7 +91,7 @@ public function it_returns_the_translation(): void self::assertEquals('Peas', $vegetable->translate()->name); } - /** @test */ + #[Test] public function it_returns_the_translation_with_accessor(): void { $vegetable = factory(Vegetable::class)->create(['name:el' => 'Αρακάς', 'name:en' => 'Peas']); @@ -99,7 +100,7 @@ public function it_returns_the_translation_with_accessor(): void self::assertEquals('Peas', $vegetable->{'name:en'}); } - /** @test */ + #[Test] public function it_returns_null_when_the_locale_doesnt_exist(): void { $vegetable = factory(Vegetable::class)->create(['name:el' => 'Αρακάς']); @@ -107,7 +108,7 @@ public function it_returns_null_when_the_locale_doesnt_exist(): void self::assertSame(null, $vegetable->{'name:unknown-locale'}); } - /** @test */ + #[Test] public function it_saves_translations(): void { $vegetable = factory(Vegetable::class)->create(['name:el' => 'Αρακάς', 'name:en' => 'Peas']); @@ -121,7 +122,7 @@ public function it_saves_translations(): void self::assertEquals('Pea', $vegetable->name); } - /** @test */ + #[Test] public function it_saves_translations_with_mutator(): void { $vegetable = factory(Vegetable::class)->create(['name:el' => 'Αρακάς', 'name:en' => 'Peas']); @@ -138,7 +139,7 @@ public function it_saves_translations_with_mutator(): void self::assertEquals('Μπιζέλι', $vegetable->translate()->name); } - /** @test */ + #[Test] public function it_does_not_lazy_load_translations_when_updating_non_translated_attributes(): void { DB::enableQueryLog(); @@ -161,7 +162,7 @@ public function it_does_not_lazy_load_translations_when_updating_non_translated_ DB::disableQueryLog(); } - /** @test */ + #[Test] public function it_uses_default_locale_to_return_translations(): void { $vegetable = factory(Vegetable::class)->create(['name:el' => 'Αρακάς']); @@ -176,7 +177,7 @@ public function it_uses_default_locale_to_return_translations(): void self::assertEquals('Μπιζέλι', $vegetable->translate('el')->name); } - /** @test */ + #[Test] public function it_creates_translations_using_the_shortcut(): void { $vegetable = factory(Vegetable::class)->create(); @@ -193,7 +194,7 @@ public function it_creates_translations_using_the_shortcut(): void ]); } - /** @test */ + #[Test] public function it_creates_translations_using_mass_assignment(): void { $vegetable = Vegetable::create([ @@ -205,7 +206,7 @@ public function it_creates_translations_using_mass_assignment(): void self::assertEquals('Peas', $vegetable->name); } - /** @test */ + #[Test] public function it_creates_translations_using_mass_assignment_and_locales(): void { $vegetable = Vegetable::create([ @@ -223,7 +224,7 @@ public function it_creates_translations_using_mass_assignment_and_locales(): voi self::assertEquals('Pois', $vegetable->translate('fr')->name); } - /** @test */ + #[Test] public function it_skips_mass_assignment_if_attributes_non_fillable(): void { $this->expectException(MassAssignmentException::class); @@ -238,7 +239,7 @@ public function it_skips_mass_assignment_if_attributes_non_fillable(): void self::assertNull($country->translate('fr')); } - /** @test */ + #[Test] public function it_returns_if_object_has_translation(): void { $vegetable = factory(Vegetable::class)->create(['name:en' => 'Peas']); @@ -247,7 +248,7 @@ public function it_returns_if_object_has_translation(): void self::assertFalse($vegetable->hasTranslation('some-code')); } - /** @test */ + #[Test] public function it_returns_default_translation(): void { $this->app->make('config')->set('translatable.fallback_locale', 'de'); @@ -262,7 +263,7 @@ public function it_returns_default_translation(): void self::assertSame('Erbsen', $vegetable->translateOrDefault()->name); } - /** @test */ + #[Test] public function fallback_option_in_config_overrides_models_fallback_option(): void { $this->app->make('config')->set('translatable.fallback_locale', 'de'); @@ -280,7 +281,7 @@ public function fallback_option_in_config_overrides_models_fallback_option(): vo self::assertNull($vegetable->getTranslation('ch')); } - /** @test */ + #[Test] public function configuration_defines_if_fallback_is_used(): void { $this->app->make('config')->set('translatable.fallback_locale', 'de'); @@ -291,7 +292,7 @@ public function configuration_defines_if_fallback_is_used(): void self::assertEquals('de', $vegetable->getTranslation('ch')->locale); } - /** @test */ + #[Test] public function useTranslationFallback_overrides_configuration(): void { $this->app->make('config')->set('translatable.fallback_locale', 'de'); @@ -303,7 +304,7 @@ public function useTranslationFallback_overrides_configuration(): void self::assertNull($vegetable->getTranslation('ch')); } - /** @test */ + #[Test] public function it_returns_null_if_fallback_is_not_defined(): void { $this->app->make('config')->set('translatable.fallback_locale', 'ch'); @@ -313,7 +314,7 @@ public function it_returns_null_if_fallback_is_not_defined(): void self::assertNull($vegetable->getTranslation('pl', true)); } - /** @test */ + #[Test] public function it_fills_a_non_default_language_with_fallback_set(): void { $this->app->make('config')->set('translatable.fallback_locale', 'en'); @@ -328,7 +329,7 @@ public function it_fills_a_non_default_language_with_fallback_set(): void self::assertEquals('Peas', $vegetable->translate('en')->name); } - /** @test */ + #[Test] public function it_creates_a_new_translation(): void { $this->app->make('config')->set('translatable.fallback_locale', 'en'); @@ -340,7 +341,7 @@ public function it_creates_a_new_translation(): void self::assertEquals('Peas', $vegetable->translate('en')->name); } - /** @test */ + #[Test] public function the_locale_key_is_locale_by_default(): void { $vegetable = new Vegetable(); @@ -348,7 +349,7 @@ public function the_locale_key_is_locale_by_default(): void self::assertEquals('locale', $vegetable->getLocaleKey()); } - /** @test */ + #[Test] public function the_locale_key_can_be_overridden_in_configuration(): void { $this->app->make('config')->set('translatable.locale_key', 'language_id'); @@ -357,7 +358,7 @@ public function the_locale_key_can_be_overridden_in_configuration(): void self::assertEquals('language_id', $vegetable->getLocaleKey()); } - /** @test */ + #[Test] public function the_locale_key_can_be_customized_per_model(): void { $vegetable = new Vegetable(); @@ -379,13 +380,13 @@ public function test_the_translation_model_can_be_customized(): void CountryStrict::reguard(); } - /** @test */ + #[Test] public function it_reads_the_configuration(): void { self::assertEquals('Translation', $this->app->make('config')->get('translatable.translation_suffix')); } - /** @test */ + #[Test] public function getting_translation_does_not_create_translation(): void { $vegetable = factory(Vegetable::class)->create(); @@ -393,7 +394,7 @@ public function getting_translation_does_not_create_translation(): void self::assertNull($vegetable->getTranslation('en', false)); } - /** @test */ + #[Test] public function getting_translated_field_does_not_create_translation(): void { $this->app->setLocale('en'); @@ -402,7 +403,7 @@ public function getting_translated_field_does_not_create_translation(): void self::assertNull($vegetable->getTranslation('en')); } - /** @test */ + #[Test] public function it_has_methods_that_return_always_a_translation(): void { $vegetable = factory(Vegetable::class)->create(); @@ -412,7 +413,7 @@ public function it_has_methods_that_return_always_a_translation(): void self::assertEquals('xyz', $vegetable->translateOrNew()->locale); } - /** @test */ + #[Test] public function it_throws_an_exception_if_translation_does_not_exist(): void { $this->expectException(ModelNotFoundException::class); @@ -426,7 +427,7 @@ public function it_throws_an_exception_if_translation_does_not_exist(): void $vegetable->translateOrFail('xyz'); } - /** @test */ + #[Test] public function it_returns_if_attribute_is_translated(): void { $vegetable = new Vegetable(); @@ -435,7 +436,7 @@ public function it_returns_if_attribute_is_translated(): void self::assertFalse($vegetable->isTranslationAttribute('some-field')); } - /** @test */ + #[Test] public function config_overrides_apps_locale(): void { $veegtable = factory(Vegetable::class)->create(['name:de' => 'Erbsen']); @@ -444,7 +445,7 @@ public function config_overrides_apps_locale(): void self::assertEquals('Erbsen', $veegtable->name); } - /** @test */ + #[Test] public function locales_as_array_keys_are_properly_detected(): void { $this->app->config->set('translatable.locales', ['en' => ['US', 'GB']]); @@ -460,7 +461,7 @@ public function locales_as_array_keys_are_properly_detected(): void self::assertEquals('US Peas', $vegetable->getTranslation('en-US')->name); } - /** @test */ + #[Test] public function locale_separator_can_be_configured(): void { $this->app->make('config')->set('translatable.locales', ['en' => ['GB']]); @@ -473,7 +474,7 @@ public function locale_separator_can_be_configured(): void self::assertEquals('Peas', $vegetable->getTranslation('en_GB')->name); } - /** @test */ + #[Test] public function fallback_for_country_based_locales(): void { $this->app->make('config')->set('translatable.use_fallback', true); @@ -491,7 +492,7 @@ public function fallback_for_country_based_locales(): void self::assertEquals('French fries', $vegetable->getTranslation('en-US')->name); } - /** @test */ + #[Test] public function fallback_for_country_based_locales_with_no_base_locale(): void { $this->app->make('config')->set('translatable.use_fallback', true); @@ -508,7 +509,7 @@ public function fallback_for_country_based_locales_with_no_base_locale(): void self::assertEquals('Chips', $vegetable->getTranslation('pt-BR')->name); } - /** @test */ + #[Test] public function to_array_and_fallback_with_country_based_locales_enabled(): void { $this->app->make('config')->set('translatable.locale', 'en-GB'); @@ -523,7 +524,7 @@ public function to_array_and_fallback_with_country_based_locales_enabled(): void self::assertEquals('Frites', $vegetable['name']); } - /** @test */ + #[Test] public function it_skips_translations_in_to_array_when_config_is_set(): void { $this->app->make('config')->set('translatable.to_array_always_loads_translations', false); @@ -534,7 +535,7 @@ public function it_skips_translations_in_to_array_when_config_is_set(): void self::assertFalse(isset($vegetable['name'])); } - /** @test */ + #[Test] public function it_returns_translations_in_to_array_when_config_is_set_but_translations_are_loaded(): void { $this->app->make('config')->set('translatable.to_array_always_loads_translations', false); @@ -545,7 +546,7 @@ public function it_returns_translations_in_to_array_when_config_is_set_but_trans self::assertTrue(isset($vegetable['name'])); } - /** @test */ + #[Test] public function it_should_mutate_the_translated_attribute_if_a_mutator_is_set_on_model(): void { $person = new Person(['name' => 'john doe']); @@ -554,7 +555,7 @@ public function it_should_mutate_the_translated_attribute_if_a_mutator_is_set_on self::assertEquals('John Doe', $person->name); } - /** @test */ + #[Test] public function it_deletes_all_translations(): void { $vegetable = factory(Vegetable::class)->create(['name:es' => 'Guisantes', 'name:en' => 'Peas']); @@ -566,7 +567,7 @@ public function it_deletes_all_translations(): void self::assertEquals(0, count($vegetable->translations)); } - /** @test */ + #[Test] public function it_deletes_translations_for_given_locales(): void { $vegetable = factory(Vegetable::class)->create(['name:es' => 'Guisantes', 'name:en' => 'Peas']); @@ -578,7 +579,7 @@ public function it_deletes_translations_for_given_locales(): void self::assertEquals(1, count($vegetable->translations)); } - /** @test */ + #[Test] public function passing_an_empty_array_should_not_delete_translations(): void { $vegetable = factory(Vegetable::class)->create(['name:es' => 'Guisantes', 'name:en' => 'Peas']); @@ -590,7 +591,7 @@ public function passing_an_empty_array_should_not_delete_translations(): void self::assertEquals(2, count($vegetable->translations)); } - /** @test */ + #[Test] public function fill_with_translation_key(): void { $vegetable = new Vegetable(); @@ -607,7 +608,7 @@ public function fill_with_translation_key(): void self::assertEquals('Erbsen', $vegetable->translate('de')->name); } - /** @test */ + #[Test] public function it_uses_the_default_locale_from_the_model(): void { $vegetable = new Vegetable(); @@ -629,7 +630,7 @@ public function it_uses_the_default_locale_from_the_model(): void self::assertEquals('Pois', $vegetable->name); } - /** @test */ + #[Test] public function replicate_entity(): void { $vegetable = new Vegetable(); @@ -658,7 +659,7 @@ public function replicate_entity(): void self::assertEquals($replicated->translate('de')->vegetable_identity, $replicated->identity); } - /** @test */ + #[Test] public function can_get_translations_as_array(): void { $vegetable = factory(Vegetable::class)->create([ @@ -674,7 +675,7 @@ public function can_get_translations_as_array(): void ], $vegetable->getTranslationsArray()); } - /** @test */ + #[Test] public function fill_will_ignore_unkown_locales(): void { config(['translatable.locales' => ['en']]); @@ -694,7 +695,7 @@ public function fill_will_ignore_unkown_locales(): void self::assertDatabaseMissing('vegetable_translations', ['locale' => 'ua']); } - /** @test */ + #[Test] public function fill_will_ignore_unkown_locales_with_translations(): void { config(['translatable.locales' => ['en']]); @@ -715,7 +716,7 @@ public function fill_will_ignore_unkown_locales_with_translations(): void self::assertDatabaseMissing('vegetable_translations', ['locale' => 'ua']); } - /** @test */ + #[Test] public function it_uses_fallback_locale_if_default_is_empty(): void { $this->app->make('config')->set('translatable.use_fallback', true); @@ -733,7 +734,7 @@ public function it_uses_fallback_locale_if_default_is_empty(): void self::assertEquals('Peas', $vegetable->name); } - /** @test */ + #[Test] public function it_uses_value_when_fallback_is_not_available(): void { $this->app->make('config')->set('translatable.fallback_locale', 'it'); @@ -753,7 +754,7 @@ public function it_uses_value_when_fallback_is_not_available(): void self::assertEquals('Erbsen', $vegetable->getAttribute('name')); } - /** @test */ + #[Test] public function empty_translated_attribute(): void { $this->app->setLocale('invalid'); @@ -762,7 +763,7 @@ public function empty_translated_attribute(): void self::assertNull($vegetable->name); } - /** @test */ + #[Test] public function numeric_translated_attribute(): void { $this->app->make('config')->set('translatable.fallback_locale', 'de'); @@ -798,7 +799,7 @@ protected function isEmptyTranslatableAttribute(string $key, $value): bool self::assertSame('1', $vegetable->name); } - /** @test */ + #[Test] public function translation_relation(): void { $this->app->make('config')->set('translatable.fallback_locale', 'fr'); @@ -814,7 +815,7 @@ public function translation_relation(): void self::assertEquals('en', $peas->translation->locale); } - /** @test */ + #[Test] public function translation_relation_can_use_fallback_locale(): void { $this->app->make('config')->set('translatable.fallback_locale', 'fr'); @@ -827,7 +828,7 @@ public function translation_relation_can_use_fallback_locale(): void self::assertEquals('fr', $peas->translation->locale); } - /** @test */ + #[Test] public function translation_relation_returns_null_if_no_available_locale_was_found(): void { $this->app->make('config')->set('translatable.fallback_locale', 'xyz'); @@ -839,7 +840,7 @@ public function translation_relation_returns_null_if_no_available_locale_was_fou self::assertNull($peas->translation); } - /** @test */ + #[Test] public function can_fill_conflicting_attribute_locale(): void { $this->app->make('config')->set('translatable.locales', ['en', 'id']); @@ -866,7 +867,7 @@ public function can_fill_conflicting_attribute_locale(): void self::assertEquals('en:my country', $country->getTranslation('en', false)->name); } - /** @test */ + #[Test] public function it_returns_first_existing_translation_as_fallback(): void { /** @var Locales $helper */ @@ -943,7 +944,7 @@ public function it_returns_first_existing_translation_as_fallback(): void self::assertEquals($helper->getCountryLocale('de', 'DE'), $translation->locale); } - /** @test */ + #[Test] public function it_uses_translation_relation_if_locale_matches(): void { $this->app->make('config')->set('translatable.use_fallback', false); @@ -963,7 +964,7 @@ public function it_uses_translation_relation_if_locale_matches(): void self::assertFalse($country->relationLoaded('translations')); } - /** @test */ + #[Test] public function it_uses_translations_relation_if_locale_does_not_match(): void { $this->app->make('config')->set('translatable.use_fallback', false); @@ -984,7 +985,7 @@ public function it_uses_translations_relation_if_locale_does_not_match(): void self::assertTrue($country->relationLoaded('translations')); } - /** @test */ + #[Test] public function it_does_not_load_translation_relation_if_not_already_loaded(): void { $this->app->make('config')->set('translatable.use_fallback', false); @@ -1003,7 +1004,7 @@ public function it_does_not_load_translation_relation_if_not_already_loaded(): v self::assertTrue($country->relationLoaded('translations')); } - /** @test */ + #[Test] public function it_does_not_delete_translations_on_cascade_by_default() { $vegetable = factory(Vegetable::class)->create(['name:en' => 'Peas']); @@ -1017,7 +1018,7 @@ public function it_does_not_delete_translations_on_cascade_by_default() $this->assertDatabaseHas('vegetable_translations', ['vegetable_identity' => $vegetable->identity]); } - /** @test */ + #[Test] public function it_deletes_translations_on_cascade() { Vegetable::enableDeleteTranslationsCascade(); @@ -1032,7 +1033,7 @@ public function it_deletes_translations_on_cascade() $this->assertDatabaseMissing('vegetable_translations', ['vegetable_identity' => $vegetable->identity]); } - /** @test */ + #[Test] public function it_does_not_delete_on_cascade_after_retrieving_a_model() { Vegetable::enableDeleteTranslationsCascade(); @@ -1048,7 +1049,7 @@ public function it_does_not_delete_on_cascade_after_retrieving_a_model() $this->assertDatabaseHas('vegetable_translations', ['vegetable_identity' => $vegetable->identity]); } - /** @test */ + #[Test] public function it_can_restore_translations_in_a_transaction() { Vegetable::enableDeleteTranslationsCascade(); diff --git a/tests/ValidationTest.php b/tests/ValidationTest.php index 1ffc03f..70d4b53 100644 --- a/tests/ValidationTest.php +++ b/tests/ValidationTest.php @@ -2,6 +2,7 @@ namespace Tests; +use PHPUnit\Framework\Attributes\Test; use Astrotomic\Translatable\Locales; use Astrotomic\Translatable\Validation\RuleFactory; use Illuminate\Validation\Rule; @@ -10,7 +11,7 @@ final class ValidationTest extends TestCase { - /** @test */ + #[Test] public function it_does_not_touch_untranslated_keys(): void { $rules = [ @@ -24,7 +25,7 @@ public function it_does_not_touch_untranslated_keys(): void self::assertEquals($rules, RuleFactory::make($rules)); } - /** @test */ + #[Test] public function format_array_it_replaces_single_key(): void { $rules = [ @@ -41,7 +42,7 @@ public function format_array_it_replaces_single_key(): void ], RuleFactory::make($rules, RuleFactory::FORMAT_ARRAY)); } - /** @test */ + #[Test] public function format_array_it_replaces_sub_key(): void { $rules = [ @@ -58,7 +59,7 @@ public function format_array_it_replaces_sub_key(): void ], RuleFactory::make($rules, RuleFactory::FORMAT_ARRAY)); } - /** @test */ + #[Test] public function format_array_it_replaces_middle_key(): void { $rules = [ @@ -75,7 +76,7 @@ public function format_array_it_replaces_middle_key(): void ], RuleFactory::make($rules, RuleFactory::FORMAT_ARRAY)); } - /** @test */ + #[Test] public function format_array_it_replaces_middle_key_with_custom_prefix(): void { $rules = [ @@ -92,7 +93,7 @@ public function format_array_it_replaces_middle_key_with_custom_prefix(): void ], RuleFactory::make($rules, RuleFactory::FORMAT_ARRAY, '{')); } - /** @test */ + #[Test] public function format_array_it_replaces_middle_key_with_custom_suffix(): void { $rules = [ @@ -109,7 +110,7 @@ public function format_array_it_replaces_middle_key_with_custom_suffix(): void ], RuleFactory::make($rules, RuleFactory::FORMAT_ARRAY, '%', '}')); } - /** @test */ + #[Test] public function format_array_it_replaces_middle_key_with_custom_delimiters(): void { $rules = [ @@ -126,7 +127,7 @@ public function format_array_it_replaces_middle_key_with_custom_delimiters(): vo ], RuleFactory::make($rules, RuleFactory::FORMAT_ARRAY, '{', '}')); } - /** @test */ + #[Test] public function format_array_it_replaces_middle_key_with_custom_regex_delimiters(): void { $rules = [ @@ -143,7 +144,7 @@ public function format_array_it_replaces_middle_key_with_custom_regex_delimiters ], RuleFactory::make($rules, RuleFactory::FORMAT_ARRAY, '$', '$')); } - /** @test */ + #[Test] public function format_array_it_uses_config_as_default(): void { app('config')->set('translatable.rule_factory', [ @@ -168,7 +169,7 @@ public function format_array_it_uses_config_as_default(): void ], RuleFactory::make($rules)); } - /** @test */ + #[Test] public function format_key_it_replaces_single_key(): void { $rules = [ @@ -185,7 +186,7 @@ public function format_key_it_replaces_single_key(): void ], RuleFactory::make($rules, RuleFactory::FORMAT_KEY)); } - /** @test */ + #[Test] public function format_key_it_replaces_sub_key(): void { $rules = [ @@ -202,7 +203,7 @@ public function format_key_it_replaces_sub_key(): void ], RuleFactory::make($rules, RuleFactory::FORMAT_KEY)); } - /** @test */ + #[Test] public function format_key_it_replaces_middle_key(): void { $rules = [ @@ -219,7 +220,7 @@ public function format_key_it_replaces_middle_key(): void ], RuleFactory::make($rules, RuleFactory::FORMAT_KEY)); } - /** @test */ + #[Test] public function format_key_it_uses_config_as_default(): void { app('config')->set('translatable.rule_factory', [ @@ -244,7 +245,7 @@ public function format_key_it_uses_config_as_default(): void ], RuleFactory::make($rules)); } - /** @test */ + #[Test] public function it_replaces_key_with_custom_locales(): void { $rules = [ @@ -262,7 +263,7 @@ public function it_replaces_key_with_custom_locales(): void ])); } - /** @test */ + #[Test] public function it_throws_exception_with_undefined_locales(): void { $this->expectException(InvalidArgumentException::class); @@ -279,7 +280,7 @@ public function it_throws_exception_with_undefined_locales(): void ]); } - /** @test */ + #[Test] public function format_array_it_replaces_single_rule(): void { $rules = [ @@ -300,7 +301,7 @@ public function format_array_it_replaces_single_rule(): void ], RuleFactory::make($rules, RuleFactory::FORMAT_ARRAY)); } - /** @test */ + #[Test] public function format_array_it_replaces_imploded_rules(): void { $rules = [ @@ -321,7 +322,7 @@ public function format_array_it_replaces_imploded_rules(): void ], RuleFactory::make($rules, RuleFactory::FORMAT_ARRAY)); } - /** @test */ + #[Test] public function format_array_it_replaces_array_of_rules(): void { $rules = [ @@ -342,7 +343,7 @@ public function format_array_it_replaces_array_of_rules(): void ], RuleFactory::make($rules, RuleFactory::FORMAT_ARRAY)); } - /** @test */ + #[Test] public function format_array_it_does_not_touch_non_string_rule(): void { $rules = [ @@ -361,7 +362,7 @@ public function format_array_it_does_not_touch_non_string_rule(): void self::assertInstanceOf(RequiredIf::class, $formattedRules['de-AT.content']); } - /** @test */ + #[Test] public function format_array_it_does_not_touch_non_string_rule_in_array(): void { $rules = [ @@ -387,7 +388,7 @@ public function format_array_it_does_not_touch_non_string_rule_in_array(): void self::assertInstanceOf(RequiredIf::class, $formattedRules['de-AT.content'][1]); } - /** @test */ + #[Test] public function format_key_it_replaces_single_rule(): void { $rules = [ @@ -408,7 +409,7 @@ public function format_key_it_replaces_single_rule(): void ], RuleFactory::make($rules, RuleFactory::FORMAT_KEY)); } - /** @test */ + #[Test] public function format_key_it_replaces_imploded_rules(): void { $rules = [ @@ -429,7 +430,7 @@ public function format_key_it_replaces_imploded_rules(): void ], RuleFactory::make($rules, RuleFactory::FORMAT_KEY)); } - /** @test */ + #[Test] public function format_key_it_replaces_array_of_rules(): void { $rules = [ @@ -450,7 +451,7 @@ public function format_key_it_replaces_array_of_rules(): void ], RuleFactory::make($rules, RuleFactory::FORMAT_KEY)); } - /** @test */ + #[Test] public function format_key_it_does_not_touch_non_string_rule(): void { $rules = [ @@ -469,7 +470,7 @@ public function format_key_it_does_not_touch_non_string_rule(): void self::assertInstanceOf(RequiredIf::class, $formattedRules['content:de-AT']); } - /** @test */ + #[Test] public function format_key_it_does_not_touch_non_string_rule_in_array(): void { $rules = [ From 371cd6114a22baec62bcc2ea640481a6ded19246 Mon Sep 17 00:00:00 2001 From: Shift Date: Sun, 17 Mar 2024 20:52:34 +0000 Subject: [PATCH 18/31] Add return types to test methods --- tests/TranslatableTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/TranslatableTest.php b/tests/TranslatableTest.php index ff83918..06b37e9 100644 --- a/tests/TranslatableTest.php +++ b/tests/TranslatableTest.php @@ -1005,7 +1005,7 @@ public function it_does_not_load_translation_relation_if_not_already_loaded(): v } #[Test] - public function it_does_not_delete_translations_on_cascade_by_default() + public function it_does_not_delete_translations_on_cascade_by_default(): void { $vegetable = factory(Vegetable::class)->create(['name:en' => 'Peas']); @@ -1019,7 +1019,7 @@ public function it_does_not_delete_translations_on_cascade_by_default() } #[Test] - public function it_deletes_translations_on_cascade() + public function it_deletes_translations_on_cascade(): void { Vegetable::enableDeleteTranslationsCascade(); $vegetable = factory(Vegetable::class)->create(['name:en' => 'Peas']); @@ -1034,7 +1034,7 @@ public function it_deletes_translations_on_cascade() } #[Test] - public function it_does_not_delete_on_cascade_after_retrieving_a_model() + public function it_does_not_delete_on_cascade_after_retrieving_a_model(): void { Vegetable::enableDeleteTranslationsCascade(); $vegetable = factory(Vegetable::class)->create(['name:en' => 'Peas']); @@ -1050,7 +1050,7 @@ public function it_does_not_delete_on_cascade_after_retrieving_a_model() } #[Test] - public function it_can_restore_translations_in_a_transaction() + public function it_can_restore_translations_in_a_transaction(): void { Vegetable::enableDeleteTranslationsCascade(); $vegetable = factory(Vegetable::class)->create(['name:en' => 'Peas']); From 79dd334f92be0ac80b8d009102de46be72961230 Mon Sep 17 00:00:00 2001 From: Oleksandr Moik Date: Sun, 17 Mar 2024 23:11:42 +0200 Subject: [PATCH 19/31] Fix test - use less strict version for pint --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9540b3a..47221a9 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ }, "require-dev": { "laravel/legacy-factories": "^1.0.4", - "laravel/pint": "^1.14", + "laravel/pint": "^1.0", "mockery/mockery": "^1.3.3", "orchestra/testbench": "^6.0 || ^7.0 || ^8.0 || ^9.0", "phpunit/phpunit": "^10.0" From 9ce54f55b5ce46b7fb67a9bde1f6dfdb3ec605ca Mon Sep 17 00:00:00 2001 From: Oleksandr Moik Date: Sun, 17 Mar 2024 23:15:49 +0200 Subject: [PATCH 20/31] Update README.md files --- README.md | 8 ++++---- docs/README.md | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b7158c6..53c84c3 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,8 @@ [![Offset Earth](https://img.shields.io/badge/Treeware-%F0%9F%8C%B3-green?style=for-the-badge)](https://plant.treeware.earth/Astrotomic/laravel-translatable) [![Larabelles](https://img.shields.io/badge/Larabelles-%F0%9F%A6%84-lightpink?style=for-the-badge)](https://www.larabelles.com/) -[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/Astrotomic/laravel-translatable/phpunit?style=flat-square&logoColor=white&logo=github&label=PHPunit)](https://github.com/Astrotomic/laravel-translatable/actions?query=workflow%3Aphpunit) -[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/Astrotomic/laravel-translatable/pint?style=flat-square&logoColor=white&logo=github&label=Pint)](https://github.com/Astrotomic/laravel-translatable/actions?query=workflow%3Apint) +[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/Astrotomic/laravel-translatable/run-tests?style=flat-square&logoColor=white&logo=github&label=Tests)](https://github.com/Astrotomic/laravel-translatable/actions?query=workflow%3Arun-tests) +[![StyleCI](https://styleci.io/repos/192333549/shield)](https://styleci.io/repos/192333549) [![Codecov Coverage](https://img.shields.io/codecov/c/github/Astrotomic/laravel-translatable?logo=codecov&logoColor=white&label=Codecov&style=flat-square)](https://codecov.io/gh/Astrotomic/laravel-translatable) [![Total Downloads](https://img.shields.io/packagist/dt/astrotomic/laravel-translatable.svg?label=Downloads&style=flat-square)](https://packagist.org/packages/astrotomic/laravel-translatable) [![GitBook](https://img.shields.io/badge/GitBook-Astrotomic-7e57c2.svg?style=flat-square)](https://docs.astrotomic.info/laravel-translatable) @@ -97,8 +97,8 @@ If you discover any security related issues, please check [SECURITY](https://git ## Versions | Package | Laravel | PHP | -| :------------------ | :---------------------------- | :-------- | -| **v11.13 - v11.13** | `10.* / 11.*` | `^8.1` | +|:--------------------|:------------------------------|:----------| +| **v11.13 - v11.13** | `8.* / 9.* / 10.*` / `11.*` | `^8.0` | | **v11.12 - v11.12** | `8.* / 9.* / 10.*` | `^8.0` | | **v11.10 - v11.11** | `8.* / 9.*` | `^8.0` | | **v11.6 - v11.9** | `5.8.* / 6.* / 7.* / 8.*` | `>=7.2` | diff --git a/docs/README.md b/docs/README.md index cd2a43f..c0b5b34 100644 --- a/docs/README.md +++ b/docs/README.md @@ -74,7 +74,8 @@ echo $post->translate('fr')->title; // Mon premier post ## Versions | Package | Laravel | PHP | -| :------------------ | :---------------------------- | :-------- | +|:--------------------|:------------------------------|:----------| +| **v11.13 - v11.13** | `8.* / 9.* / 10.*` / `11.*` | `^8.0` | | **v11.12 - v11.12** | `8.* / 9.* / 10.*` | `^8.0` | | **v11.10 - v11.11** | `8.* / 9.*` | `^8.0` | | **v11.6 - v11.9** | `5.8.* / 6.* / 7.* / 8.*` | `>=7.2` | From 352018228090d86a6b6ec694fa650620515176f6 Mon Sep 17 00:00:00 2001 From: Oleksandr Moik Date: Sun, 17 Mar 2024 23:43:12 +0200 Subject: [PATCH 21/31] Apply patch from styleci --- tests/EloquentOverrideTest.php | 2 +- tests/LocalesTest.php | 2 +- tests/ScopesTest.php | 2 +- tests/TranslatableTest.php | 2 +- tests/ValidationTest.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/EloquentOverrideTest.php b/tests/EloquentOverrideTest.php index 4875bff..6e2b550 100644 --- a/tests/EloquentOverrideTest.php +++ b/tests/EloquentOverrideTest.php @@ -2,8 +2,8 @@ namespace Tests; -use PHPUnit\Framework\Attributes\Test; use Tests\Eloquent\Vegetable; +use PHPUnit\Framework\Attributes\Test; final class EloquentOverrideTest extends TestCase { diff --git a/tests/LocalesTest.php b/tests/LocalesTest.php index b155ae1..3d5c5f1 100644 --- a/tests/LocalesTest.php +++ b/tests/LocalesTest.php @@ -2,9 +2,9 @@ namespace Tests; -use PHPUnit\Framework\Attributes\Test; use Astrotomic\Translatable\Exception\LocalesNotDefinedException; use Astrotomic\Translatable\Locales; +use PHPUnit\Framework\Attributes\Test; final class LocalesTest extends TestCase { diff --git a/tests/ScopesTest.php b/tests/ScopesTest.php index 98f51a9..f76cdad 100644 --- a/tests/ScopesTest.php +++ b/tests/ScopesTest.php @@ -2,9 +2,9 @@ namespace Tests; -use PHPUnit\Framework\Attributes\Test; use Tests\Eloquent\Country; use Tests\Eloquent\Vegetable; +use PHPUnit\Framework\Attributes\Test; final class ScopesTest extends TestCase { diff --git a/tests/TranslatableTest.php b/tests/TranslatableTest.php index 06b37e9..f45857a 100644 --- a/tests/TranslatableTest.php +++ b/tests/TranslatableTest.php @@ -2,7 +2,6 @@ namespace Tests; -use PHPUnit\Framework\Attributes\Test; use Astrotomic\Translatable\Locales; use Tests\Eloquent\Country; use Tests\Eloquent\CountryStrict; @@ -14,6 +13,7 @@ use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\DB; +use PHPUnit\Framework\Attributes\Test; final class TranslatableTest extends TestCase { diff --git a/tests/ValidationTest.php b/tests/ValidationTest.php index 70d4b53..0085fa5 100644 --- a/tests/ValidationTest.php +++ b/tests/ValidationTest.php @@ -2,12 +2,12 @@ namespace Tests; -use PHPUnit\Framework\Attributes\Test; use Astrotomic\Translatable\Locales; use Astrotomic\Translatable\Validation\RuleFactory; use Illuminate\Validation\Rule; use Illuminate\Validation\Rules\RequiredIf; use InvalidArgumentException; +use PHPUnit\Framework\Attributes\Test; final class ValidationTest extends TestCase { From 551bf996c96980b2fb969996e069383b1cb05556 Mon Sep 17 00:00:00 2001 From: Gummibeer Date: Wed, 17 Apr 2024 11:39:18 +0000 Subject: [PATCH 22/31] Prettified Code! --- README.md | 2 +- docs/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 53c84c3..20d34d8 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ If you discover any security related issues, please check [SECURITY](https://git ## Versions | Package | Laravel | PHP | -|:--------------------|:------------------------------|:----------| +| :------------------ | :---------------------------- | :-------- | | **v11.13 - v11.13** | `8.* / 9.* / 10.*` / `11.*` | `^8.0` | | **v11.12 - v11.12** | `8.* / 9.* / 10.*` | `^8.0` | | **v11.10 - v11.11** | `8.* / 9.*` | `^8.0` | diff --git a/docs/README.md b/docs/README.md index c0b5b34..da4f0b7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -74,7 +74,7 @@ echo $post->translate('fr')->title; // Mon premier post ## Versions | Package | Laravel | PHP | -|:--------------------|:------------------------------|:----------| +| :------------------ | :---------------------------- | :-------- | | **v11.13 - v11.13** | `8.* / 9.* / 10.*` / `11.*` | `^8.0` | | **v11.12 - v11.12** | `8.* / 9.* / 10.*` | `^8.0` | | **v11.10 - v11.11** | `8.* / 9.*` | `^8.0` | From 29f50f75d830b3f1f6cf952e0e8ee2c91119ec91 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 17 Apr 2024 13:41:04 +0200 Subject: [PATCH 23/31] fix phpunit CI --- .github/workflows/phpunit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 540f9f4..cbf7968 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -24,7 +24,7 @@ jobs: phpunit: '9.*' - laravel: '10.*' phpunit: '10.*' - - laravel: '10.*' + - laravel: '11.*' phpunit: '10.*' exclude: - php: '8.0' From 76f2ebe4d9d6a981a0562ca76abc6c7b5eaeeae0 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 17 Apr 2024 13:42:22 +0200 Subject: [PATCH 24/31] do not ignore IDE files - global gitignore instead --- .gitignore | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitignore b/.gitignore index c9d4490..d054a8c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,3 @@ /.phpunit.cache /build/ /coverage.clover -/.idea -/.vscode -/.fleet From b73f7ad228c4631552c49a71dd4155f4840b017f Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 17 Apr 2024 13:43:22 +0200 Subject: [PATCH 25/31] update readme badges --- README.md | 4 ++-- docs/README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 20d34d8..1f44fe2 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,8 @@ [![Offset Earth](https://img.shields.io/badge/Treeware-%F0%9F%8C%B3-green?style=for-the-badge)](https://plant.treeware.earth/Astrotomic/laravel-translatable) [![Larabelles](https://img.shields.io/badge/Larabelles-%F0%9F%A6%84-lightpink?style=for-the-badge)](https://www.larabelles.com/) -[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/Astrotomic/laravel-translatable/run-tests?style=flat-square&logoColor=white&logo=github&label=Tests)](https://github.com/Astrotomic/laravel-translatable/actions?query=workflow%3Arun-tests) -[![StyleCI](https://styleci.io/repos/192333549/shield)](https://styleci.io/repos/192333549) +[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/Astrotomic/laravel-translatable/phpunit?style=flat-square&logoColor=white&logo=github&label=PHPunit)](https://github.com/Astrotomic/laravel-translatable/actions?query=workflow%3Aphpunit) +[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/Astrotomic/laravel-translatable/pint?style=flat-square&logoColor=white&logo=github&label=Pint)](https://github.com/Astrotomic/laravel-translatable/actions?query=workflow%3Apint) [![Codecov Coverage](https://img.shields.io/codecov/c/github/Astrotomic/laravel-translatable?logo=codecov&logoColor=white&label=Codecov&style=flat-square)](https://codecov.io/gh/Astrotomic/laravel-translatable) [![Total Downloads](https://img.shields.io/packagist/dt/astrotomic/laravel-translatable.svg?label=Downloads&style=flat-square)](https://packagist.org/packages/astrotomic/laravel-translatable) [![GitBook](https://img.shields.io/badge/GitBook-Astrotomic-7e57c2.svg?style=flat-square)](https://docs.astrotomic.info/laravel-translatable) diff --git a/docs/README.md b/docs/README.md index da4f0b7..7fd44eb 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,7 +2,7 @@ [![Latest Version](http://img.shields.io/packagist/v/astrotomic/laravel-translatable.svg?label=Release&style=for-the-badge)](https://packagist.org/packages/astrotomic/laravel-translatable) [![MIT License](https://img.shields.io/github/license/Astrotomic/laravel-translatable.svg?label=License&color=blue&style=for-the-badge)](https://github.com/Astrotomic/laravel-translatable/blob/master/LICENSE) [![Offset Earth](https://img.shields.io/badge/Treeware-%F0%9F%8C%B3-green?style=for-the-badge)](https://plant.treeware.earth/Astrotomic/laravel-translatable) -[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/Astrotomic/laravel-translatable/run-tests?style=flat-square&logoColor=white&logo=github&label=Tests)](https://github.com/Astrotomic/laravel-translatable/actions?query=workflow%3Arun-tests) [![StyleCI](https://styleci.io/repos/192333549/shield)](https://styleci.io/repos/192333549) [![Codecov Coverage](https://img.shields.io/codecov/c/github/Astrotomic/laravel-translatable?logo=codecov&logoColor=white&label=Codecov&style=flat-square)](https://codecov.io/gh/Astrotomic/laravel-translatable) [![Total Downloads](https://img.shields.io/packagist/dt/astrotomic/laravel-translatable.svg?label=Downloads&style=flat-square)](https://packagist.org/packages/astrotomic/laravel-translatable) +[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/Astrotomic/laravel-translatable/phpunit?style=flat-square&logoColor=white&logo=github&label=PHPunit)](https://github.com/Astrotomic/laravel-translatable/actions?query=workflow%3Aphpunit) [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/Astrotomic/laravel-translatable/pint?style=flat-square&logoColor=white&logo=github&label=Pint)](https://github.com/Astrotomic/laravel-translatable/actions?query=workflow%3Apint) [![Codecov Coverage](https://img.shields.io/codecov/c/github/Astrotomic/laravel-translatable?logo=codecov&logoColor=white&label=Codecov&style=flat-square)](https://codecov.io/gh/Astrotomic/laravel-translatable) [![Total Downloads](https://img.shields.io/packagist/dt/astrotomic/laravel-translatable.svg?label=Downloads&style=flat-square)](https://packagist.org/packages/astrotomic/laravel-translatable) ![Laravel Translatable](.gitbook/assets/socialcard.png) From e2e364ad432bef6791132f204f15fb164a2185cd Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 17 Apr 2024 13:45:14 +0200 Subject: [PATCH 26/31] fix php cs --- tests/Eloquent/Person.php | 4 ++-- tests/Eloquent/Vegetable.php | 8 ++++---- tests/EloquentOverrideTest.php | 2 +- tests/ScopesTest.php | 2 +- tests/TranslatableTest.php | 10 +++++----- tests/factories/CountryFactory.php | 2 +- tests/factories/VegetableFactory.php | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/Eloquent/Person.php b/tests/Eloquent/Person.php index dfd8fcd..656ae7a 100644 --- a/tests/Eloquent/Person.php +++ b/tests/Eloquent/Person.php @@ -8,8 +8,6 @@ class Person extends Eloquent implements TranslatableContract { - protected $table = 'people'; - use Translatable; /** @@ -42,6 +40,8 @@ class Person extends Eloquent implements TranslatableContract */ public $localeKey; + protected $table = 'people'; + /** * Mutate name attribute into upper-case. * diff --git a/tests/Eloquent/Vegetable.php b/tests/Eloquent/Vegetable.php index b91c336..afd57e0 100644 --- a/tests/Eloquent/Vegetable.php +++ b/tests/Eloquent/Vegetable.php @@ -10,15 +10,15 @@ class Vegetable extends Eloquent implements TranslatableContract { use Translatable; - protected $primaryKey = 'identity'; - public $translationForeignKey = 'vegetable_identity'; public $translatedAttributes = ['name']; - protected $fillable = ['quantity']; - public $localeKey; public $translationModel; + + protected $primaryKey = 'identity'; + + protected $fillable = ['quantity']; } diff --git a/tests/EloquentOverrideTest.php b/tests/EloquentOverrideTest.php index 6e2b550..4875bff 100644 --- a/tests/EloquentOverrideTest.php +++ b/tests/EloquentOverrideTest.php @@ -2,8 +2,8 @@ namespace Tests; -use Tests\Eloquent\Vegetable; use PHPUnit\Framework\Attributes\Test; +use Tests\Eloquent\Vegetable; final class EloquentOverrideTest extends TestCase { diff --git a/tests/ScopesTest.php b/tests/ScopesTest.php index f76cdad..98f51a9 100644 --- a/tests/ScopesTest.php +++ b/tests/ScopesTest.php @@ -2,9 +2,9 @@ namespace Tests; +use PHPUnit\Framework\Attributes\Test; use Tests\Eloquent\Country; use Tests\Eloquent\Vegetable; -use PHPUnit\Framework\Attributes\Test; final class ScopesTest extends TestCase { diff --git a/tests/TranslatableTest.php b/tests/TranslatableTest.php index f45857a..ed55ec5 100644 --- a/tests/TranslatableTest.php +++ b/tests/TranslatableTest.php @@ -3,17 +3,17 @@ namespace Tests; use Astrotomic\Translatable\Locales; +use Illuminate\Database\Eloquent\MassAssignmentException; +use Illuminate\Database\Eloquent\ModelNotFoundException; +use Illuminate\Support\Facades\App; +use Illuminate\Support\Facades\DB; +use PHPUnit\Framework\Attributes\Test; use Tests\Eloquent\Country; use Tests\Eloquent\CountryStrict; use Tests\Eloquent\CountryTranslation; use Tests\Eloquent\Person; use Tests\Eloquent\Vegetable; use Tests\Eloquent\VegetableTranslation; -use Illuminate\Database\Eloquent\MassAssignmentException; -use Illuminate\Database\Eloquent\ModelNotFoundException; -use Illuminate\Support\Facades\App; -use Illuminate\Support\Facades\DB; -use PHPUnit\Framework\Attributes\Test; final class TranslatableTest extends TestCase { diff --git a/tests/factories/CountryFactory.php b/tests/factories/CountryFactory.php index 1b8d3f8..5c4f1ca 100644 --- a/tests/factories/CountryFactory.php +++ b/tests/factories/CountryFactory.php @@ -1,8 +1,8 @@ Date: Sat, 13 Apr 2024 13:41:36 +0200 Subject: [PATCH 27/31] add phpstan and correct till level 5 --- composer.json | 2 ++ phpstan.neon | 18 ++++++++++++++++++ .../Exception/LocalesNotDefinedException.php | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 phpstan.neon diff --git a/composer.json b/composer.json index 47221a9..2392945 100644 --- a/composer.json +++ b/composer.json @@ -36,6 +36,7 @@ "illuminate/support": "^8.0 || ^9.0 || ^10.0 || ^11.0" }, "require-dev": { + "larastan/larastan": "^2.0", "laravel/legacy-factories": "^1.0.4", "laravel/pint": "^1.0", "mockery/mockery": "^1.3.3", @@ -66,6 +67,7 @@ }, "scripts": { "fix": "@php vendor/bin/pint", + "phpstan": "@php vendor/bin/phpstan analyse", "test": "@php vendor/bin/phpunit", "test-coverage": "@php vendor/bin/phpunit --coverage-html=build" } diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..95608f0 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,18 @@ +includes: + - vendor/larastan/larastan/extension.neon + +parameters: + + paths: + - src/ + + # Level 9 is the highest level + level: 6 + +# ignoreErrors: +# - '#PHPDoc tag @var#' +# +# excludePaths: +# - ./*/*/FileToBeExcluded.php +# +# checkMissingIterableValueType: false diff --git a/src/Translatable/Exception/LocalesNotDefinedException.php b/src/Translatable/Exception/LocalesNotDefinedException.php index 13dbdb6..6d2dfc0 100644 --- a/src/Translatable/Exception/LocalesNotDefinedException.php +++ b/src/Translatable/Exception/LocalesNotDefinedException.php @@ -6,6 +6,6 @@ class LocalesNotDefinedException extends \Exception { public static function make(): self { - return new static('Please make sure you have run `php artisan vendor:publish --provider="Astrotomic\Translatable\TranslatableServiceProvider"` and that the locales configuration is defined.'); + return new self('Please make sure you have run `php artisan vendor:publish --provider="Astrotomic\Translatable\TranslatableServiceProvider"` and that the locales configuration is defined.'); } } From 87ea0913ce94dfb2e5d63e69f7cbf6446df201bc Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 17 Apr 2024 13:51:35 +0200 Subject: [PATCH 28/31] fix CI --- .github/workflows/phpunit.yml | 8 +------- README.md | 4 ++-- composer.json | 8 ++++---- docs/README.md | 4 ++-- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index cbf7968..6caeb38 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -14,12 +14,10 @@ jobs: fail-fast: false matrix: php: [8.0, 8.1, 8.2, 8.3] - laravel: [8.*, 9.*, 10.*, 11.*] + laravel: [9.*, 10.*, 11.*] dependency-version: [prefer-stable] os: [ubuntu-latest] include: - - laravel: '8.*' - phpunit: '9.*' - laravel: '9.*' phpunit: '9.*' - laravel: '10.*' @@ -31,10 +29,6 @@ jobs: laravel: '10.*' - php: '8.0' laravel: '11.*' - - php: '8.2' - laravel: '8.*' - - php: '8.3' - laravel: '8.*' - php: '8.3' laravel: '9.*' - php: '8.1' diff --git a/README.md b/README.md index 1f44fe2..11d9c27 100644 --- a/README.md +++ b/README.md @@ -97,8 +97,8 @@ If you discover any security related issues, please check [SECURITY](https://git ## Versions | Package | Laravel | PHP | -| :------------------ | :---------------------------- | :-------- | -| **v11.13 - v11.13** | `8.* / 9.* / 10.*` / `11.*` | `^8.0` | +| :------------------ |:------------------------------| :-------- | +| **v11.13 - v11.13** | `9.* / 10.* / 11.*` | `^8.0` | | **v11.12 - v11.12** | `8.* / 9.* / 10.*` | `^8.0` | | **v11.10 - v11.11** | `8.* / 9.*` | `^8.0` | | **v11.6 - v11.9** | `5.8.* / 6.* / 7.* / 8.*` | `>=7.2` | diff --git a/composer.json b/composer.json index 2392945..4b18561 100644 --- a/composer.json +++ b/composer.json @@ -31,16 +31,16 @@ }, "require": { "php": "^8.0", - "illuminate/contracts": "^8.0 || ^9.0 || ^10.0 || ^11.0", - "illuminate/database": "^8.0 || ^9.0 || ^10.0 || ^11.0", - "illuminate/support": "^8.0 || ^9.0 || ^10.0 || ^11.0" + "illuminate/contracts": "^9.0 || ^10.0 || ^11.0", + "illuminate/database": "^9.0 || ^10.0 || ^11.0", + "illuminate/support": "^9.0 || ^10.0 || ^11.0" }, "require-dev": { "larastan/larastan": "^2.0", "laravel/legacy-factories": "^1.0.4", "laravel/pint": "^1.0", "mockery/mockery": "^1.3.3", - "orchestra/testbench": "^6.0 || ^7.0 || ^8.0 || ^9.0", + "orchestra/testbench": "^7.0 || ^8.0 || ^9.0", "phpunit/phpunit": "^10.0" }, "minimum-stability": "dev", diff --git a/docs/README.md b/docs/README.md index 7fd44eb..21c045e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -74,8 +74,8 @@ echo $post->translate('fr')->title; // Mon premier post ## Versions | Package | Laravel | PHP | -| :------------------ | :---------------------------- | :-------- | -| **v11.13 - v11.13** | `8.* / 9.* / 10.*` / `11.*` | `^8.0` | +| :------------------ |:------------------------------| :-------- | +| **v11.13 - v11.13** | `9.* / 10.* / 11.*` | `^8.0` | | **v11.12 - v11.12** | `8.* / 9.* / 10.*` | `^8.0` | | **v11.10 - v11.11** | `8.* / 9.*` | `^8.0` | | **v11.6 - v11.9** | `5.8.* / 6.* / 7.* / 8.*` | `>=7.2` | From cd5ba705066200c3ee4fd9f2e8d3d3e76247ba6b Mon Sep 17 00:00:00 2001 From: Gummibeer Date: Wed, 17 Apr 2024 11:51:57 +0000 Subject: [PATCH 29/31] Prettified Code! --- README.md | 2 +- docs/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 11d9c27..6b04000 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ If you discover any security related issues, please check [SECURITY](https://git ## Versions | Package | Laravel | PHP | -| :------------------ |:------------------------------| :-------- | +| :------------------ | :---------------------------- | :-------- | | **v11.13 - v11.13** | `9.* / 10.* / 11.*` | `^8.0` | | **v11.12 - v11.12** | `8.* / 9.* / 10.*` | `^8.0` | | **v11.10 - v11.11** | `8.* / 9.*` | `^8.0` | diff --git a/docs/README.md b/docs/README.md index 21c045e..124a834 100644 --- a/docs/README.md +++ b/docs/README.md @@ -74,7 +74,7 @@ echo $post->translate('fr')->title; // Mon premier post ## Versions | Package | Laravel | PHP | -| :------------------ |:------------------------------| :-------- | +| :------------------ | :---------------------------- | :-------- | | **v11.13 - v11.13** | `9.* / 10.* / 11.*` | `^8.0` | | **v11.12 - v11.12** | `8.* / 9.* / 10.*` | `^8.0` | | **v11.10 - v11.11** | `8.* / 9.*` | `^8.0` | From 92fb7a9b6e6fe68435e84680f8b36634c8938ab9 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 17 Apr 2024 13:54:13 +0200 Subject: [PATCH 30/31] improve yaml files --- .github/workflows/phpunit.yml | 4 ++-- .github/workflows/pint.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 6caeb38..908a694 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -13,8 +13,8 @@ jobs: strategy: fail-fast: false matrix: - php: [8.0, 8.1, 8.2, 8.3] - laravel: [9.*, 10.*, 11.*] + php: ['8.0', '8.1', '8.2', '8.3'] + laravel: ['9.*', '10.*', '11.*'] dependency-version: [prefer-stable] os: [ubuntu-latest] include: diff --git a/.github/workflows/pint.yml b/.github/workflows/pint.yml index 79b0a9b..26337ce 100644 --- a/.github/workflows/pint.yml +++ b/.github/workflows/pint.yml @@ -8,9 +8,9 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 5 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: shivammathur/setup-php@v2 with: - php-version: 8.2 + php-version: 8.3 - run: composer install --prefer-dist --no-interaction --no-suggest - run: vendor/bin/pint --test From 88baff32a60a132bf15d9e7b6484541290b18ec0 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 17 Apr 2024 13:55:20 +0200 Subject: [PATCH 31/31] improve yaml files --- .github/workflows/composer-normalize.yml | 4 ++-- .github/workflows/dependabot-auto-merge.yml | 4 ++-- .github/workflows/markdown-normalize.yml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/composer-normalize.yml b/.github/workflows/composer-normalize.yml index d2d63d1..7ee8d0b 100644 --- a/.github/workflows/composer-normalize.yml +++ b/.github/workflows/composer-normalize.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Git checkout - uses: actions/checkout@v4.1.2 + uses: actions/checkout@v4 - name: Validate Composer configuration run: composer validate --strict @@ -22,6 +22,6 @@ jobs: composer global config --no-plugins allow-plugins.ergebnis/composer-normalize true composer normalize --indent-style=space --indent-size=4 --no-check-lock --no-update-lock --no-interaction --ansi - - uses: stefanzweifel/git-auto-commit-action@v4.15.4 + - uses: stefanzweifel/git-auto-commit-action@v5 with: commit_message: normalize composer.json diff --git a/.github/workflows/dependabot-auto-merge.yml b/.github/workflows/dependabot-auto-merge.yml index f772133..c8ac6ef 100644 --- a/.github/workflows/dependabot-auto-merge.yml +++ b/.github/workflows/dependabot-auto-merge.yml @@ -13,7 +13,7 @@ jobs: - name: Dependabot metadata id: metadata - uses: dependabot/fetch-metadata@v1.6.0 + uses: dependabot/fetch-metadata@v2 with: github-token: "${{ secrets.GITHUB_TOKEN }}" compat-lookup: true @@ -37,4 +37,4 @@ jobs: run: gh pr merge --auto --merge "$PR_URL" env: PR_URL: ${{github.event.pull_request.html_url}} - GH_TOKEN: ${{secrets.GITHUB_TOKEN}} \ No newline at end of file + GH_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/.github/workflows/markdown-normalize.yml b/.github/workflows/markdown-normalize.yml index c4b9710..e90e6d9 100644 --- a/.github/workflows/markdown-normalize.yml +++ b/.github/workflows/markdown-normalize.yml @@ -11,9 +11,9 @@ jobs: runs-on: ubuntu-latest steps: - name: Git checkout - uses: actions/checkout@v4.1.2 + uses: actions/checkout@v4 - name: Prettify markdown - uses: creyD/prettier_action@v4.3 + uses: creyD/prettier_action@v4 with: prettier_options: --write **/*.md