Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Flynsarmy committed Sep 4, 2015
1 parent 47cbcfc commit 9b6b261
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
35 changes: 30 additions & 5 deletions tests/CsvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,45 @@ public function testCanOpenCSV()

// Test an openable CSV
$expected = "resource";
$actual = $seeder->openCSV(__DIR__.'/csvs/test.csv');
$actual = $seeder->openCSV(__DIR__.'/csvs/users.csv');
$this->assertInternalType($expected, $actual);

// Test a non-openable CSV
$expected = FALSE;
$actual = $seeder->openCSV(__DIR__.'/csvs/test_that_does_not_exist.csv');
$actual = $seeder->openCSV(__DIR__.'/csvs/csv_that_does_not_exist.csv');
$this->assertEquals($expected, $actual);
}

public function testImport()
{
$seeder = new \Flynsarmy\CsvSeeder\CsvSeeder;
$seeder->table = 'users';
$seeder->filename = __DIR__.'/csvs/test.csv';
$seeder->filename = __DIR__.'/csvs/users.csv';
$seeder->hashable = '';
$seeder->run();

// Make sure the rows imported
$this->seeInDatabase('users', [
'id' => 1,
'first_name' => 'Abe',
'last_name' => 'Abeson',
'email' => '[email protected]',
'age' => 50,
]);
$this->seeInDatabase('users', [
'id' => 3,
'first_name' => 'Charly',
'last_name' => 'Charlyson',
'email' => '[email protected]',
'age' => 52,
]);
}

public function testIgnoredColumnImport()
{
$seeder = new \Flynsarmy\CsvSeeder\CsvSeeder;
$seeder->table = 'users';
$seeder->filename = __DIR__.'/csvs/users_with_ignored_column.csv';
$seeder->hashable = '';
$seeder->run();

Expand All @@ -147,7 +172,7 @@ public function testHash()
{
$seeder = new \Flynsarmy\CsvSeeder\CsvSeeder;
$seeder->table = 'users';
$seeder->filename = __DIR__.'/csvs/test.csv';
$seeder->filename = __DIR__.'/csvs/users.csv';

// Assert unhashed passwords
$seeder->hashable = '';
Expand Down Expand Up @@ -178,7 +203,7 @@ public function testOffset()
{
$seeder = new \Flynsarmy\CsvSeeder\CsvSeeder;
$seeder->table = 'users';
$seeder->filename = __DIR__.'/csvs/test.csv';
$seeder->filename = __DIR__.'/csvs/users.csv';
$seeder->hashable = '';
$seeder->offset_rows = 4;
$seeder->mapping = [
Expand Down
10 changes: 10 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Tests

TO test, open *phpunit.xml* in your laravel installations root directory
and add to the `testsuites` section:

<testsuite name="Application Test Suite">
<directory>./vendor/flynsarmy/csv-seeder/tests/</directory>
</testsuite>

Then run `phpunit`
File renamed without changes.
6 changes: 6 additions & 0 deletions tests/csvs/users_with_ignored_column.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
id,first_name,last_name,email,password,address,age,foo
1,Abe,Abeson,[email protected],abeabeson,123 Abe street,50,abelony
2,Betty,Bettyson,[email protected],bettybettyson,123 Betty street,51,bettlelony
3,Charly,Charlyson,[email protected],charlycharlyson,123 Charly street,52,charlelony
4,Delta,Deltason,[email protected],deltadeltason,123 Delta street,53,deltalony
5,Echo,Echoson,[email protected],echoechoson,123 Echo street,54,echolony

0 comments on commit 9b6b261

Please sign in to comment.