diff --git a/.gitattributes b/.gitattributes index 65b9655b..78cc4c77 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/.github/workflows/composer-normalize.yml b/.github/workflows/composer-normalize.yml index d2d63d1f..7ee8d0b1 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 f7721335..c8ac6efa 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 c4b97100..e90e6d93 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 diff --git a/.github/workflows/run-tests.yml b/.github/workflows/phpunit.yml similarity index 67% rename from .github/workflows/run-tests.yml rename to .github/workflows/phpunit.yml index 7d666d47..908a694b 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/phpunit.yml @@ -1,42 +1,44 @@ -name: run-tests +name: phpunit on: push: pull_request: - schedule: - - 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 + fail-fast: false matrix: - php: [8.0, 8.1] - laravel: [8.*, 9.*, 10.*] + php: ['8.0', '8.1', '8.2', '8.3'] + laravel: ['9.*', '10.*', '11.*'] dependency-version: [prefer-stable] os: [ubuntu-latest] + include: + - laravel: '9.*' + phpunit: '9.*' + - laravel: '10.*' + phpunit: '10.*' + - laravel: '11.*' + phpunit: '10.*' exclude: - - laravel: 10.* - php: 8.0 + - php: '8.0' + laravel: '10.*' + - php: '8.0' + laravel: '11.*' + - php: '8.3' + laravel: '9.*' + - php: '8.1' + laravel: '11.*' name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }} steps: - name: Checkout code - uses: actions/checkout@v4.1.2 - - - 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- + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -49,6 +51,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/.github/workflows/pint.yml b/.github/workflows/pint.yml new file mode 100644 index 00000000..26337ce0 --- /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@v4 + - uses: shivammathur/setup-php@v2 + with: + php-version: 8.3 + - 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 5afb7970..00000000 --- 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/.gitignore b/.gitignore index f792fcc0..d054a8cb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ /vendor/ /composer.lock /coverage/ -/.phpunit.result.cache +/.phpunit.cache /build/ /coverage.clover diff --git a/.php_cs b/.php_cs deleted file mode 100644 index f310dd9b..00000000 --- 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 6deb8320..00000000 --- a/.styleci.yml +++ /dev/null @@ -1,3 +0,0 @@ -preset: laravel - -risky: true diff --git a/README.md b/README.md index ff36dd2a..6b04000e 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) @@ -97,7 +97,8 @@ 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` | | **v11.6 - v11.9** | `5.8.* / 6.* / 7.* / 8.*` | `>=7.2` | diff --git a/composer.json b/composer.json index 6988335b..4b185612 100644 --- a/composer.json +++ b/composer.json @@ -31,15 +31,17 @@ }, "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": "^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", - "phpunit/phpunit": "^9.0" + "orchestra/testbench": "^7.0 || ^8.0 || ^9.0", + "phpunit/phpunit": "^10.0" }, "minimum-stability": "dev", "prefer-stable": true, @@ -50,7 +52,7 @@ }, "autoload-dev": { "psr-4": { - "Astrotomic\\Translatable\\Tests\\": "tests/" + "Tests\\": "tests/" } }, "config": { @@ -64,8 +66,9 @@ } }, "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", + "phpstan": "@php vendor/bin/phpstan analyse", + "test": "@php vendor/bin/phpunit", + "test-coverage": "@php vendor/bin/phpunit --coverage-html=build" } } diff --git a/docs/README.md b/docs/README.md index ae0ab600..124a834f 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) @@ -74,7 +74,8 @@ 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` | | **v11.6 - v11.9** | `5.8.* / 6.* / 7.* / 8.*` | `>=7.2` | diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 00000000..95608f0e --- /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/phpunit.xml.dist b/phpunit.xml.dist index 5b011d3a..a92657e1 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,27 +1,26 @@ - ./tests/ + ./tests/ ./tests/factories/ - ./tests/migrations/ - ./tests/models/ + ./tests/Eloquent/ - - + + ./src/Translatable/ - - + + diff --git a/pint.json b/pint.json new file mode 100644 index 00000000..4373f2dd --- /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 + } + } +} diff --git a/src/Translatable/Contracts/Translatable.php b/src/Translatable/Contracts/Translatable.php index e8242260..748546d0 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/Exception/LocalesNotDefinedException.php b/src/Translatable/Exception/LocalesNotDefinedException.php index 13dbdb6d..6d2dfc0f 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.'); } } diff --git a/src/Translatable/Traits/Relationship.php b/src/Translatable/Traits/Relationship.php index 606368a6..22832dc5 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()); - } } diff --git a/src/Translatable/Translatable.php b/src/Translatable/Translatable.php index 17800bd4..41f5f8d4 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 bf0d30b3..fee16dbb 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 4fb18499..88a4bca3 100644 --- a/tests/Eloquent/Country.php +++ b/tests/Eloquent/Country.php @@ -1,6 +1,6 @@ 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 */ + #[Test] 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 */ + #[Test] 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 */ + #[Test] 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 */ + #[Test] public function it_finds_custom_primary_keys(): void { $vegetable = new Vegetable(); - static::assertEquals('vegetable_identity', $vegetable->getTranslationRelationKey()); + self::assertEquals('vegetable_identity', $vegetable->getTranslationRelationKey()); } - /** @test */ + #[Test] 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 3fa842c7..3d5c5f1f 100644 --- a/tests/LocalesTest.php +++ b/tests/LocalesTest.php @@ -1,40 +1,41 @@ 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 */ + #[Test] public function it_loads_the_locales_from_the_configuration(): void { $this->app['config']->set('translatable.locales', [ '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 */ + #[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', [ @@ -55,10 +56,10 @@ 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 */ + #[Test] public function it_loads_locales_and_countries(): void { $this->app['config']->set('translatable.locales', [ @@ -73,10 +74,10 @@ 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 */ + #[Test] public function can_return_locales_as_array(): void { $this->app['config']->set('translatable.locales', [ @@ -88,27 +89,27 @@ 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 */ + #[Test] 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 */ + #[Test] public function current_can_return_the_translator_locale_if_configuration_is_empty(): void { $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 */ + #[Test] public function it_checks_if_it_has_a_locale(): void { $this->app['config']->set('translatable.locales', [ @@ -120,11 +121,11 @@ 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 */ + #[Test] public function can_access_as_an_array(): void { $this->app['config']->set('translatable.locales', [ @@ -136,11 +137,11 @@ 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 */ + #[Test] public function can_retrieve_a_specific_locale_by_get(): void { $this->app['config']->set('translatable.locales', [ @@ -152,11 +153,11 @@ 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 */ + #[Test] public function missing_locale_returns_null_by_get(): void { $this->app['config']->set('translatable.locales', [ @@ -168,11 +169,11 @@ 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 */ + #[Test] public function it_can_add_a_locale(): void { $this->app['config']->set('translatable.locales', [ @@ -180,13 +181,13 @@ 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 */ + #[Test] public function locale_can_be_added_by_accessing_as_an_array(): void { $this->app['config']->set('translatable.locales', [ @@ -194,13 +195,13 @@ 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 */ + #[Test] public function locale_country_can_be_added_by_accessing_as_an_array(): void { $this->app['config']->set('translatable.locales', [ @@ -208,13 +209,13 @@ 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 */ + #[Test] public function can_forget_a_locale(): void { $this->app['config']->set('translatable.locales', [ @@ -223,13 +224,13 @@ 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 */ + #[Test] public function can_forget_a_locale_using_unset_as_an_array(): void { $this->app['config']->set('translatable.locales', [ @@ -238,45 +239,45 @@ 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 */ + #[Test] 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 */ + #[Test] public function can_set_a_default_locale_country_separator_if_configuration_is_missing(): void { $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 */ + #[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 */ + #[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 */ + #[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 900ad267..98f51a98 100644 --- a/tests/ScopesTest.php +++ b/tests/ScopesTest.php @@ -1,33 +1,34 @@ 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 */ + #[Test] public function translated_in_scope_works_with_default_locale(): void { app()->setLocale('de'); 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 */ + #[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à']); @@ -36,12 +37,12 @@ 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 */ + #[Test] public function not_translated_in_scope_works_with_default_locale(): void { app()->setLocale('en'); @@ -50,21 +51,21 @@ 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 */ + #[Test] public function translated_scope_returns_records_with_at_least_one_translation(): void { 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 */ + #[Test] public function lists_of_translated_fields(): void { app()->setLocale('de'); @@ -75,12 +76,12 @@ 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 */ + #[Test] public function lists_of_translated_fields_with_fallback(): void { app('config')->set('translatable.fallback_locale', 'en'); @@ -95,14 +96,14 @@ 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 */ + #[Test] public function lists_of_translated_fields_disable_autoload_translations(): void { app()->setLocale('de'); @@ -112,11 +113,11 @@ 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(); } - /** @test */ + #[Test] public function lists_of_translated_fields_enable_autoload_translations(): void { app()->setLocale('de'); @@ -126,7 +127,7 @@ public function lists_of_translated_fields_enable_autoload_translations(): void Country::enableAutoloadTranslations(); - static::assertEquals([[ + self::assertEquals([[ 'id' => 1, 'name' => 'Griechenland', 'translations' => [[ @@ -139,18 +140,18 @@ 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']); $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 */ + #[Test] public function scope_withTranslation_with_fallback(): void { app('config')->set('translatable.fallback_locale', 'de'); @@ -159,12 +160,12 @@ 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 */ + #[Test] public function scope_withTranslation_with_country_based_fallback(): void { app('config')->set('translatable.fallback_locale', 'en'); @@ -178,33 +179,33 @@ 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 */ + #[Test] 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 */ + #[Test] public function orWhereTranslation_filters_by_translation(): void { factory(Country::class)->create(['code' => 'gr', 'name:en' => 'Greece']); @@ -212,33 +213,33 @@ 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 */ + #[Test] 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 */ + #[Test] 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 */ + #[Test] public function orWhereTranslationLike_filters_by_translation(): void { factory(Country::class)->create(['code' => 'gr', 'name:en' => 'Greece']); @@ -246,43 +247,43 @@ 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 */ + #[Test] 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 */ + #[Test] 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 */ + #[Test] 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 */ + #[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']]); @@ -290,10 +291,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/TestCase.php b/tests/TestCase.php index dc25859e..063f376c 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -1,6 +1,6 @@ getTranslationModelNameDefault() ); } - /** @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'); - static::assertEquals( + self::assertEquals( 'App\Models\Translations\VegetableTranslation', (new Vegetable())->getTranslationModelNameDefault() ); } - /** @test */ + #[Test] public function it_finds_the_translation_class_with_suffix_set(): void { $this->app->make('config')->set('translatable.translation_suffix', 'Trans'); - static::assertEquals( - 'Astrotomic\Translatable\Tests\Eloquent\VegetableTrans', + self::assertEquals( + 'Tests\Eloquent\VegetableTrans', (new Vegetable())->getTranslationModelName() ); } - /** @test */ + #[Test] 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() ); } - /** @test */ + #[Test] 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 */ + #[Test] 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 */ + #[Test] 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 */ + #[Test] 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 */ + #[Test] 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 */ + #[Test] public function it_saves_translations_with_mutator(): void { $vegetable = factory(Vegetable::class)->create(['name:el' => 'Αρακάς', 'name:en' => 'Peas']); @@ -132,36 +133,36 @@ 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 */ + #[Test] public function it_does_not_lazy_load_translations_when_updating_non_translated_attributes(): void { 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(); } - /** @test */ + #[Test] public function it_uses_default_locale_to_return_translations(): void { $vegetable = factory(Vegetable::class)->create(['name:el' => 'Αρακάς']); @@ -169,14 +170,14 @@ 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 */ + #[Test] public function it_creates_translations_using_the_shortcut(): void { $vegetable = factory(Vegetable::class)->create(); @@ -185,15 +186,15 @@ 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', ]); } - /** @test */ + #[Test] public function it_creates_translations_using_mass_assignment(): void { $vegetable = Vegetable::create([ @@ -201,86 +202,86 @@ 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 */ + #[Test] public function it_creates_translations_using_mass_assignment_and_locales(): void { $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 */ + #[Test] 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 */ + #[Test] 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 */ + #[Test] public function it_returns_default_translation(): void { $this->app->make('config')->set('translatable.fallback_locale', 'de'); $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 */ + #[Test] public function fallback_option_in_config_overrides_models_fallback_option(): void { $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 */ + #[Test] public function configuration_defines_if_fallback_is_used(): void { $this->app->make('config')->set('translatable.fallback_locale', 'de'); @@ -288,10 +289,10 @@ 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 */ + #[Test] public function useTranslationFallback_overrides_configuration(): void { $this->app->make('config')->set('translatable.fallback_locale', 'de'); @@ -300,20 +301,20 @@ 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 */ + #[Test] public function it_returns_null_if_fallback_is_not_defined(): void { $this->app->make('config')->set('translatable.fallback_locale', 'ch'); $vegetable = factory(Vegetable::class)->create(['name:en' => 'Peas']); - static::assertNull($vegetable->getTranslation('pl', true)); + 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'); @@ -321,14 +322,14 @@ 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 */ + #[Test] public function it_creates_a_new_translation(): void { $this->app->make('config')->set('translatable.fallback_locale', 'en'); @@ -337,32 +338,32 @@ 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 */ + #[Test] public function the_locale_key_is_locale_by_default(): void { $vegetable = new Vegetable(); - static::assertEquals('locale', $vegetable->getLocaleKey()); + 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'); $vegetable = new Vegetable(); - static::assertEquals('language_id', $vegetable->getLocaleKey()); + self::assertEquals('language_id', $vegetable->getLocaleKey()); } - /** @test */ + #[Test] 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,46 +374,46 @@ 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 */ + #[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 */ + #[Test] 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 */ + #[Test] 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 */ + #[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 */ + #[Test] public function it_throws_an_exception_if_translation_does_not_exist(): void { $this->expectException(ModelNotFoundException::class); @@ -421,46 +422,46 @@ 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'); } - /** @test */ + #[Test] 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 */ + #[Test] 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 */ + #[Test] 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 */ + #[Test] public function locale_separator_can_be_configured(): void { $this->app->make('config')->set('translatable.locales', ['en' => ['GB']]); @@ -470,10 +471,10 @@ 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 */ + #[Test] public function fallback_for_country_based_locales(): void { $this->app->make('config')->set('translatable.use_fallback', true); @@ -483,15 +484,15 @@ 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 */ + #[Test] public function fallback_for_country_based_locales_with_no_base_locale(): void { $this->app->make('config')->set('translatable.use_fallback', true); @@ -501,14 +502,14 @@ 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 */ + #[Test] public function to_array_and_fallback_with_country_based_locales_enabled(): void { $this->app->make('config')->set('translatable.locale', 'en-GB'); @@ -520,10 +521,10 @@ 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 */ + #[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); @@ -531,10 +532,10 @@ 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 */ + #[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); @@ -542,55 +543,55 @@ 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 */ + #[Test] public function it_should_mutate_the_translated_attribute_if_a_mutator_is_set_on_model(): void { $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 */ + #[Test] 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 */ + #[Test] 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 */ + #[Test] 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 */ + #[Test] public function fill_with_translation_key(): void { $vegetable = new Vegetable(); @@ -598,16 +599,16 @@ 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 */ + #[Test] public function it_uses_the_default_locale_from_the_model(): void { $vegetable = new Vegetable(); @@ -615,21 +616,21 @@ 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 */ + #[Test] public function replicate_entity(): void { $vegetable = new Vegetable(); @@ -643,22 +644,22 @@ 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 */ + #[Test] public function can_get_translations_as_array(): void { $vegetable = factory(Vegetable::class)->create([ @@ -667,34 +668,34 @@ public function can_get_translations_as_array(): void 'name:de' => 'Erbsen', ]); - static::assertEquals([ + self::assertEquals([ 'de' => ['name' => 'Erbsen'], 'en' => ['name' => 'Peas'], 'fr' => ['name' => 'Pois'], ], $vegetable->getTranslationsArray()); } - /** @test */ + #[Test] public function fill_will_ignore_unkown_locales(): void { config(['translatable.locales' => ['en']]); $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 */ + #[Test] public function fill_will_ignore_unkown_locales_with_translations(): void { config(['translatable.locales' => ['en']]); @@ -707,15 +708,15 @@ 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 */ + #[Test] public function it_uses_fallback_locale_if_default_is_empty(): void { $this->app->make('config')->set('translatable.use_fallback', true); @@ -728,12 +729,12 @@ 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 */ + #[Test] public function it_uses_value_when_fallback_is_not_available(): void { $this->app->make('config')->set('translatable.fallback_locale', 'it'); @@ -747,22 +748,22 @@ 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 */ + #[Test] public function empty_translated_attribute(): void { $this->app->setLocale('invalid'); $vegetable = factory(Vegetable::class)->create(); - static::assertNull($vegetable->name); + self::assertNull($vegetable->name); } - /** @test */ + #[Test] public function numeric_translated_attribute(): void { $this->app->make('config')->set('translatable.fallback_locale', 'de'); @@ -771,6 +772,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,13 +793,13 @@ 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 */ + #[Test] public function translation_relation(): void { $this->app->make('config')->set('translatable.fallback_locale', 'fr'); @@ -809,11 +811,11 @@ 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 */ + #[Test] public function translation_relation_can_use_fallback_locale(): void { $this->app->make('config')->set('translatable.fallback_locale', 'fr'); @@ -822,11 +824,11 @@ 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 */ + #[Test] public function translation_relation_returns_null_if_no_available_locale_was_found(): void { $this->app->make('config')->set('translatable.fallback_locale', 'xyz'); @@ -835,10 +837,10 @@ 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 */ + #[Test] public function can_fill_conflicting_attribute_locale(): void { $this->app->make('config')->set('translatable.locales', ['en', 'id']); @@ -860,12 +862,12 @@ 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 */ + #[Test] public function it_returns_first_existing_translation_as_fallback(): void { /** @var Locales $helper */ @@ -904,17 +906,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,19 +932,19 @@ 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 */ + #[Test] public function it_uses_translation_relation_if_locale_matches(): void { $this->app->make('config')->set('translatable.use_fallback', false); @@ -953,16 +955,16 @@ 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 */ + #[Test] public function it_uses_translations_relation_if_locale_does_not_match(): void { $this->app->make('config')->set('translatable.use_fallback', false); @@ -973,17 +975,17 @@ 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 */ + #[Test] public function it_does_not_load_translation_relation_if_not_already_loaded(): void { $this->app->make('config')->set('translatable.use_fallback', false); @@ -992,18 +994,18 @@ 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 */ - public function it_does_not_delete_translations_on_cascade_by_default() + #[Test] + public function it_does_not_delete_translations_on_cascade_by_default(): void { $vegetable = factory(Vegetable::class)->create(['name:en' => 'Peas']); @@ -1016,8 +1018,8 @@ public function it_does_not_delete_translations_on_cascade_by_default() $this->assertDatabaseHas('vegetable_translations', ['vegetable_identity' => $vegetable->identity]); } - /** @test */ - public function it_deletes_translations_on_cascade() + #[Test] + public function it_deletes_translations_on_cascade(): void { Vegetable::enableDeleteTranslationsCascade(); $vegetable = factory(Vegetable::class)->create(['name:en' => 'Peas']); @@ -1031,8 +1033,8 @@ public function it_deletes_translations_on_cascade() $this->assertDatabaseMissing('vegetable_translations', ['vegetable_identity' => $vegetable->identity]); } - /** @test */ - public function it_does_not_delete_on_cascade_after_retrieving_a_model() + #[Test] + public function it_does_not_delete_on_cascade_after_retrieving_a_model(): void { Vegetable::enableDeleteTranslationsCascade(); $vegetable = factory(Vegetable::class)->create(['name:en' => 'Peas']); @@ -1047,8 +1049,8 @@ public function it_does_not_delete_on_cascade_after_retrieving_a_model() $this->assertDatabaseHas('vegetable_translations', ['vegetable_identity' => $vegetable->identity]); } - /** @test */ - public function it_can_restore_translations_in_a_transaction() + #[Test] + public function it_can_restore_translations_in_a_transaction(): void { Vegetable::enableDeleteTranslationsCascade(); $vegetable = factory(Vegetable::class)->create(['name:en' => 'Peas']); diff --git a/tests/ValidationTest.php b/tests/ValidationTest.php index 889fef41..0085fa5a 100644 --- a/tests/ValidationTest.php +++ b/tests/ValidationTest.php @@ -1,16 +1,17 @@ 'required', ]; - static::assertEquals([ + self::assertEquals([ 'title' => 'required', 'en.content' => 'required', 'de.content' => 'required', @@ -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 = [ @@ -49,7 +50,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', @@ -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 = [ @@ -66,7 +67,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', @@ -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 = [ @@ -83,7 +84,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', @@ -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 = [ @@ -100,7 +101,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', @@ -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 = [ @@ -117,7 +118,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', @@ -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 = [ @@ -134,7 +135,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', @@ -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', [ @@ -158,7 +159,7 @@ public function format_array_it_uses_config_as_default(): void '%content%' => 'required', ]; - static::assertEquals([ + self::assertEquals([ 'title' => 'required', '%content%' => 'required', 'en.content' => 'required', @@ -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 = [ @@ -176,7 +177,7 @@ public function format_key_it_replaces_single_key(): void '%content%' => 'required', ]; - static::assertEquals([ + self::assertEquals([ 'title' => 'required', 'content:en' => 'required', 'content:de' => 'required', @@ -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 = [ @@ -193,7 +194,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', @@ -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 = [ @@ -210,7 +211,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', @@ -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', [ @@ -234,7 +235,7 @@ public function format_key_it_uses_config_as_default(): void '%content%' => 'required', ]; - static::assertEquals([ + self::assertEquals([ 'title' => 'required', '%content%' => 'required', 'content:en' => 'required', @@ -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 = [ @@ -252,7 +253,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', @@ -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 = [ @@ -287,7 +288,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', @@ -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 = [ @@ -308,7 +309,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', @@ -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 = [ @@ -329,7 +330,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', @@ -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 = [ @@ -354,14 +355,14 @@ 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 */ + #[Test] public function format_array_it_does_not_touch_non_string_rule_in_array(): void { $rules = [ @@ -376,18 +377,18 @@ 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 */ + #[Test] public function format_key_it_replaces_single_rule(): void { $rules = [ @@ -395,7 +396,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', @@ -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 = [ @@ -416,7 +417,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', @@ -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 = [ @@ -437,7 +438,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', @@ -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 = [ @@ -462,14 +463,14 @@ 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 */ + #[Test] public function format_key_it_does_not_touch_non_string_rule_in_array(): void { $rules = [ @@ -484,15 +485,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 diff --git a/tests/factories/CountryFactory.php b/tests/factories/CountryFactory.php index d27f5a97..5c4f1ca5 100644 --- a/tests/factories/CountryFactory.php +++ b/tests/factories/CountryFactory.php @@ -1,8 +1,8 @@