Skip to content

Commit f80f660

Browse files
ManunchikPowerKiKi
authored andcommitted
Add PhpOffice\PhpWord\Cell\IOFactory::createWriter unit test
1 parent 2b7b4dd commit f80f660

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

tests/PhpWordTests/IOFactoryTest.php

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,54 @@
1717

1818
namespace PhpOffice\PhpWordTests;
1919

20+
use PhpOffice\PhpWord\Exception\Exception;
2021
use PhpOffice\PhpWord\IOFactory;
2122
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;
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

Comments
 (0)