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

Commit 77da527

Browse files
authored
Merge pull request #556 from dimsav/ft-laravel-58
upgrade everything for Laravel 5.8
2 parents 0c1f96d + a38cc39 commit 77da527

File tree

5 files changed

+72
-134
lines changed

5 files changed

+72
-134
lines changed

.circleci/config.yml

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,46 @@ version: 2
6464

6565
jobs:
6666
build:
67+
docker:
68+
- image: 'circleci/php:latest'
69+
environment:
70+
LARAVEL_VERSION: '@stable'
71+
- image: 'circleci/mysql:5.7'
72+
command: 'mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_bin --innodb-large-prefix=true --innodb-file-format=Barracuda'
73+
environment:
74+
MYSQL_USER: 'root'
75+
MYSQL_ALLOW_EMPTY_PASSWORD: true
76+
<<: *defaults
77+
78+
build-php73-laravel58:
6779
docker:
6880
- image: 'circleci/php:7.3'
6981
environment:
70-
LARAVEL_VERSION: '5.7.*'
82+
LARAVEL_VERSION: '5.8.*'
83+
- image: 'circleci/mysql:5.7'
84+
command: 'mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_bin --innodb-large-prefix=true --innodb-file-format=Barracuda'
85+
environment:
86+
MYSQL_USER: 'root'
87+
MYSQL_ALLOW_EMPTY_PASSWORD: true
88+
<<: *defaults
89+
90+
build-php72-laravel58:
91+
docker:
92+
- image: 'circleci/php:7.2'
93+
environment:
94+
LARAVEL_VERSION: '5.8.*'
95+
- image: 'circleci/mysql:5.7'
96+
command: 'mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_bin --innodb-large-prefix=true --innodb-file-format=Barracuda'
97+
environment:
98+
MYSQL_USER: 'root'
99+
MYSQL_ALLOW_EMPTY_PASSWORD: true
100+
<<: *defaults
101+
102+
build-php71-laravel58:
103+
docker:
104+
- image: 'circleci/php:7.1'
105+
environment:
106+
LARAVEL_VERSION: '5.8.*'
71107
- image: 'circleci/mysql:5.7'
72108
command: 'mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_bin --innodb-large-prefix=true --innodb-file-format=Barracuda'
73109
environment:
@@ -151,9 +187,8 @@ workflows:
151187
version: 2
152188
build_all:
153189
jobs:
154-
- build-php73-laravel57
155-
- build-php72-laravel57
190+
- build-php73-laravel58
191+
- build-php72-laravel58
192+
- build-php71-laravel58
156193
- build-php71-laravel57
157-
- build-php73-laravel56
158-
- build-php72-laravel56
159194
- build-php71-laravel56

