/** * @expectedException \Exception * @expectedExceptionMessage Reader não identificado */ public function testExpectException() { $instance = ReaderFactory::create(null); }
$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 \Box\Spout\Common\Exception\UnsupportedTypeException * * @return void */ public function testCreateReaderShouldThrowWithUnsupportedType() { ReaderFactory::create('unsupportedType'); }