From 415d9b95c4fbefabb00d55f28d1481da3b86a17c Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Sun, 29 Jun 2014 14:10:49 +0700 Subject: [PATCH] Update tests --- src/PhpWord/Element/SDT.php | 2 +- src/PhpWord/PhpWord.php | 9 ++- .../Tests/Element/AbstractElementTest.php | 2 - tests/PhpWord/Tests/Element/SDTTest.php | 69 +++++++++++++++++++ tests/PhpWord/Tests/PhpWordTest.php | 12 ++++ tests/PhpWord/Tests/Shared/StringTest.php | 8 +++ 6 files changed, 94 insertions(+), 8 deletions(-) create mode 100644 tests/PhpWord/Tests/Element/SDTTest.php diff --git a/src/PhpWord/Element/SDT.php b/src/PhpWord/Element/SDT.php index 477c50f3..c69ed427 100644 --- a/src/PhpWord/Element/SDT.php +++ b/src/PhpWord/Element/SDT.php @@ -77,7 +77,7 @@ class SDT extends Text public function setType($value) { $enum = array('comboBox', 'dropDownList', 'date'); - $this->type = $this->setEnumVal($value, $enum, $this->type); + $this->type = $this->setEnumVal($value, $enum, 'comboBox'); return $this; } diff --git a/src/PhpWord/PhpWord.php b/src/PhpWord/PhpWord.php index be808f01..7c5cbbfe 100644 --- a/src/PhpWord/PhpWord.php +++ b/src/PhpWord/PhpWord.php @@ -99,14 +99,10 @@ class PhpWord /** * Dynamic function call to reduce static dependency * - * Usage: - * - Getting and adding collections (Titles, Footnotes, and Endnotes) - * - Adding style - * * @param mixed $function * @param mixed $args + * @throws \BadMethodCallException * @return mixed - * * @since 0.12.0 */ public function __call($function, $args) @@ -149,6 +145,9 @@ class PhpWord if (in_array($function, $addStyle)) { return forward_static_call_array(array('PhpOffice\\PhpWord\\Style', $function), $args); } + + // Exception + throw new \BadMethodCallException("Method $function is not defined."); } /** diff --git a/tests/PhpWord/Tests/Element/AbstractElementTest.php b/tests/PhpWord/Tests/Element/AbstractElementTest.php index c92469f3..180dd4d0 100644 --- a/tests/PhpWord/Tests/Element/AbstractElementTest.php +++ b/tests/PhpWord/Tests/Element/AbstractElementTest.php @@ -19,8 +19,6 @@ namespace PhpOffice\PhpWord\Tests\Element; /** * Test class for PhpOffice\PhpWord\Element\AbstractElement - * - * @runTestsInSeparateProcesses */ class AbstractElementTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/PhpWord/Tests/Element/SDTTest.php b/tests/PhpWord/Tests/Element/SDTTest.php new file mode 100644 index 00000000..aa7e89b3 --- /dev/null +++ b/tests/PhpWord/Tests/Element/SDTTest.php @@ -0,0 +1,69 @@ +setValue($value);; + $object->setListItems($types);; + + $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\SDT', $object); + $this->assertEquals($type, $object->getType()); + $this->assertEquals($types, $object->getListItems()); + $this->assertEquals($value, $object->getValue()); + } + + /** + * Test set type exception + * + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Invalid style value + */ + public function testSetTypeException() + { + $object = new SDT('comboBox'); + $object->setType('foo'); + } + + /** + * Test set type + */ + public function testSetTypeNull() + { + $object = new SDT('comboBox'); + $object->setType(' '); + + $this->assertEquals('comboBox', $object->getType()); + } +} diff --git a/tests/PhpWord/Tests/PhpWordTest.php b/tests/PhpWord/Tests/PhpWordTest.php index 75b2d288..756f848f 100644 --- a/tests/PhpWord/Tests/PhpWordTest.php +++ b/tests/PhpWord/Tests/PhpWordTest.php @@ -157,4 +157,16 @@ class PhpWordTest extends \PHPUnit_Framework_TestCase $this->assertTrue($phpWord->save('test.docx', 'Word2007', true)); } + + /** + * Test calling undefined method + * + * @expectedException \BadMethodCallException + * @expectedExceptionMessage is not defined + */ + public function testCallUndefinedMethod() + { + $phpWord = new PhpWord(); + $phpWord->undefinedMethod(); + } } diff --git a/tests/PhpWord/Tests/Shared/StringTest.php b/tests/PhpWord/Tests/Shared/StringTest.php index bf5862fb..a3524ede 100644 --- a/tests/PhpWord/Tests/Shared/StringTest.php +++ b/tests/PhpWord/Tests/Shared/StringTest.php @@ -64,4 +64,12 @@ class StringTest extends \PHPUnit_Framework_TestCase $this->assertEquals('\uc0{\u8364}', String::toUnicode('€')); $this->assertEquals('\uc0{\u233}', String::toUnicode('é')); } + + /** + * Test remove underscore prefix + */ + public function testRemoveUnderscorePrefix() + { + $this->assertEquals('item', String::removeUnderscorePrefix('_item')); + } }