composer.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,24 @@
77
{
88
"name": "Dimitrios Savvopoulos",
99
"email": "[email protected]",
10-
"homepage": "http://dimsav.com"
10+
"homepage": "http://dimsav.com",
11+
"role": "Developer"
12+
},
13+
{
14+
"name": "Tom Witkowski",
15+
"email": "[email protected]",
16+
"homepage": "https://gummibeer.de",
17+
"role": "Developer"
1118
}
1219
],
20+
"support": {
21+
"issues": "https://github.com/dimsav/laravel-translatable/issues"
22+
},
1323
"require": {
1424
"php": ">=7.1.3",
1525
"illuminate/support": "5.6.*|5.7.*|5.8.*"
1626
},
1727
"require-dev": {
18-
"dms/phpunit-arraysubset-asserts": "^0.1.0",
1928
"orchestra/testbench": "3.6.*|3.7.*|3.8.*"
2029
},
2130
"autoload": {

phpunit.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
convertNoticesToExceptions="true"
88
convertWarningsToExceptions="true"
99
processIsolation="false"
10-
stopOnFailure="false"
10+
stopOnFailure="true"
1111
>
1212
<testsuites>
1313
<testsuite name="Package Test Suite">
@@ -16,7 +16,7 @@
1616
</testsuites>
1717
<filter>
1818
<whitelist processUncoveredFilesFromWhitelist="false">
19-
<file>./Translatable/Translatable.php</file>
19+
<file>./src/Translatable/Translatable.php</file>
2020
</whitelist>
2121
</filter>
2222
</phpunit>

tests/TestsBase.php

Lines changed: 9 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -15,79 +15,30 @@ class TestsBase extends TestCase
1515

1616
protected function setUp(): void
1717
{
18-
$this->makeSureDatabaseExists(static::DB_NAME);
19-
20-
if (! static::$db2Setup) {
21-
$this->makeSureDatabaseExists(static::DB_NAME2);
22-
}
23-
2418
parent::setUp();
2519

26-
if (! static::$db2Setup) {
27-
$this->makeSureSchemaIsCreated('mysql2');
28-
$this->truncateAllTablesButMigrations(static::DB_NAME2);
29-
static::$db2Setup = true;
30-
}
31-
32-
$this->makeSureSchemaIsCreated('mysql');
33-
$this->enableQueryCounter();
20+
$this->migrate('mysql');
3421
$this->refreshSeedData();
3522
}
3623

37-
private function refreshSeedData()
24+
protected function refreshSeedData()
3825
{
39-
$this->truncateAllTablesButMigrations(static::DB_NAME);
4026
$seeder = new AddFreshSeeds;
4127
$seeder->run();
4228
}
4329

44-
private function makeSureDatabaseExists($dbName)
45-
{
46-
$this->runQuery('CREATE DATABASE IF NOT EXISTS '.$dbName);
47-
}
48-
49-
private function makeSureSchemaIsCreated($dbConnectionName)
30+
protected function migrate($dbConnectionName)
5031
{
5132
$migrationsPath = '../../../../tests/migrations';
52-
$artisan = $this->app->make('Illuminate\Contracts\Console\Kernel');
33+
$artisan = $this->app->make(\Illuminate\Contracts\Console\Kernel::class);
5334

5435
// Makes sure the migrations table is created
55-
$artisan->call('migrate', [
36+
$artisan->call('migrate:fresh', [
5637
'--database' => $dbConnectionName,
5738
'--path' => $migrationsPath,
5839
]);
5940
}
6041

61-
private function truncateAllTablesButMigrations($dbName)
62-
{
63-
$db = $this->app->make('db');
64-
$db->statement('SET FOREIGN_KEY_CHECKS=0;');
65-
66-
foreach ($tables = $db->select('SHOW TABLES') as $table) {
67-
$table = $table->{'Tables_in_'.$dbName};
68-
if ($table != 'migrations') {
69-
$db->table($table)->truncate();
70-
}
71-
}
72-
$db->statement('SET FOREIGN_KEY_CHECKS=1;');
73-
}
74-
75-
/**
76-
* @param $query
77-
* return void
78-
*/
79-
private function runQuery($query)
80-
{
81-
$dbUsername = static::DB_USERNAME;
82-
$dbPassword = static::DB_PASSWORD;
83-
84-
$command = "mysql -u $dbUsername ";
85-
$command .= $dbPassword ? " -p$dbPassword" : '';
86-
$command .= " -e '$query'";
87-
88-
exec($command.' 2>/dev/null');
89-
}
90-
9142
public function testRunningMigration()
9243
{
9344
$country = Country::find(1);
@@ -96,7 +47,9 @@ public function testRunningMigration()
9647

9748
protected function getPackageProviders($app)
9849
{
99-
return ['Dimsav\Translatable\TranslatableServiceProvider'];
50+
return [
51+
\Dimsav\Translatable\TranslatableServiceProvider::class,
52+
];
10053
}
10154

10255
protected function getEnvironmentSetUp($app)
@@ -129,69 +82,6 @@ protected function getEnvironmentSetUp($app)
12982

13083
protected function getPackageAliases($app)
13184
{
132-
return ['Eloquent' => 'Illuminate\Database\Eloquent\Model'];
133-
}
134-
135-
protected function enableQueryCounter()
136-
{
137-
$that = $this;
138-
DB::listen(function (\Illuminate\Database\Events\QueryExecuted $query) use ($that) {
139-
$that->queriesCount++;
140-
// echo("\n--- Query {$that->queriesCount} --- {$this->beautifyQuery($this->insertBindingsIntoQuery($query->sql, $this->formatBindingsForSqlInjection($query->bindings)))}\n");
141-
});
142-
}
143-
144-
private function beautifyQuery($query)
145-
{
146-
$capitalizeWords = ['select ', ' from ', ' where ', ' on ', ' join '];
147-
$newLineWords = ['select ', 'from ', 'where ', 'join '];
148-
foreach ($capitalizeWords as $word) {
149-
$query = str_replace($word, strtoupper($word), $query);
150-
}
151-
152-
foreach ($newLineWords as $word) {
153-
$query = str_replace($word, "\n$word", $query);
154-
$word = strtoupper($word);
155-
$query = str_replace($word, "\n$word", $query);
156-
}
157-
158-
return $query;
159-
}
160-
161-
/**
162-
* @param $bindings
163-
*
164-
* @return mixed
165-
*/
166-
private function formatBindingsForSqlInjection($bindings)
167-
{
168-
foreach ($bindings as $i => $binding) {
169-
if ($binding instanceof DateTime) {
170-
$bindings[$i] = $binding->format('\'Y-m-d H:i:s\'');
171-
} else {
172-
if (is_string($binding)) {
173-
$bindings[$i] = "'$binding'";
174-
}
175-
}
176-
}
177-
178-
return $bindings;
179-
}
180-
181-
/**
182-
* @param $query
183-
* @param $bindings
184-
*
185-
* @return string
186-
*/
187-
private function insertBindingsIntoQuery($query, $bindings)
188-
{
189-
if (empty($bindings)) {
190-
return $query;
191-
}
192-
193-
$query = str_replace(['%', '?'], ['%%', '%s'], $query);
194-
195-
return vsprintf($query, $bindings);
85+
return ['Eloquent' => \Illuminate\Database\Eloquent\Model::class];
19686
}
19787
}

tests/TranslatableTest.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,8 @@ public function test_it_always_uses_value_when_fallback_not_available()
706706

707707
public function test_translation_with_multiconnection()
708708
{
709+
$this->migrate('mysql2');
710+
709711
// Add country & translation in second db
710712
$country = new Country();
711713
$country->setConnection('mysql2');
@@ -718,18 +720,20 @@ public function test_translation_with_multiconnection()
718720
// Verify added country & translation in second db
719721
$country = new Country();
720722
$country->setConnection('mysql2');
721-
$sgCountry = $country->find($countryId);
722-
$this->assertEquals('Singapore', $sgCountry->translate('sg')->name);
723+
$sgCountry2 = $country->newQuery()->find($countryId);
724+
$this->assertEquals('Singapore', $sgCountry2->translate('sg')->name);
723725

724726
// Verify added country not in default db
725727
$country = new Country();
726-
$sgCountry = $country::where('code', 'sg')->get();
727-
$this->assertEmpty($sgCountry);
728+
$country->setConnection('mysql');
729+
$sgCountry1 = $country->newQuery()->where('code', 'sg')->get();
730+
$this->assertEmpty($sgCountry1);
728731

729732
// Verify added translation not in default db
730733
$country = new Country();
731-
$sgCountry = $country->find($countryId);
732-
$this->assertEmpty($sgCountry->translate('sg'));
734+
$country->setConnection('mysql');
735+
$sgCountry1 = $country->newQuery()->find($countryId);
736+
$this->assertEmpty($sgCountry1->translate('sg'));
733737
}
734738

735739
public function test_empty_translated_attribute()

0 commit comments

Comments
 (0)