expectException(ReaderException::class); $this->expectExceptionMessage('Unable to identify a reader for this file'); IOFactory::identify($file); } public function testCreateInvalid(): void { $file = __DIR__ . '/../data/Reader/NotASpreadsheetFile.doc'; $this->expectException(ReaderException::class); $this->expectExceptionMessage('Unable to identify a reader for this file'); IOFactory::createReaderForFile($file); } public function testLoadInvalid(): void { $file = __DIR__ . '/../data/Reader/NotASpreadsheetFile.doc'; $this->expectException(ReaderException::class); $this->expectExceptionMessage('Unable to identify a reader for this file'); IOFactory::load($file); } public function testFormatAsExpected(): void { $fileName = 'samples/templates/30template.xls'; $actual = IOFactory::identify($fileName, [IOFactory::READER_XLS]); self::assertSame('Xls', $actual); } public function testFormatNotAsExpectedThrowsException(): void { $fileName = 'samples/templates/30template.xls'; $this->expectException(ReaderException::class); IOFactory::identify($fileName, [IOFactory::READER_ODS]); } public function testIdentifyNonExistingFileThrowException(): void { $this->expectException(ReaderException::class); IOFactory::identify('/non/existing/file'); } public function testIdentifyExistingDirectoryThrowExceptions(): void { $this->expectException(ReaderException::class); IOFactory::identify('.'); } public function testRegisterInvalidWriter(): void { $this->expectException(\PhpOffice\PhpSpreadsheet\Writer\Exception::class); IOFactory::registerWriter('foo', 'bar'); } public function testRegisterInvalidReader(): void { $this->expectException(\PhpOffice\PhpSpreadsheet\Reader\Exception::class); IOFactory::registerReader('foo', 'bar'); } public function testCreateInvalidWriter(): void { $this->expectException(\PhpOffice\PhpSpreadsheet\Writer\Exception::class); $spreadsheet = new Spreadsheet(); IOFactory::createWriter($spreadsheet, 'bad'); } public function testCreateInvalidReader(): void { $this->expectException(\PhpOffice\PhpSpreadsheet\Reader\Exception::class); IOFactory::createReader('bad'); } public function testCreateReaderUnknownExtension(): void { $filename = 'samples/Reader/sampleData/example1.tsv'; $reader = IOFactory::createReaderForFile($filename); self::assertEquals('PhpOffice\\PhpSpreadsheet\\Reader\\Csv', get_class($reader)); } public function testCreateReaderCsvExtension(): void { $filename = 'samples/Reader/sampleData/example1.csv'; $reader = IOFactory::createReaderForFile($filename); self::assertEquals('PhpOffice\\PhpSpreadsheet\\Reader\\Csv', get_class($reader)); } public function testCreateReaderNoExtension(): void { $filename = 'samples/Reader/sampleData/example1xls'; $reader = IOFactory::createReaderForFile($filename); self::assertEquals('PhpOffice\\PhpSpreadsheet\\Reader\\Xls', get_class($reader)); } public function testCreateReaderNotSpreadsheet(): void { $this->expectException(\PhpOffice\PhpSpreadsheet\Reader\Exception::class); $filename = __FILE__; IOFactory::createReaderForFile($filename); } }