diff --git a/.gitignore b/.gitignore index 166ef74..37727c5 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ Homestead.yaml Homestead.json .env **/.DS_Store +.idea/* diff --git a/.travis.yml b/.travis.yml index 2fffed2..d14393b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: php php: - - '7.0' - - '7.1' + - '7.2' + - '7.3' before_script: composer install --dev script: phpunit diff --git a/composer.json b/composer.json index 3d5318f..53deb1c 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "keywords": ["laravel", "database", "import", "artisan"], "license": "MIT", "require": { - "illuminate/support": "^5" + "illuminate/support": ">=5.7" }, "authors": [ { diff --git a/src/Import.php b/src/Import.php index 1c15ceb..03f8906 100644 --- a/src/Import.php +++ b/src/Import.php @@ -3,6 +3,7 @@ namespace Nicklayb\LaravelDbImport; use DB; +use Illuminate\Support\Str; /** * Class for Import process @@ -207,7 +208,7 @@ public function hasTableFilter($table) */ public function getFilterName($table) { - return 'filter'.studly_case($table); + return 'filter'. Str::studly($table); } /** @@ -258,16 +259,21 @@ public function hashPassword($password) */ public function getSortedSourceTables() { - $tables = $this->getSourceTables(); $filteredTables = collect([]); $holds = collect([]); - foreach ($tables as $table) { - if ($this->hasLastTable($table)) { - $holds->push($table); + + foreach ($this->getSourceTables() as $table) { + $index = $this->hasLastTable($table); + if ($index >= 0) { + $holds->put($index, $table); } elseif (!$this->hasIgnoreTable($table)) { $filteredTables->push($table); } } + $arrayHolds = $holds->toArray(); + ksort($arrayHolds); + $holds = collect($arrayHolds); + return $filteredTables->merge($holds); } @@ -282,13 +288,14 @@ public function hasIgnoreTable($table) } /** - * Check if a specified table should be last + * Gets the index of a table in the last tables array * - * @return bool + * @return int */ public function hasLastTable($table) { - return in_array($table, $this->lastTables); + $index = array_search($table, $this->lastTables); + return ($index !== false) ? $index : -1; } /** @@ -325,7 +332,7 @@ public function getPasswordResetValues($table) * * @return bool */ - public function needsRefrseh() + public function needsRefresh() { return $this->refresh; } @@ -348,7 +355,7 @@ public function hasLastTables() */ public function getManipulationName($table) { - return 'manipulate'.studly_case($table); + return 'manipulate'.Str::studly($table); } /** diff --git a/src/ImportCommand.php b/src/ImportCommand.php index 794264d..dc6f8c9 100644 --- a/src/ImportCommand.php +++ b/src/ImportCommand.php @@ -31,7 +31,7 @@ class ImportCommand extends Command * * @var string */ - protected $description = 'Import data from a source database to a destionation database'; + protected $description = 'Import data from a source database to a destination database'; /** * Import to execute @@ -118,7 +118,7 @@ public function handle() { if ($this->boot()) { $this->bar->start(); - if ($this->import->needsRefrseh()) { + if ($this->import->needsRefresh()) { $this->bar->setMessage('Refreshing'); Artisan::call('migrate:refresh'); } diff --git a/tests/ImportTest.php b/tests/ImportTest.php index 96c41eb..2c9d8c8 100644 --- a/tests/ImportTest.php +++ b/tests/ImportTest.php @@ -11,7 +11,7 @@ class BasicImport extends Nicklayb\LaravelDbImport\Import class ExtendedImport extends Nicklayb\LaravelDbImport\Import { protected $ignoreTables = [ 'migrations' ]; - protected $lastTables = [ 'relation_one', 'relation_two' ]; + protected $lastTables = [ 'relation_two','relation_one' ]; protected $selects = [ 'users' => [ 'id', 'firstname', 'lastname' @@ -89,12 +89,12 @@ public function testHasIgnoreTableInexistant() public function testHasLastTable() { - $this->assertTrue($this->extendedImport->hasLastTable('relation_one')); + $this->assertEquals($this->extendedImport->hasLastTable('relation_one'), 1); } public function testHasLastTableInexistant() { - $this->assertFalse($this->extendedImport->hasLastTable('products')); + $this->assertEquals($this->extendedImport->hasLastTable('products'), -1); } public function testHasPasswordReset() @@ -236,10 +236,12 @@ public function testGetSortedSourceTables() 'products', 'roles', 'orders', - 'relation_one', - 'relation_two' + 'relation_two', + 'relation_one' ]; - - $this->assertEquals($expected, $this->extendedImport->getSortedSourceTables()->toArray()); + $tables = $this->extendedImport->getSortedSourceTables()->toArray(); + for ($i = 0; $i < count($tables) ; $i++) { + $this->assertEquals($expected[$i], $tables[$i]); + } } }