Fixed exceptions in reader/writer
This commit is contained in:
parent
421b6e6f9d
commit
66c73c07c5
|
|
@ -37,13 +37,12 @@ abstract class IOFactory
|
|||
*/
|
||||
public static function createWriter(PhpWord $phpWord, $name)
|
||||
{
|
||||
try {
|
||||
$fqName = "PhpOffice\\PhpWord\\Writer\\{$name}";
|
||||
|
||||
return new $fqName($phpWord);
|
||||
} catch (\Exception $ex) {
|
||||
throw new Exception("Could not instantiate \"{$name}\" class.");
|
||||
if ($name !== 'IWriter' && $name !== 'ODText' && $name !== 'RTF' && $name !== 'Word2007') {
|
||||
throw new Exception("\"{$name}\" is not a valid writer.");
|
||||
}
|
||||
|
||||
$fqName = "PhpOffice\\PhpWord\\Writer\\{$name}";
|
||||
return new $fqName($phpWord);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -53,13 +52,12 @@ abstract class IOFactory
|
|||
*/
|
||||
public static function createReader($name)
|
||||
{
|
||||
try {
|
||||
$fqName = "PhpOffice\\PhpWord\\Reader\\{$name}";
|
||||
|
||||
return new $fqName();
|
||||
} catch (\Exception $ex) {
|
||||
throw new Exception("Could not instantiate \"{$name}\" class.");
|
||||
if ($name !== 'IReader' && $name !== 'Word2007') {
|
||||
throw new Exception("\"{$name}\" is not a valid reader.");
|
||||
}
|
||||
|
||||
$fqName = "PhpOffice\\PhpWord\\Reader\\{$name}";
|
||||
return new $fqName();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ final class IOFactoryTest extends \PHPUnit_Framework_TestCase
|
|||
/**
|
||||
* @covers ::createWriter
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* @expectedExceptionMessage Could not instantiate "Word2006" class.
|
||||
*/
|
||||
final public function testNonexistentWriterCanNotBeCreated()
|
||||
{
|
||||
|
|
@ -45,7 +44,6 @@ final class IOFactoryTest extends \PHPUnit_Framework_TestCase
|
|||
/**
|
||||
* @covers ::createReader
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* @expectedExceptionMessage Could not instantiate "Word2006" class.
|
||||
*/
|
||||
final public function testNonexistentReaderCanNotBeCreated()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue