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

Commit 0c1f96d

Browse files
jhm-cibermandimsav
authored andcommitted
Update to Laravel 5.8 (#550)
* Update to Laravel 5.8 -Removes the direct dependency on phpunit (since is required by orchestra/testbench) - Update tests to support phpunit 8.0.0 (some methods were deprecated) * Fix linting * Update readme compatibility table
1 parent 567b72a commit 0c1f96d

File tree

6 files changed

+43
-29
lines changed

6 files changed

+43
-29
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
],
1313
"require": {
1414
"php": ">=7.1.3",
15-
"illuminate/support": "5.6.*|5.7.*"
15+
"illuminate/support": "5.6.*|5.7.*|5.8.*"
1616
},
1717
"require-dev": {
18-
"orchestra/testbench": "3.6.*|3.7.*",
19-
"phpunit/phpunit": "~7.0"
18+
"dms/phpunit-arraysubset-asserts": "^0.1.0",
19+
"orchestra/testbench": "3.6.*|3.7.*|3.8.*"
2020
},
2121
"autoload": {
2222
"psr-4": {

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ This is a Laravel package for translatable models. Its goal is to remove the com
7373

7474
Laravel | Translatable
7575
:---------|:----------
76+
5.8 | 9.*
7677
5.7 | 9.*
7778
5.6 | 9.*
7879
5.5 | 8.*

tests/ScopesTest.php

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ public function test_lists_of_translated_fields()
5252
App::setLocale('de');
5353
App::make('config')->set('translatable.to_array_always_loads_translations', false);
5454

55-
$list = [[
56-
'id' => '1',
57-
'name' => 'Griechenland',
58-
]];
59-
$this->assertArraySubset($list, Country::listsTranslations('name')->get()->toArray());
55+
$arr = Country::listsTranslations('name')->get()->toArray();
56+
57+
$this->assertEquals(1, count($arr));
58+
$this->assertEquals('1', $arr[0]['id']);
59+
$this->assertEquals('Griechenland', $arr[0]['name']);
6060
}
6161

6262
public function test_lists_of_translated_fields_with_fallback()
@@ -73,7 +73,16 @@ public function test_lists_of_translated_fields_with_fallback()
7373
'id' => 2,
7474
'name' => 'France',
7575
]];
76-
$this->assertArraySubset($list, $country->listsTranslations('name')->get()->toArray());
76+
77+
$arr = $country->listsTranslations('name')->get()->toArray();
78+
79+
$this->assertEquals(2, count($arr));
80+
81+
$this->assertEquals(1, $arr[0]['id']);
82+
$this->assertEquals('Griechenland', $arr[0]['name']);
83+
84+
$this->assertEquals(2, $arr[1]['id']);
85+
$this->assertEquals('France', $arr[1]['name']);
7786
}
7887

7988
public function test_lists_of_translated_fields_disable_autoload_translations()
@@ -125,7 +134,18 @@ public function test_scope_withTranslation_with_country_based_fallback()
125134
['name' => 'Zucchini', 'locale' => 'de'],
126135
['name' => 'Zucchetti', 'locale' => 'de-CH'],
127136
];
128-
$this->assertArraySubset($expectedTranslations, $result['translations']);
137+
$translations = $result['translations'];
138+
139+
$this->assertEquals(3, count($translations));
140+
141+
$this->assertEquals('en', $translations[0]['locale']);
142+
$this->assertEquals('zucchini', $translations[0]['name']);
143+
144+
$this->assertEquals('de', $translations[1]['locale']);
145+
$this->assertEquals('Zucchini', $translations[1]['name']);
146+
147+
$this->assertEquals('de-CH', $translations[2]['locale']);
148+
$this->assertEquals('Zucchetti', $translations[2]['name']);
129149
}
130150

131151
public function test_whereTranslation_filters_by_translation()

tests/TestCoreModelExtension.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,20 @@ public function test_it_saves_translations_when_existing_and_dirty()
3838

3939
// Failing saving
4040

41-
/**
42-
* @expectedException \Exception
43-
*/
4441
public function test_it_throws_query_exception_if_code_is_null()
4542
{
43+
$this->expectException('\Exception');
44+
4645
$country = new Country();
4746
$country->name = 'Belgium';
4847
$country->code = null;
4948
$country->save();
5049
}
5150

52-
/**
53-
* @expectedException \Exception
54-
*/
5551
public function test_it_throws_query_exception_if_saving_and_name_is_null()
5652
{
53+
$this->expectException('\Exception');
54+
5755
$country = new Country();
5856
$country->code = 'be';
5957
$country->name = null;
@@ -88,21 +86,19 @@ public function test_it_returns_false_if_does_not_exist_and_parent_save_returns_
8886

8987
// Filling
9088

91-
/**
92-
* @expectedException Illuminate\Database\Eloquent\MassAssignmentException
93-
*/
9489
public function test_it_throws_exception_if_filling_a_protected_property()
9590
{
91+
$this->expectException(Illuminate\Database\Eloquent\MassAssignmentException::class);
92+
9693
$country = new CountryGuarded();
9794
$this->assertTrue($country->totallyGuarded());
9895
$country->fill(['code' => 'it', 'en' => ['name' => 'Italy']]);
9996
}
10097

101-
/**
102-
* @expectedException Illuminate\Database\Eloquent\MassAssignmentException
103-
*/
10498
public function test_translation_throws_exception_if_filling_a_protected_property()
10599
{
100+
$this->expectException(Illuminate\Database\Eloquent\MassAssignmentException::class);
101+
106102
$country = new Country();
107103
$country->translationModel = Model\CountryTranslationGuarded::class;
108104
$country->fill(['code' => 'it', 'en' => ['name' => 'Italy']]);

tests/TestsBase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class TestsBase extends TestCase
1313
const DB_USERNAME = 'homestead';
1414
const DB_PASSWORD = 'secret';
1515

16-
public function setUp()
16+
protected function setUp(): void
1717
{
1818
$this->makeSureDatabaseExists(static::DB_NAME);
1919

tests/TranslatableTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,9 @@ public function test_it_creates_translations_using_mass_assignment_and_locales()
217217
$this->assertEquals('Belgique', $country->translate('fr')->name);
218218
}
219219

220-
/**
221-
* @expectedException Illuminate\Database\Eloquent\MassAssignmentException
222-
*/
223220
public function test_it_skips_mass_assignment_if_attributes_non_fillable()
224221
{
222+
$this->expectException(Illuminate\Database\Eloquent\MassAssignmentException::class);
225223
$data = [
226224
'code' => 'be',
227225
'en' => ['name' => 'Belgium'],
@@ -376,11 +374,10 @@ public function test_getting_translated_field_does_not_create_translation()
376374
$this->assertSame($country->getTranslation('en'), null);
377375
}
378376

379-
/**
380-
* @expectedException Dimsav\Translatable\Exception\LocalesNotDefinedException
381-
*/
382377
public function test_if_locales_are_not_defined_throw_exception()
383378
{
379+
$this->expectException(Dimsav\Translatable\Exception\LocalesNotDefinedException::class);
380+
384381
$this->app->config->set('translatable.locales', []);
385382
new Country(['code' => 'pl']);
386383
}

0 commit comments

Comments
 (0)