Add PhpOffice\PhpWord\Cell\IOFactory::createWriter unit test

This commit is contained in:
Manunchik 2019-10-22 14:10:26 +05:00 committed by Adrien Crivelli
parent 2b7b4ddc5f
commit f80f660457
No known key found for this signature in database
GPG Key ID: 16D79B903B4B5874
1 changed files with 41 additions and 3 deletions

View File

@ -17,16 +17,54 @@
namespace PhpOffice\PhpWordTests; namespace PhpOffice\PhpWordTests;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\IOFactory; use PhpOffice\PhpWord\IOFactory;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Writer\HTML;
use PhpOffice\PhpWord\Writer\ODText;
use PhpOffice\PhpWord\Writer\PDF;
use PhpOffice\PhpWord\Writer\RTF;
use PhpOffice\PhpWord\Writer\Word2007;
use PHPUnit\Framework\TestCase;
/** /**
* Test class for PhpOffice\PhpWord\IOFactory. * Test class for PhpOffice\PhpWord\IOFactory.
* *
* @runTestsInSeparateProcesses * @runTestsInSeparateProcesses
*/ */
class IOFactoryTest extends \PHPUnit\Framework\TestCase class IOFactoryTest extends TestCase
{ {
protected function setUp(): void
{
$rendererName = Settings::PDF_RENDERER_DOMPDF;
$rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/dompdf/dompdf');
Settings::setPdfRenderer($rendererName, $rendererLibraryPath);
}
/**
* Create all possible writers.
*
* @dataProvider providerCreateWriter
*/
public function testCreateWriter(string $name, string $expected): void
{
$phpWord = new PhpWord();
$actual = IOFactory::createWriter($phpWord, $name);
self::assertInstanceOf($expected, $actual);
}
public function providerCreateWriter(): iterable
{
return [
['ODText', ODText::class],
['RTF', RTF::class],
['Word2007', Word2007::class],
['HTML', HTML::class],
['PDF', PDF::class],
];
}
/** /**
* Create existing writer. * Create existing writer.
*/ */
@ -43,7 +81,7 @@ class IOFactoryTest extends \PHPUnit\Framework\TestCase
*/ */
public function testNonexistentWriterCanNotBeCreated(): void public function testNonexistentWriterCanNotBeCreated(): void
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\Exception::class); $this->expectException(Exception::class);
IOFactory::createWriter(new PhpWord(), 'Word2006'); IOFactory::createWriter(new PhpWord(), 'Word2006');
} }
@ -63,7 +101,7 @@ class IOFactoryTest extends \PHPUnit\Framework\TestCase
*/ */
public function testNonexistentReaderCanNotBeCreated(): void public function testNonexistentReaderCanNotBeCreated(): void
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\Exception::class); $this->expectException(Exception::class);
IOFactory::createReader('Word2006'); IOFactory::createReader('Word2006');
} }