Exemplo n.º 1
0
 /**
  * @covers FileParser\Service\Readers\ReaderFactory::getReaderForFile
  */
 public function testGetReaderForFile()
 {
     $result = ReaderFactory::getReaderForFile("test.csv");
     $this->assertInstanceOf("FileParser\\Service\\Readers\\CsvReader", $result);
 }
Exemplo n.º 2
0
 /**
  * @test
  */
 public function createWithValidExtension()
 {
     $reader = ReaderFactory::factory('jpeg');
     $this->assertEquals(new JpegReader(), $reader);
 }
Exemplo n.º 3
0
        $reader = $this->createReader($fileName);
        return $reader;
    }
    public function createReader($fileName)
    {
        //stripos()は文字列を検索し、対象の文字列の位置を返す
        $poscsv = stripos($fileName, 'csv');
        $posxml = stripos($fileName, 'xml');
        if ($poscsv !== false) {
            return new CSVFileReader($fileName);
        } else {
            if ($posxml !== false) {
                return new XMLFileReader($fileName);
            } else {
                die('This file type is not supported:' . $fileName);
            }
        }
    }
}
/*
 * Client
 */
//ファイル名
$fileName = 'music.xml';
//$fileName = 'music.csv';
//Factoryクラスを使ってReaderを生成
$factory = new ReaderFactory();
$reader = $factory->create($fileName);
//Readerでファイル読み込み
$reader->read();
$reader->display();
 /**
  * @expectedException \Exception
  * @expectedExceptionMessage Reader não identificado
  */
 public function testExpectException()
 {
     $instance = ReaderFactory::create(null);
 }
Exemplo n.º 5
0
 /**
  * @expectedException \Box\Spout\Common\Exception\UnsupportedTypeException
  *
  * @return void
  */
 public function testCreateReaderShouldThrowWithUnsupportedType()
 {
     ReaderFactory::create('unsupportedType');
 }
Exemplo n.º 6
0
 /**
  * 
  */
 protected function initReader()
 {
     $this->_reader = ReaderFactory::createFromFile($this->getType(), $this->source->getPath(), $this->getOptions());
 }