Skip to content

Commit

Permalink
Laravel 6 support (#154)
Browse files Browse the repository at this point in the history
* Laravel 6 support

* This version of PHPUnit is supported on PHP 7.2 and PHP 7.3.

* setUp void

* composer update dependencies

* fix : void setUp

* fix : void tearDown

* change composer to laravel 6

* Arr::get fix helper

* add new line .gitignore
  • Loading branch information
dmitryuk authored and William committed Sep 19, 2019
1 parent cd0d001 commit 37f5cd0
Show file tree
Hide file tree
Showing 25 changed files with 96 additions and 90 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ composer.phar
composer.lock
.DS_Store
tests/temp/database.sqlite
.idea
24 changes: 12 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
language: php

php:
- 7.0
- 7.1

before_script:
- travis_retry composer self-update
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source

script:
- phpunit
language: php

php:
- 7.2
- 7.3

before_script:
- travis_retry composer self-update
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source

script:
- phpunit
86 changes: 43 additions & 43 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
{
"name": "waavi/translation",
"description": "A Translation package for Laravel 5 with database and cache support",
"keywords": [
"waavi",
"laravel-translator",
"laravel",
"translator",
"translation",
"localization"
],
"license": "MIT",
"authors": [
{
"name": "Waavi",
"email": "info@waavi.com",
"homepage": "http://waavi.com"
}
],
"require": {
"laravel/framework": "~5.5",
"doctrine/dbal": "^2.5"
},
"require-dev": {
"phpunit/phpunit" : "~6.0",
"orchestra/testbench": "~3.5",
"mockery/mockery": "^0.9.9"
},
"autoload": {
"psr-4": {
"Waavi\\Translation\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Waavi\\Translation\\Test\\": "tests"
}
},
"minimum-stability": "dev",
"scripts": {
"test": "vendor/bin/phpunit"
}
}
{
"name": "waavi/translation",
"description": "A Translation package for Laravel 5 with database and cache support",
"keywords": [
"waavi",
"laravel-translator",
"laravel",
"translator",
"translation",
"localization"
],
"license": "MIT",
"authors": [
{
"name": "Waavi",
"email": "info@waavi.com",
"homepage": "http://waavi.com"
}
],
"require": {
"laravel/framework": "~6.0",
"doctrine/dbal": "^2.5"
},
"require-dev": {
"phpunit/phpunit" : "~8.3",
"orchestra/testbench": "~4.0",
"mockery/mockery": "^1.2.3"
},
"autoload": {
"psr-4": {
"Waavi\\Translation\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Waavi\\Translation\\Test\\": "tests"
}
},
"minimum-stability": "dev",
"scripts": {
"test": "vendor/bin/phpunit"
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ WAAVI is a web development studio based in Madrid, Spain. You can learn more abo
5.4.x | 2.2.x
5.5.x | 2.3.x and higher
5.6.x | 2.3.x and higher

6.x | 2.4.x and higher
## Features overview

- Allow dynamic changes to the site's text and translations.
Expand Down
3 changes: 2 additions & 1 deletion src/Loaders/DatabaseLoader.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace Waavi\Translation\Loaders;

use Illuminate\Support\Arr;
use Waavi\Translation\Repositories\TranslationRepository;

class DatabaseLoader extends Loader
Expand Down Expand Up @@ -41,7 +42,7 @@ public function loadSource($locale, $group, $namespace = '*')
$dotArray = $this->translationRepository->loadSource($locale, $namespace, $group);
$undot = [];
foreach ($dotArray as $item => $text) {
array_set($undot, $item, $text);
Arr::set($undot, $item, $text);
}
return $undot;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Repositories/LanguageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Illuminate\Config\Repository as Config;
use Illuminate\Foundation\Application;
use Illuminate\Support\Arr;
use Illuminate\Validation\Factory as Validator;
use Waavi\Translation\Models\Language;

Expand Down Expand Up @@ -177,7 +178,7 @@ public function percentTranslated($locale)
*/
public function validate(array $attributes)
{
$id = array_get($attributes, 'id', 'NULL');
$id = Arr::get($attributes, 'id', 'NULL');
$table = $this->model->getTable();
$rules = [
'locale' => "required|unique:{$table},locale,{$id}",
Expand Down
9 changes: 5 additions & 4 deletions src/Repositories/TranslationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Illuminate\Database\Query\JoinClause;
use Illuminate\Foundation\Application;
use Illuminate\Support\Arr;
use Illuminate\Support\NamespacedItemResolver;
use Waavi\Translation\Models\Translation;

Expand Down Expand Up @@ -165,7 +166,7 @@ public function deleteByCode($code)
public function loadArray(array $lines, $locale, $group, $namespace = '*')
{
// Transform the lines into a flat dot array:
$lines = array_dot($lines);
$lines = Arr::dot($lines);
foreach ($lines as $item => $text) {
if (is_string($text)) {
// Check if the entry exists in the database:
Expand Down Expand Up @@ -409,9 +410,9 @@ public function flagAsReviewed($id)
public function validate(array $attributes)
{
$table = $this->model->getTable();
$locale = array_get($attributes, 'locale', '');
$namespace = array_get($attributes, 'namespace', '');
$group = array_get($attributes, 'group', '');
$locale = Arr::get($attributes, 'locale', '');
$namespace = Arr::get($attributes, 'namespace', '');
$group = Arr::get($attributes, 'group', '');
$rules = [
'locale' => 'required',
'namespace' => 'required',
Expand Down
5 changes: 3 additions & 2 deletions src/Traits/Translatable.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace Waavi\Translation\Traits;

use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Str;

Expand Down Expand Up @@ -84,7 +85,7 @@ public function attributesToArray()
*/
public function translationCodeFor($attribute)
{
return array_get($this->attributes, "{$attribute}_translation", false);
return Arr::get($this->attributes, "{$attribute}_translation", false);
}

/**
Expand All @@ -107,7 +108,7 @@ public function rawValueRequested($attribute)
*/
public function getRawAttribute($attribute)
{
return array_get($this->attributes, $attribute, '');
return Arr::get($this->attributes, $attribute, '');
}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/UriLocalizer.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace Waavi\Translation;

use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Waavi\Translation\Repositories\LanguageRepository;

class UriLocalizer
Expand Down Expand Up @@ -94,10 +95,10 @@ protected function parseUrl($url, $segment = 0)
{
$parsedUrl = parse_url($url);
$parsedUrl['segments'] = array_values(array_filter(explode('/', $parsedUrl['path']), 'strlen'));
$localeCandidate = array_get($parsedUrl['segments'], $segment, false);
$localeCandidate = Arr::get($parsedUrl['segments'], $segment, false);
$parsedUrl['locale'] = in_array($localeCandidate, $this->availableLocales) ? $localeCandidate : null;
$parsedUrl['query'] = array_get($parsedUrl, 'query', false);
$parsedUrl['fragment'] = array_get($parsedUrl, 'fragment', false);
$parsedUrl['query'] = Arr::get($parsedUrl, 'query', false);
$parsedUrl['fragment'] = Arr::get($parsedUrl, 'fragment', false);
unset($parsedUrl['path']);
return $parsedUrl;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Cache/RepositoryFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class RepositoryFactoryTest extends TestCase
{
public function setUp()
public function setUp(): void
{
// During the parent's setup, both a 'es' 'Spanish' and 'en' 'English' languages are inserted into the database.
parent::setUp();
Expand Down
2 changes: 1 addition & 1 deletion tests/Cache/SimpleRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class SimpleRepositoryTest extends TestCase
{
public function setUp()
public function setUp(): void
{
// During the parent's setup, both a 'es' 'Spanish' and 'en' 'English' languages are inserted into the database.
parent::setUp();
Expand Down
2 changes: 1 addition & 1 deletion tests/Cache/TaggedRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class TaggedRepositoryTest extends TestCase
{
public function setUp()
public function setUp(): void
{
// During the parent's setup, both a 'es' 'Spanish' and 'en' 'English' languages are inserted into the database.
parent::setUp();
Expand Down
2 changes: 1 addition & 1 deletion tests/Cache/TranslationCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class TranslationCacheTest extends TestCase
{
public function setUp()
public function setUp(): void
{
// During the parent's setup, both a 'es' 'Spanish' and 'en' 'English' languages are inserted into the database.
parent::setUp();
Expand Down
4 changes: 2 additions & 2 deletions tests/Commands/FlushTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

class FlushTest extends TestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->cacheRepository = \App::make('translation.cache.repository');
}

public function tearDown()
public function tearDown(): void
{
parent::tearDown();
Mockery::close();
Expand Down
2 changes: 1 addition & 1 deletion tests/Commands/LoadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class LoadTest extends TestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->languageRepository = \App::make(LanguageRepository::class);
Expand Down
4 changes: 2 additions & 2 deletions tests/Loaders/CacheLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

class CacheLoaderTest extends TestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->cache = Mockery::mock(Cache::class);
$this->fallback = Mockery::mock(Loader::class);
$this->cacheLoader = new CacheLoader('en', $this->cache, $this->fallback, 60, 'translation');
}

public function tearDown()
public function tearDown(): void
{
Mockery::close();
parent::tearDown();
Expand Down
4 changes: 2 additions & 2 deletions tests/Loaders/DatabaseLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

class DatabaseLoaderTest extends TestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->translationRepository = \App::make(TranslationRepository::class);
$this->loader = new DatabaseLoader('es', $this->translationRepository);
}

public function tearDown()
public function tearDown():void
{
Mockery::close();
parent::tearDown();
Expand Down
4 changes: 2 additions & 2 deletions tests/Loaders/FileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

class FileLoaderTest extends TestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->laravelLoader = Mockery::mock(LaravelFileLoader::class);
$this->fileLoader = new FileLoader('en', $this->laravelLoader);
}

public function tearDown()
public function tearDown(): void
{
Mockery::close();
parent::tearDown();
Expand Down
4 changes: 2 additions & 2 deletions tests/Loaders/LoadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

class LoadTest extends TestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->laravelLoader = Mockery::mock(LaravelFileLoader::class);
// We will use the file loader:
$this->fileLoader = new FileLoader('en', $this->laravelLoader);
}

public function tearDown()
public function tearDown(): void
{
Mockery::close();
parent::tearDown();
Expand Down
4 changes: 2 additions & 2 deletions tests/Loaders/MixedLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

class MixedLoaderTest extends TestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->fileLoader = Mockery::mock(FileLoader::class);
$this->dbLoader = Mockery::mock(DatabaseLoader::class);
$this->mixedLoader = new MixedLoader('en', $this->fileLoader, $this->dbLoader);
}

public function tearDown()
public function tearDown(): void
{
Mockery::close();
parent::tearDown();
Expand Down
2 changes: 1 addition & 1 deletion tests/Repositories/LanguageRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class LanguageRepositoryTest extends TestCase
{
public function setUp()
public function setUp(): void
{
// During the parent's setup, both a 'es' 'Spanish' and 'en' 'English' languages are inserted into the database.
parent::setUp();
Expand Down
Loading

0 comments on commit 37f5cd0

Please sign in to comment.