Skip to content

Commit

Permalink
Merge pull request #6 from tectonic/feature/laravel-8
Browse files Browse the repository at this point in the history
Feature laravel 8
  • Loading branch information
kirkbushell authored Mar 21, 2022
2 parents cfe2ec3 + 2466a99 commit 29e9b18
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.idea*
vendor/*
composer.lock
composer.lock
.phpunit.result.cache
19 changes: 11 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
}
],
"require": {
"php": ">=7.0.0",
"illuminate/support": "5.*",
"illuminate/database": "5.*",
"tectonic/localisation": "^2.0.3"
"php": "^7.4|^8.0",
"illuminate/support": "^8.0",
"illuminate/database": "^8.0",
"tectonic/localisation": "^3.0"
},
"require-dev": {
"mockery/mockery": "dev-master@dev",
"orchestra/testbench": "3.*",
"phpunit/phpunit": "~5.7"
"mockery/mockery": "^1.4",
"orchestra/testbench": "*",
"phpunit/phpunit": "^9.0"
},
"autoload": {
"psr-4": {
Expand All @@ -28,5 +28,8 @@
"Tests\\": "tests/"
}
},
"minimum-stability": "stable"
"config": {
"preferred-install": "dist",
"sort-packages": true
}
}
5 changes: 4 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="all">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
<php>
<env name="DB_CONNECTION" value="testing"/>
<env name="APP_KEY" value="base64:2fl+Ktvkfl+Fuz4Qp/A75G2RTiWVA/ZoKZvp6fiiM10="/>
</php>
</phpunit>
2 changes: 1 addition & 1 deletion src/Database/TranslationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function findForUpdate(Translatable $model, $language, $field)
'field' => $field
]);

if (count($translations)) {
if (isset($translations[0])) {
return $translations[0];
}

Expand Down
2 changes: 1 addition & 1 deletion src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
use Tectonic\LaravelLocalisation\Database\EloquentTranslationRepository;
use Tectonic\LaravelLocalisation\Translator\Engine;
use Tectonic\LaravelLocalisation\Translator\Transformers\CollectionTransformer;
use Tectonic\LaravelLocalisation\Translator\Transformers\ModelTransformer;
use Tectonic\LaravelLocalisation\Translator\Transformers\PaginationTransformer;
use Tectonic\Localisation\Translator\Engine;
use Tectonic\Localisation\Contracts\TranslationRepository;

class ServiceProvider extends LaravelServiceProvider
Expand Down
18 changes: 18 additions & 0 deletions src/Translator/Engine.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
namespace Tectonic\LaravelLocalisation\Translator;

class Engine extends \Tectonic\Localisation\Translator\Engine
{

/**
* Alias for translate
*
* @param $object
* @param null $language
* @return mixed|object
*/
public function get($object, $language = null)
{
return parent::translate($object, $language);
}
}
11 changes: 7 additions & 4 deletions src/Translator/Transformers/CollectionTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ public function isAppropriateFor($object)
/**
* Once a transformer for an object has been found, it then must do whatever work is necessary on that object.
*
* @param Collection $collection
* @param Collection $collection
* @param null $language
* @return mixed
*/
public function transform($collection)
public function transform($collection, $language = null)
{
return $this->translate($collection, false);
}
Expand All @@ -34,10 +35,12 @@ public function transform($collection)
* Same as transform but should only translate objects one-level deep. With collections, we always
* have to pass off to the model transformer anyway, so just simply re-call the transform method.
*
* @param object $collection
* @param object $collection
* @param null $language
* @param null $fields
* @return mixed
*/
public function shallow($collection)
public function shallow($collection, $language = null, $fields = null)
{
return $this->translate($collection, true);
}
Expand Down
11 changes: 7 additions & 4 deletions src/Translator/Transformers/ModelTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,24 @@ public function isAppropriateFor($object)
/**
* Once a transformer for an object has been found, it then must do whatever work is necessary on that object.
*
* @param Model $model
* @param Model $model
* @param null $language
* @return mixed
*/
public function transform($model)
public function transform($model, $language = null)
{
return $this->translate($model, false);
}

/**
* Same as transform but should only translate objects one-level deep.
*
* @param object $model
* @param Model $model
* @param null $language
* @param null $fields
* @return mixed
*/
public function shallow($model)
public function shallow($model, $language = null, $fields = null)
{
return $this->translate($model, true);
}
Expand Down
13 changes: 8 additions & 5 deletions src/Translator/Transformers/PaginationTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ public function isAppropriateFor($object)
/**
* Once a transformer for an object has been found, it then must do whatever work is necessary on that object.
*
* @param object $paginator
* @param object $paginator
* @param null $language
* @return mixed
*/
public function transform($paginator)
public function transform($paginator, $language = null)
{
$transformer = App::make(CollectionTransformer::class);

Expand All @@ -40,12 +41,14 @@ public function transform($paginator)
/**
* Same as transform but should only translate objects one-level deep.
*
* @param object $paginator
* @param object $paginator
* @param null $language
* @param array $fields
* @return mixed
*/
public function shallow($paginator)
public function shallow($paginator, $language = null, $fields = [])
{
return $this->transform($paginator);
return $this->transform($paginator, $language);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/AcceptanceTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class AcceptanceTestCase extends TestCase
{
use Testable;

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
6 changes: 2 additions & 4 deletions tests/Database/TranslationServiceTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace tests\Database;
namespace Tests\Database;

use Mockery as m;
use Tectonic\LaravelLocalisation\Database\TranslationService;
Expand Down Expand Up @@ -42,11 +42,9 @@ public function testTranslationCreation()
$this->assertEquals($translation, $service->create($model, 'en', 'name', 'colours'));
}

/**
* @expectedException Tectonic\LaravelLocalisation\Database\TranslationNotFound
*/
public function testTranslationUpdateWithNullTranslation()
{
$this->expectException(\Tectonic\LaravelLocalisation\Database\TranslationNotFound::class);
$repository = m::mock(TranslationRepository::class);
$repository->shouldReceive('getByCriteria')->once()->andReturn(null);
$service = new TranslationService($repository);
Expand Down
6 changes: 5 additions & 1 deletion tests/Stubs/Model.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace tests\Stubs;
namespace Tests\Stubs;

use Tectonic\Localisation\Contracts\Translatable;
use Tectonic\Localisation\Translator\Translations;
Expand All @@ -19,4 +19,8 @@ public function getTranslatableFields()
{
return ['name'];
}

public function touch()
{
}
}
11 changes: 8 additions & 3 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
<?php
namespace Tests;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\TestCase as IlluminatedTestCase;
use Mockery as m;
use Orchestra\Testbench\Concerns\CreatesApplication;

class TestCase extends \PHPUnit_Framework_TestCase
class TestCase extends IlluminatedTestCase
{
use RefreshDatabase;
use Testable;
use CreatesApplication;

public function setUp()
public function setUp(): void
{
parent::setUp();
m::close();

$this->init();
}
}

0 comments on commit 29e9b18

Please sign in to comment.