-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from DanAtFh/import-non-default-connection
fix issue where data did not seed on non-default connection
- Loading branch information
Showing
3 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,11 @@ protected function getEnvironmentSetUp($app) | |
'database' => ':memory:', | ||
'prefix' => '', | ||
]); | ||
$app['config']->set('database.connections.csvSeederTest2', [ | ||
'driver' => 'sqlite', | ||
'database' => ':memory:', | ||
'prefix' => '', | ||
]); | ||
} | ||
|
||
/** @test */ | ||
|
@@ -436,4 +441,34 @@ public function it_offsets() | |
'age' => 54 | ||
]); | ||
} | ||
/** @test */ | ||
public function it_imports_with_non_default_connection() | ||
{ | ||
$seeder = new \Flynsarmy\CsvSeeder\CsvSeeder(); | ||
$seeder->table = 'tests_users2'; | ||
$seeder->filename = __DIR__ . '/csvs/users.csv'; | ||
$seeder->connection = 'csvSeederTest2'; | ||
$seeder->hashable = []; | ||
$seeder->run(); | ||
|
||
// Make sure the rows imported | ||
$this->assertDatabaseHas('tests_users2', [ | ||
'id' => 1, | ||
'first_name' => 'Abe', | ||
'last_name' => 'Abeson', | ||
'email' => '[email protected]', | ||
'age' => 50, | ||
'created_at' => null, | ||
'updated_at' => null, | ||
], 'csvSeederTest2'); | ||
$this->assertDatabaseHas('tests_users2', [ | ||
'id' => 3, | ||
'first_name' => 'Charly', | ||
'last_name' => 'Charlyson', | ||
'email' => '[email protected]', | ||
'age' => 52, | ||
'created_at' => null, | ||
'updated_at' => null, | ||
], 'csvSeederTest2'); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
tests/migrations/2021_02_08_000000_create_second_tests_users_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class CreateSecondTestsUsersTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::connection('csvSeederTest2')->create('tests_users2', function ($table) { | ||
$table->increments('id'); | ||
$table->string('first_name')->default(''); | ||
$table->string('last_name')->default(''); | ||
$table->string('email')->default(''); | ||
$table->string('password')->default(''); | ||
$table->string('address')->default(''); | ||
$table->integer('age')->default(0); | ||
$table->timestamps(); | ||
}); | ||
} | ||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::connection('csvSeederTest2')->drop('tests_users2'); | ||
} | ||
} |