Skip to content
This repository was archived by the owner on Jun 18, 2019. It is now read-only.

Update to Laravel 5.8 #550

Merged
merged 3 commits into from
Feb 27, 2019
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
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
],
"require": {
"php": ">=7.1.3",
"illuminate/support": "5.6.*|5.7.*"
"illuminate/support": "5.6.*|5.7.*|5.8.*"
},
"require-dev": {
"orchestra/testbench": "3.6.*|3.7.*",
"phpunit/phpunit": "~7.0"
"dms/phpunit-arraysubset-asserts": "^0.1.0",
"orchestra/testbench": "3.6.*|3.7.*|3.8.*"
},
"autoload": {
"psr-4": {
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ This is a Laravel package for translatable models. Its goal is to remove the com

Laravel | Translatable
:---------|:----------
5.8 | 9.*
5.7 | 9.*
5.6 | 9.*
5.5 | 8.*
Expand Down
34 changes: 27 additions & 7 deletions tests/ScopesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ public function test_lists_of_translated_fields()
App::setLocale('de');
App::make('config')->set('translatable.to_array_always_loads_translations', false);

$list = [[
'id' => '1',
'name' => 'Griechenland',
]];
$this->assertArraySubset($list, Country::listsTranslations('name')->get()->toArray());
$arr = Country::listsTranslations('name')->get()->toArray();

$this->assertEquals(1, count($arr));
$this->assertEquals('1', $arr[0]['id']);
$this->assertEquals('Griechenland', $arr[0]['name']);
}

public function test_lists_of_translated_fields_with_fallback()
Expand All @@ -73,7 +73,16 @@ public function test_lists_of_translated_fields_with_fallback()
'id' => 2,
'name' => 'France',
]];
$this->assertArraySubset($list, $country->listsTranslations('name')->get()->toArray());

$arr = $country->listsTranslations('name')->get()->toArray();

$this->assertEquals(2, count($arr));

$this->assertEquals(1, $arr[0]['id']);
$this->assertEquals('Griechenland', $arr[0]['name']);

$this->assertEquals(2, $arr[1]['id']);
$this->assertEquals('France', $arr[1]['name']);
}

public function test_lists_of_translated_fields_disable_autoload_translations()
Expand Down Expand Up @@ -125,7 +134,18 @@ public function test_scope_withTranslation_with_country_based_fallback()
['name' => 'Zucchini', 'locale' => 'de'],
['name' => 'Zucchetti', 'locale' => 'de-CH'],
];
$this->assertArraySubset($expectedTranslations, $result['translations']);
$translations = $result['translations'];

$this->assertEquals(3, count($translations));

$this->assertEquals('en', $translations[0]['locale']);
$this->assertEquals('zucchini', $translations[0]['name']);

$this->assertEquals('de', $translations[1]['locale']);
$this->assertEquals('Zucchini', $translations[1]['name']);

$this->assertEquals('de-CH', $translations[2]['locale']);
$this->assertEquals('Zucchetti', $translations[2]['name']);
}

public function test_whereTranslation_filters_by_translation()
Expand Down
20 changes: 8 additions & 12 deletions tests/TestCoreModelExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,20 @@ public function test_it_saves_translations_when_existing_and_dirty()

// Failing saving

/**
* @expectedException \Exception
*/
public function test_it_throws_query_exception_if_code_is_null()
{
$this->expectException('\Exception');

$country = new Country();
$country->name = 'Belgium';
$country->code = null;
$country->save();
}

/**
* @expectedException \Exception
*/
public function test_it_throws_query_exception_if_saving_and_name_is_null()
{
$this->expectException('\Exception');

$country = new Country();
$country->code = 'be';
$country->name = null;
Expand Down Expand Up @@ -88,21 +86,19 @@ public function test_it_returns_false_if_does_not_exist_and_parent_save_returns_

// Filling

/**
* @expectedException Illuminate\Database\Eloquent\MassAssignmentException
*/
public function test_it_throws_exception_if_filling_a_protected_property()
{
$this->expectException(Illuminate\Database\Eloquent\MassAssignmentException::class);

$country = new CountryGuarded();
$this->assertTrue($country->totallyGuarded());
$country->fill(['code' => 'it', 'en' => ['name' => 'Italy']]);
}

/**
* @expectedException Illuminate\Database\Eloquent\MassAssignmentException
*/
public function test_translation_throws_exception_if_filling_a_protected_property()
{
$this->expectException(Illuminate\Database\Eloquent\MassAssignmentException::class);

$country = new Country();
$country->translationModel = Model\CountryTranslationGuarded::class;
$country->fill(['code' => 'it', 'en' => ['name' => 'Italy']]);
Expand Down
2 changes: 1 addition & 1 deletion tests/TestsBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TestsBase extends TestCase
const DB_USERNAME = 'homestead';
const DB_PASSWORD = 'secret';

public function setUp()
protected function setUp(): void
{
$this->makeSureDatabaseExists(static::DB_NAME);

Expand Down
9 changes: 3 additions & 6 deletions tests/TranslatableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,9 @@ public function test_it_creates_translations_using_mass_assignment_and_locales()
$this->assertEquals('Belgique', $country->translate('fr')->name);
}

/**
* @expectedException Illuminate\Database\Eloquent\MassAssignmentException
*/
public function test_it_skips_mass_assignment_if_attributes_non_fillable()
{
$this->expectException(Illuminate\Database\Eloquent\MassAssignmentException::class);
$data = [
'code' => 'be',
'en' => ['name' => 'Belgium'],
Expand Down Expand Up @@ -376,11 +374,10 @@ public function test_getting_translated_field_does_not_create_translation()
$this->assertSame($country->getTranslation('en'), null);
}

/**
* @expectedException Dimsav\Translatable\Exception\LocalesNotDefinedException
*/
public function test_if_locales_are_not_defined_throw_exception()
{
$this->expectException(Dimsav\Translatable\Exception\LocalesNotDefinedException::class);

$this->app->config->set('translatable.locales', []);
new Country(['code' => 'pl']);
}
Expand Down