1717
1818namespace PhpOffice \PhpWordTests ;
1919
20+ use PhpOffice \PhpWord \Exception \Exception ;
2021use PhpOffice \PhpWord \IOFactory ;
2122use PhpOffice \PhpWord \PhpWord ;
23+ use PhpOffice \PhpWord \Settings ;
24+ use PhpOffice \PhpWord \Writer \HTML ;
25+ use PhpOffice \PhpWord \Writer \ODText ;
26+ use PhpOffice \PhpWord \Writer \PDF ;
27+ use PhpOffice \PhpWord \Writer \RTF ;
28+ use PhpOffice \PhpWord \Writer \Word2007 ;
29+ use PHPUnit \Framework \TestCase ;
2230
2331/**
2432 * Test class for PhpOffice\PhpWord\IOFactory.
2533 *
2634 * @runTestsInSeparateProcesses
2735 */
28- class IOFactoryTest extends \ PHPUnit \ Framework \ TestCase
36+ class IOFactoryTest extends TestCase
2937{
38+ protected function setUp (): void
39+ {
40+ $ rendererName = Settings::PDF_RENDERER_DOMPDF ;
41+ $ rendererLibraryPath = realpath (PHPWORD_TESTS_BASE_DIR . '/../vendor/dompdf/dompdf ' );
42+ Settings::setPdfRenderer ($ rendererName , $ rendererLibraryPath );
43+ }
44+
45+ /**
46+ * Create all possible writers.
47+ *
48+ * @dataProvider providerCreateWriter
49+ */
50+ public function testCreateWriter (string $ name , string $ expected ): void
51+ {
52+ $ phpWord = new PhpWord ();
53+ $ actual = IOFactory::createWriter ($ phpWord , $ name );
54+ self ::assertInstanceOf ($ expected , $ actual );
55+ }
56+
57+ public function providerCreateWriter (): iterable
58+ {
59+ return [
60+ ['ODText ' , ODText::class],
61+ ['RTF ' , RTF ::class],
62+ ['Word2007 ' , Word2007::class],
63+ ['HTML ' , HTML ::class],
64+ ['PDF ' , PDF ::class],
65+ ];
66+ }
67+
3068 /**
3169 * Create existing writer.
3270 */
@@ -43,7 +81,7 @@ public function testExistingWriterCanBeCreated(): void
4381 */
4482 public function testNonexistentWriterCanNotBeCreated (): void
4583 {
46- $ this ->expectException (\ PhpOffice \ PhpWord \ Exception \ Exception::class);
84+ $ this ->expectException (Exception::class);
4785 IOFactory::createWriter (new PhpWord (), 'Word2006 ' );
4886 }
4987
@@ -63,7 +101,7 @@ public function testExistingReaderCanBeCreated(): void
63101 */
64102 public function testNonexistentReaderCanNotBeCreated (): void
65103 {
66- $ this ->expectException (\ PhpOffice \ PhpWord \ Exception \ Exception::class);
104+ $ this ->expectException (Exception::class);
67105 IOFactory::createReader ('Word2006 ' );
68106 }
69107
0 commit comments