Skip to content

Commit

Permalink
unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rap2hpoutre committed Apr 5, 2018
1 parent af122af commit 1f51200
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions tests/FastExcelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@
*/
class FastExcelTest extends TestCase
{

/**
* @return \Illuminate\Support\Collection
*/
private function collection()
{
return collect([
['col1' => 'row1 col1', 'col2' => 'row1 col2'],
['col1' => 'row2 col1', 'col2' => ''],
['col1' => 'row3 col1', 'col2' => 'row3 col2'],
]);
}

/**
* @throws \Box\Spout\Common\Exception\IOException
* @throws \Box\Spout\Common\Exception\UnsupportedTypeException
Expand All @@ -18,11 +31,7 @@ class FastExcelTest extends TestCase
public function testImportXlsx()
{
$collection = (new FastExcel)->import(__DIR__ . '/test1.xlsx');
$this->assertEquals(collect([
['col1' => 'row1 col1', 'col2' => 'row1 col2'],
['col1' => 'row2 col1', 'col2' => ''],
['col1' => 'row3 col1', 'col2' => 'row3 col2'],
]), $collection);
$this->assertEquals($this->collection(), $collection);
}

/**
Expand All @@ -32,11 +41,7 @@ public function testImportXlsx()
*/
public function testImportCsv()
{
$original_collection = collect([
['col1' => 'row1 col1', 'col2' => 'row1 col2'],
['col1' => 'row2 col1', 'col2' => ''],
['col1' => 'row3 col1', 'col2' => 'row3 col2'],
]);
$original_collection = $this->collection();

$collection = (new FastExcel)->import(__DIR__ . '/test2.csv');
$this->assertEquals($original_collection, $collection);
Expand All @@ -55,11 +60,7 @@ public function testImportCsv()
*/
public function testExportXlsx()
{
$original_collection = collect([
['col1' => 'row1 col1', 'col2' => 'row1 col2'],
['col1' => 'row2 col1', 'col2' => ''],
['col1' => 'row3 col1', 'col2' => 'row3 col2'],
]);
$original_collection = $this->collection();

(new FastExcel($original_collection))->export(__DIR__ . '/test2.xlsx');
$this->assertEquals($original_collection, (new FastExcel)->import(__DIR__ . '/test2.xlsx'));
Expand All @@ -75,14 +76,10 @@ public function testExportXlsx()
*/
public function testExportCsv()
{
$original_collection = collect([
['col1' => 'row1 col1', 'col2' => 'row1 col2'],
['col1' => 'row2 col1', 'col2' => ''],
['col1' => 'row3 col1', 'col2' => 'row3 col2'],
]);
$original_collection = $this->collection();

(new FastExcel($original_collection))->export(__DIR__ . '/test3.csv');
$this->assertEquals($original_collection, (new FastExcel)->import(__DIR__ . '/test3.csv'));
(new FastExcel($original_collection))->configureCsv(';')->export(__DIR__ . '/test3.csv');
$this->assertEquals($original_collection, (new FastExcel)->configureCsv(';')->import(__DIR__ . '/test3.csv'));
unlink(__DIR__ . '/test3.csv');
}
}

0 comments on commit 1f51200

Please sign in to comment.