Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch of changes for package; Add Laravel 11 support #395

Merged
merged 16 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
62 changes: 52 additions & 10 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,23 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [8.0, 8.1]
laravel: [8.*, 9.*, 10.*]
php: [8.0, 8.1, 8.2, 8.3]
laravel: ['8.*', '9.*', '10.*', '11.*']
dependency-version: [prefer-stable]
os: [ubuntu-latest]
exclude:
- laravel: 10.*
php: 8.0

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
- php: '8.0'
laravel: '10.*'
- php: '8.0'
laravel: '11.*'
- php: '8.1'
laravel: '11.*'
- php: '8.2'
laravel: '8.*'
- php: '8.3'
laravel: '8.*'
- php: '8.3'
laravel: '9.*'

steps:
- name: Checkout code
Expand All @@ -46,10 +54,44 @@ jobs:
coverage: xdebug
tools: composer:v2

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
- name: Select Laravel 8
uses: nick-invision/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
command: composer require "laravel/framework:^8.83.27" "phpunit/phpunit:^9.6.15" --no-update --no-interaction
if: "matrix.laravel == '8.*'"

- name: Select Laravel 9
uses: nick-invision/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
command: composer require "laravel/framework:^9.52.16" "phpunit/phpunit:^9.6.15" --no-update --no-interaction
if: "matrix.laravel == '9.*'"

- name: Select Laravel 10
uses: nick-invision/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
command: composer require "laravel/framework:^10.34.2" "phpunit/phpunit:^10.4.2" --no-update --no-interaction
if: "matrix.laravel == '10.*'"

- name: Select Laravel 11
uses: nick-invision/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
command: composer require "laravel/framework:^11.0" "phpunit/phpunit:^10.4.2" --no-update --no-interaction
if: "matrix.laravel == '11.*'"

- name: Install PHP Dependencies
uses: nick-invision/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/vendor/
/composer.lock
/coverage/
/.phpunit.result.cache
/.phpunit.cache
/build/
/coverage.clover
/.idea
/.vscode
/.fleet
35 changes: 0 additions & 35 deletions .php_cs

This file was deleted.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ If you discover any security related issues, please check [SECURITY](https://git
## Versions

| Package | Laravel | PHP |
|:--------------------|:------------------------------| :-------- |
|:--------------------|:------------------------------|:----------|
| **v11.13 - v11.13** | `8.* / 9.* / 10.*` / `11.*` | `^8.0` |
| **v11.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` |
Expand Down
13 changes: 7 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@
},
"require": {
"php": "^8.0",
"illuminate/contracts": "^8.0 || ^9.0 || ^10.0",
"illuminate/database": "^8.0 || ^9.0 || ^10.0",
"illuminate/support": "^8.0 || ^9.0 || ^10.0"
"illuminate/contracts": "^8.0 || ^9.0 || ^10.0 || ^11.0",
"illuminate/database": "^8.0 || ^9.0 || ^10.0 || ^11.0",
"illuminate/support": "^8.0 || ^9.0 || ^10.0 || ^11.0"
},
"require-dev": {
"laravel/legacy-factories": "^1.0.4",
"laravel/pint": "^1.0",
"mockery/mockery": "^1.3.3",
"orchestra/testbench": "^6.0 || ^7.0 || ^8.0",
"phpunit/phpunit": "^9.0"
"orchestra/testbench": "^6.0 || ^7.0 || ^8.0 || ^9.0",
"phpunit/phpunit": "^10.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand All @@ -64,7 +65,7 @@
}
},
"scripts": {
"csfix": "php-cs-fixer fix --using-cache=no",
"lint": "pint src/Translatable",
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-html=build"
}
Expand Down
3 changes: 2 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ echo $post->translate('fr')->title; // Mon premier post
## Versions

| Package | Laravel | PHP |
|:--------------------|:------------------------------| :-------- |
|:--------------------|:------------------------------|:----------|
| **v11.13 - v11.13** | `8.* / 9.* / 10.*` / `11.*` | `^8.0` |
| **v11.12 - v11.12** | `8.* / 9.* / 10.*` | `^8.0` |
| **v11.10 - v11.11** | `8.* / 9.*` | `^8.0` |
| **v11.6 - v11.9** | `5.8.* / 6.* / 7.* / 8.*` | `>=7.2` |
Expand Down
22 changes: 11 additions & 11 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
cacheDirectory="build"
backupStaticProperties="false"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
<directory suffix="Test.php">./tests/</directory>
<exclude>./tests/factories/</exclude>
<exclude>./tests/migrations/</exclude>
<exclude>./tests/models/</exclude>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="false">
<directory suffix=".php">./src/Translatable/</directory>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="DB_CONNECTION" value="testing"/>
<env name="DB_DATABASE" value=":memory:"/>
</php>
<source>
<include>
<directory suffix=".php">./src/Translatable/</directory>
</include>
</source>
</phpunit>
29 changes: 29 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
4 changes: 2 additions & 2 deletions src/Translatable/Contracts/Translatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);

Expand Down
10 changes: 5 additions & 5 deletions src/Translatable/Traits/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
6 changes: 3 additions & 3 deletions src/Translatable/Translatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
trait Translatable
{
use Scopes, Relationship;
use Relationship, Scopes;

protected static $autoloadTranslations = null;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion src/Translatable/Validation/RuleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
class RuleFactory
{
const FORMAT_ARRAY = 1;

const FORMAT_KEY = 2;

/**
Expand Down Expand Up @@ -77,6 +78,7 @@ public function parse(array $input): array
foreach ($input as $key => $value) {
if (! $this->isTranslatable($key)) {
$rules[$key] = $value;

continue;
}

Expand All @@ -94,7 +96,6 @@ protected function formatKey(string $locale, string $key): string
}

/**
* @param string $locale
* @param string|string[]|mixed $rule
* @return string|string[]|mixed
*/
Expand Down
Loading