-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
57 changes: 57 additions & 0 deletions
57
tests/unit/Mathielen/DataImport/Reader/SpreadsheetReaderTest.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,57 @@ | ||
<?php | ||
namespace Mathielen\DataImport\Reader; | ||
|
||
class SpreadsheetReaderTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function setUp() | ||
{ | ||
//not ready yet | ||
$this->markTestSkipped(); | ||
|
||
if (!extension_loaded('zip')) { | ||
$this->markTestSkipped(); | ||
} | ||
} | ||
|
||
public function testGetFields() | ||
{ | ||
$file = new \SplFileObject(__DIR__.'/../../../../metadata/testfiles/data_column_headers.xlsx'); | ||
$reader = new SpreadsheetReader($file, 0); | ||
$this->assertEquals(array('id', 'number', 'description'), $reader->getFields()); | ||
$this->assertEquals(array('id', 'number', 'description'), $reader->getColumnHeaders()); | ||
} | ||
|
||
public function testCountWithoutHeaders() | ||
{ | ||
$file = new \SplFileObject(__DIR__.'/../../../../metadata/testfiles/data_no_column_headers.xls'); | ||
$reader = new SpreadsheetReader($file); | ||
$this->assertEquals(3, $reader->count()); | ||
} | ||
|
||
public function testCountWithHeaders() | ||
{ | ||
$file = new \SplFileObject(__DIR__.'/../../../../metadata/testfiles/data_column_headers.xlsx'); | ||
$reader = new SpreadsheetReader($file, 0); | ||
$this->assertEquals(3, $reader->count()); | ||
} | ||
|
||
public function testIterate() | ||
{ | ||
$file = new \SplFileObject(__DIR__.'/../../../../metadata/testfiles/data_column_headers.xlsx'); | ||
$reader = new SpreadsheetReader($file, 0); | ||
foreach ($reader as $row) { | ||
$this->assertInternalType('array', $row); | ||
$this->assertEquals(array('id', 'number', 'description'), array_keys($row)); | ||
} | ||
} | ||
|
||
public function testMultiSheet() | ||
{ | ||
$file = new \SplFileObject(__DIR__.'/../../../../metadata/testfiles/data_multi_sheet.xls'); | ||
$sheet1reader = new SpreadsheetReader($file, null, 0); | ||
$this->assertEquals(3, $sheet1reader->count()); | ||
|
||
$sheet2reader = new SpreadsheetReader($file, null, 1); | ||
$this->assertEquals(2, $sheet2reader->count()); | ||
} | ||
} |