/** * @covers FileParser\Service\Readers\ReaderFactory::getReaderForFile */ public function testGetReaderForFile() { $result = ReaderFactory::getReaderForFile("test.csv"); $this->assertInstanceOf("FileParser\\Service\\Readers\\CsvReader", $result); }
/** * @test */ public function createWithValidExtension() { $reader = ReaderFactory::factory('jpeg'); $this->assertEquals(new JpegReader(), $reader); }
$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); }
/** * @expectedException \Box\Spout\Common\Exception\UnsupportedTypeException * * @return void */ public function testCreateReaderShouldThrowWithUnsupportedType() { ReaderFactory::create('unsupportedType'); }
/** * */ protected function initReader() { $this->_reader = ReaderFactory::createFromFile($this->getType(), $this->source->getPath(), $this->getOptions()); }