create a reader by file type #569

This commit is contained in:
madflow authored and Adrien Loison committed 2018-10-23 13:33:39 +02:00
1 parent 8f7f106555
commit e99c80b3ad
10 files changed
+202

No files matched your search

@@ -0,0 +1,73 @@
<?php
namespace Box\Spout\Reader\Common\Creator;
use Box\Spout\Common\Exception\IOException;
use Box\Spout\Common\Exception\UnsupportedTypeException;
use Box\Spout\TestUsingResource;
use PHPUnit\Framework\TestCase;
class ReaderEntityFactoryTest extends TestCase
{
use TestUsingResource;
/**
* @return void
*/
public function testCreateFromFileCSV()
{
$validCsv = $this->getResourcePath('csv_test_create_from_file.csv');
$reader = ReaderEntityFactory::createReaderFromFile($validCsv);
$this->assertInstanceOf('Box\Spout\Reader\CSV\Reader', $reader);
}
/**
* @return void
*/
public function testCreateFromFileCSVAllCaps()
{
$validCsv = $this->getResourcePath('csv_test_create_from_file.CSV');
$reader = ReaderEntityFactory::createReaderFromFile($validCsv);
$this->assertInstanceOf('Box\Spout\Reader\CSV\Reader', $reader);
}
/**
* @return void
*/
public function testCreateFromFileODS()
{
$validOds = $this->getResourcePath('csv_test_create_from_file.ods');
$reader = ReaderEntityFactory::createReaderFromFile($validOds);
$this->assertInstanceOf('Box\Spout\Reader\ODS\Reader', $reader);
}
/**
* @return void
*/
public function testCreateFromFileXLSX()
{
$validXlsx = $this->getResourcePath('csv_test_create_from_file.xlsx');
$reader = ReaderEntityFactory::createReaderFromFile($validXlsx);
$this->assertInstanceOf('Box\Spout\Reader\XLSX\Reader', $reader);
}
/**
* @return void
*/
public function testCreateFromFileUnsupported()
{
$this->expectException(UnsupportedTypeException::class);
$invalid = $this->getResourcePath('test_unsupported_file_type.other');
$reader = ReaderEntityFactory::createReaderFromFile($invalid);
}
/**
* @return void
*/
public function testCreateFromFileMissing()
{
$this->expectException(IOException::class);
$invalid = 'thereisnosuchfile.ext';
$reader = ReaderEntityFactory::createReaderFromFile($invalid);
}
}
@@ -2,7 +2,9 @@
namespace Box\Spout\Reader\Common\Creator;
use Box\Spout\Common\Exception\IOException;
use Box\Spout\Common\Exception\UnsupportedTypeException;
use Box\Spout\TestUsingResource;
use PHPUnit\Framework\TestCase;
/**
@@ -10,6 +12,48 @@ use PHPUnit\Framework\TestCase;
*/
class ReaderFactoryTest extends TestCase
{
use TestUsingResource;
/**
* @return void
*/
public function testCreateFromFileCSV()
{
$validCsv = $this->getResourcePath('csv_test_create_from_file.csv');
$reader = ReaderFactory::createFromFile($validCsv);
$this->assertInstanceOf('Box\Spout\Reader\CSV\Reader', $reader);
}
/**
* @return void
*/
public function testCreateFromFileCSVAllCaps()
{
$validCsv = $this->getResourcePath('csv_test_create_from_file.CSV');
$reader = ReaderFactory::createFromFile($validCsv);
$this->assertInstanceOf('Box\Spout\Reader\CSV\Reader', $reader);
}
/**
* @return void
*/
public function testCreateFromFileODS()
{
$validOds = $this->getResourcePath('csv_test_create_from_file.ods');
$reader = ReaderFactory::createFromFile($validOds);
$this->assertInstanceOf('Box\Spout\Reader\ODS\Reader', $reader);
}
/**
* @return void
*/
public function testCreateFromFileXLSX()
{
$validXlsx = $this->getResourcePath('csv_test_create_from_file.xlsx');
$reader = ReaderFactory::createFromFile($validXlsx);
$this->assertInstanceOf('Box\Spout\Reader\XLSX\Reader', $reader);
}
/**
* @return void
*/
@@ -19,4 +63,24 @@ class ReaderFactoryTest extends TestCase
ReaderFactory::create('unsupportedType');
}
/**
* @return void
*/
public function testCreateFromFileUnsupported()
{
$this->expectException(UnsupportedTypeException::class);
$invalid = $this->getResourcePath('test_unsupported_file_type.other');
$reader = ReaderFactory::createFromFile($invalid);
}
/**
* @return void
*/
public function testCreateFromFileMissing()
{
$this->expectException(IOException::class);
$invalid = 'thereisnosuchfile.ext';
$reader = ReaderFactory::createFromFile($invalid);
}
}
@@ -0,0 +1 @@
test
1 test
@@ -0,0 +1 @@
test
1 test
Binary file not shown.
Whitespace-only changes.
Binary file not shown.