17
17
18
18
namespace PhpOffice \PhpWordTests ;
19
19
20
+ use PhpOffice \PhpWord \Exception \Exception ;
20
21
use PhpOffice \PhpWord \IOFactory ;
21
22
use 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 ;
22
30
23
31
/**
24
32
* Test class for PhpOffice\PhpWord\IOFactory.
25
33
*
26
34
* @runTestsInSeparateProcesses
27
35
*/
28
- class IOFactoryTest extends \ PHPUnit \ Framework \ TestCase
36
+ class IOFactoryTest extends TestCase
29
37
{
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
+
30
68
/**
31
69
* Create existing writer.
32
70
*/
@@ -43,7 +81,7 @@ public function testExistingWriterCanBeCreated(): void
43
81
*/
44
82
public function testNonexistentWriterCanNotBeCreated (): void
45
83
{
46
- $ this ->expectException (\ PhpOffice \ PhpWord \ Exception \ Exception::class);
84
+ $ this ->expectException (Exception::class);
47
85
IOFactory::createWriter (new PhpWord (), 'Word2006 ' );
48
86
}
49
87
@@ -63,7 +101,7 @@ public function testExistingReaderCanBeCreated(): void
63
101
*/
64
102
public function testNonexistentReaderCanNotBeCreated (): void
65
103
{
66
- $ this ->expectException (\ PhpOffice \ PhpWord \ Exception \ Exception::class);
104
+ $ this ->expectException (Exception::class);
67
105
IOFactory::createReader ('Word2006 ' );
68
106
}
69
107
0 commit comments