Skip to content

Commit

Permalink
Workflow fix and tests update (#173)
Browse files Browse the repository at this point in the history
* added .idea folder into .gitignore

* added .phpunit.cache folder into .gitignore

* phpunit.xml.dist schema updated

* code style

* PHPUnit replaced by Pest

* Tests refactoring

* PHP 8.0 compatibility

* github test runner fixed

* PHP CS Fixer added and reconfigured

* PHP CS Fixer configuration rules fix

* PHP CS Fixer configuration rules fixed

* Update composer.json

* Update composer.json and run-tests.yml

* Revert "Update composer.json and run-tests.yml"

This reverts commit a3d8682.

* Update composer.json

* removed unused migration

* removed constants and comments in test files

* removed DOCBlocks form Pest.php

* removed declare(strict_types=1);

* Fix styling

* package ServiceProvider updated with spatie/laravel-package-tools

* updated README.md

* Fix Laravel 8 compatibility

* grammar fix README.md

* Translation loading fix

* Fix styling

* Revert "Fix styling"

This reverts commit a43c7b5.

* Revert "Translation loading fix"

This reverts commit 57e03e4.

* $this->app['config'] -> config()

---------

Co-authored-by: alex <aleksandar.naydenov@delta.bg>
Co-authored-by: aon4o <aon4o@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 11, 2024
1 parent c946d94 commit de25698
Show file tree
Hide file tree
Showing 35 changed files with 579 additions and 652 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Check & fix styling

on: [push]
on: [ push ]

jobs:
style:
Expand All @@ -13,7 +13,7 @@ jobs:
- name: Fix style
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php_cs --allow-risky=yes
args: --config=.php-cs-fixer.php --allow-risky=yes

- name: Extract branch name
shell: bash
Expand Down
98 changes: 49 additions & 49 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
name: run-tests

on:
- push
- pull_request
- push
- pull_request

jobs:
test:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: [8.2, 8.1, 8.0]
laravel: ['8.*', '9.*', '10.*', '11.*']
dependency-version: [prefer-stable]
include:
- laravel: 10.*
testbench: 8.*
- laravel: 9.*
testbench: 7.*
- laravel: 8.*
testbench: 6.*
- laravel: 11.*
testbench: 9.*
exclude:
- laravel: 10.*
php: 8.0
- laravel: 11.*
php: 8.1
- laravel: 11.*
php: 8.0

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
coverage: none

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "nesbot/carbon:^2.63" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
- name: Execute tests
run: vendor/bin/phpunit
test:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
php: [ 8.2, 8.1, 8.0 ]
laravel: [ '8.*', '9.*', '10.*', '11.*' ]
dependency-version: [ prefer-stable ]
include:
- laravel: 10.*
testbench: 8.*
- laravel: 9.*
testbench: 7.*
- laravel: 8.*
testbench: 6.*
- laravel: 11.*
testbench: 9.*
exclude:
- laravel: 10.*
php: 8.0
- laravel: 11.*
php: 8.1
- laravel: 11.*
php: 8.0

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
coverage: none

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "nesbot/carbon:^2.63" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
- name: Execute tests
run: composer test
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ build
composer.lock
docs
vendor
.php_cs.cache
.php-cs-fixer.cache
.phpunit.cache
.phpunit.result.cache
.idea
30 changes: 23 additions & 7 deletions .php_cs → .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,46 @@
->ignoreDotFiles(true)
->ignoreVCS(true);

return PhpCsFixer\Config::create()
return (new PhpCsFixer\Config())
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sortAlgorithm' => 'alpha'],
'array_syntax' => [
'syntax' => 'short',
],
'ordered_imports' => [
'sort_algorithm' => 'alpha',
],
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'trailing_comma_in_multiline_array' => true,
'trailing_comma_in_multiline' => [
'elements' => [
'arrays',
],
],
'phpdoc_scalar' => true,
'unary_operator_spaces' => true,
'binary_operator_spaces' => true,
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
'statements' => [
'break',
'continue',
'declare',
'return',
'throw',
'try',
],
],
'phpdoc_single_line_var_spacing' => true,
'phpdoc_var_without_name' => true,
'class_attributes_separation' => [
'elements' => [
'method', 'property',
'method' => 'one',
'property' => 'one',
],
],
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
'keep_multiple_spaces_after_comma' => true,
]
],
])
->setFinder($finder);
55 changes: 36 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,35 @@
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/spatie/laravel-translation-loader/run-tests.yml?branch=main&label=Tests&style=flat-square)
[![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-translation-loader.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-translation-loader)

In a vanilla Laravel or Lumen installation you can use [language files](https://laravel.com/docs/localization) to localize your app. This package will enable the translations to be stored in the database. You can still use all the features of [the `__` helper function](https://laravel.com/docs/localization#retrieving-translation-strings) you know and love.
In a vanilla Laravel or Lumen installation, you can use [language files](https://laravel.com/docs/localization) to
localize your app. This package will enable the translations to be stored in the database. You can still use all the
features of [the `__` helper function](https://laravel.com/docs/localization#retrieving-translation-strings) you know
and love.

```php
__('messages.welcome', ['name' => 'dayle']);
```

You can even mix using language files and the database. If a translation is present in both a file and the database, the database version will be returned.
You can even mix using language files and the database. If a translation is present in both a file and the database, the
database version will be returned.

Want to use a different source for your translations? No problem! The package is [easily extendable](https://github.com/spatie/laravel-translation-loader#creating-your-own-translation-providers).
Want to use a different source for your translations? No problem! The package
is [easily extendable](https://github.com/spatie/laravel-translation-loader#creating-your-own-translation-providers).

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).
Spatie is a web design agency based in Antwerp, Belgium.
You'll find an overview of all our open source
projects [on our website](https://spatie.be/opensource).

## Support us

[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/laravel-translation-loader.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/laravel-translation-loader)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can
support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.
You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards
on [our virtual postcard wall](https://spatie.be/open-source/postcards).

## Installation

Expand All @@ -48,14 +58,14 @@ Spatie\TranslationLoader\TranslationServiceProvider::class,
You must publish and run the migrations to create the `language_lines` table:

```bash
php artisan vendor:publish --provider="Spatie\TranslationLoader\TranslationServiceProvider" --tag="migrations"
php artisan vendor:publish --provider="Spatie\TranslationLoader\TranslationServiceProvider" --tag="translation-loader-migrations"
php artisan migrate
```

Optionally you could publish the config file using this command.
Optionally, you could publish the config file using this command.

```bash
php artisan vendor:publish --provider="Spatie\TranslationLoader\TranslationServiceProvider" --tag="config"
php artisan vendor:publish --provider="Spatie\TranslationLoader\TranslationServiceProvider" --tag="translation-loader-config"
```

This is the contents of the published config file:
Expand All @@ -78,18 +88,19 @@ return [
'model' => Spatie\TranslationLoader\LanguageLine::class,

/*
* This is the translation manager which overrides the default Laravel `translation.loader`
* This is the translation manager that overrides the default Laravel `translation.loader`
*/
'translation_manager' => Spatie\TranslationLoader\TranslationLoaderManager::class,

];
```

> **Note:** publishing assets doesn't work out of the box in Lumen. Instead you have to copy the files from the repo.
> **Note:** publishing assets doesn't work out of the box in Lumen. Instead, you have to copy the files from the repo.
## Usage

You can create a translation in the database by creating and saving an instance of the `Spatie\TranslationLoader\LanguageLine`-model:
You can create a translation in the database by creating and saving an instance of
the `Spatie\TranslationLoader\LanguageLine`-model:

```php
use Spatie\TranslationLoader\LanguageLine;
Expand All @@ -101,7 +112,8 @@ LanguageLine::create([
]);
```

You can fetch the translation with [Laravel's default `__` function](https://laravel.com/docs/localization#retrieving-translation-strings):
You can fetch the translation
with [Laravel's default `__` function](https://laravel.com/docs/localization#retrieving-translation-strings):

```php
__('validation.required'); // returns 'This is a required field'
Expand All @@ -111,15 +123,19 @@ app()->setLocale('nl');
__('validation.required'); // returns 'Dit is een verplicht veld'
```

You can still keep using the default language files as well. If a requested translation is present in both the database and the language files, the database version will be returned.
You can still keep using the default language files as well. If a requested translation is present in both the database
and the language files, the database version will be returned.

If you need to store/override json translation lines, just create a normal LanguageLine with `group => '*'`.
If you need to store/override JSON translation lines, just create a normal LanguageLine with `group => '*'`.

## Creating your own translation providers

This package ships with a translation provider than can fetch translations from the database. If you're storing your translations in a yaml-file, a csv-file, or ... you can easily extend this package by creating your own translation provider.
This package ships with a translation provider that can fetch translations from the database.
If you're storing your translations in a yaml-file, a csv-file, etc.,
you can easily extend this package by creating your own translation provider.

A translation provider can be any class that implements the `Spatie\TranslationLoader\TranslationLoaders\TranslationLoader`-interface. It contains only one method:
A translation provider can be any class that implements
the `Spatie\TranslationLoader\TranslationLoaders\TranslationLoader`-interface. It contains only one method:

```php
namespace Spatie\TranslationLoader\TranslationLoaders;
Expand All @@ -137,7 +153,7 @@ Translation providers can be registered in the `translation_loaders` key of the

## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
Please see [CHANGELOG](CHANGELOG.md) for more information about what has changed recently.

## Testing

Expand All @@ -151,7 +167,8 @@ Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTI

## Security

If you've found a bug regarding security please mail [security@spatie.be](mailto:security@spatie.be) instead of using the issue tracker.
If you've found a bug regarding security, please mail [security@spatie.be](mailto:security@spatie.be) instead of using
the issue tracker.

## Credits

Expand Down
20 changes: 13 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
}
],
"require": {
"php": "^7.2|^8.0",
"illuminate/translation": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0"
"php": "^8.0",
"illuminate/translation": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
"spatie/laravel-package-tools": "^1.12"
},
"require-dev": {
"phpunit/phpunit": "^8.0|^9.0|^10.5",
"orchestra/testbench": "^4.0|^5.0|^6.0|^7.0|^8.0|^9.0"
"friendsofphp/php-cs-fixer": "^3.59",
"orchestra/testbench": "^6.0|^7.0|^8.0|^9.0",
"pestphp/pest": "^1.23|^2.0"
},
"autoload": {
"psr-4": {
Expand All @@ -36,14 +38,18 @@
},
"autoload-dev": {
"psr-4": {
"Spatie\\TranslationLoader\\Test\\": "tests"
"Tests\\": "tests"
}
},
"scripts": {
"test": "vendor/bin/phpunit"
"test": "vendor/bin/pest",
"lint": "vendor/bin/php-cs-fixer fix"
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true
}
},
"extra": {
"laravel": {
Expand Down
2 changes: 1 addition & 1 deletion database/migrations/create_language_lines_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ return new class extends Migration
public function up(): void
{
Schema::create('language_lines', function (Blueprint $table) {
$table->bigIncrements('id');
$table->id();
$table->string('group')->index();
$table->string('key');
$table->json('text');
Expand Down
29 changes: 29 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
cacheDirectory=".phpunit.cache"
>
<coverage>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<testsuites>
<testsuite name="Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>./app</directory>
<directory>./src</directory>
</include>
</source>
</phpunit>
Loading

0 comments on commit de25698

Please sign in to comment.