Skip to content

Commit

Permalink
spreadsheetreader-test
Browse files Browse the repository at this point in the history
  • Loading branch information
mathielen committed Jun 18, 2015
1 parent e289683 commit 27b019c
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
Binary file added tests/metadata/testfiles/data_column_headers.xlsx
Binary file not shown.
Binary file added tests/metadata/testfiles/data_multi_sheet.xls
Binary file not shown.
Binary file not shown.
57 changes: 57 additions & 0 deletions tests/unit/Mathielen/DataImport/Reader/SpreadsheetReaderTest.php
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());
}
}

0 comments on commit 27b019c

Please sign in to comment.