Skip to content

Commit 415d9b9

Browse files
committed
Update tests
1 parent 33570f7 commit 415d9b9

File tree

6 files changed

+94
-8
lines changed

6 files changed

+94
-8
lines changed

src/PhpWord/Element/SDT.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function getType()
7777
public function setType($value)
7878
{
7979
$enum = array('comboBox', 'dropDownList', 'date');
80-
$this->type = $this->setEnumVal($value, $enum, $this->type);
80+
$this->type = $this->setEnumVal($value, $enum, 'comboBox');
8181

8282
return $this;
8383
}

src/PhpWord/PhpWord.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,10 @@ public function __construct()
9999
/**
100100
* Dynamic function call to reduce static dependency
101101
*
102-
* Usage:
103-
* - Getting and adding collections (Titles, Footnotes, and Endnotes)
104-
* - Adding style
105-
*
106102
* @param mixed $function
107103
* @param mixed $args
104+
* @throws \BadMethodCallException
108105
* @return mixed
109-
*
110106
* @since 0.12.0
111107
*/
112108
public function __call($function, $args)
@@ -149,6 +145,9 @@ public function __call($function, $args)
149145
if (in_array($function, $addStyle)) {
150146
return forward_static_call_array(array('PhpOffice\\PhpWord\\Style', $function), $args);
151147
}
148+
149+
// Exception
150+
throw new \BadMethodCallException("Method $function is not defined.");
152151
}
153152

154153
/**

tests/PhpWord/Tests/Element/AbstractElementTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
/**
2121
* Test class for PhpOffice\PhpWord\Element\AbstractElement
22-
*
23-
* @runTestsInSeparateProcesses
2422
*/
2523
class AbstractElementTest extends \PHPUnit_Framework_TestCase
2624
{
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* This file is part of PHPWord - A pure PHP library for reading and writing
4+
* word processing documents.
5+
*
6+
* PHPWord is free software distributed under the terms of the GNU Lesser
7+
* General Public License version 3 as published by the Free Software Foundation.
8+
*
9+
* For the full copyright and license information, please read the LICENSE
10+
* file that was distributed with this source code. For the full list of
11+
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
12+
*
13+
* @link https://github.com/PHPOffice/PHPWord
14+
* @copyright 2010-2014 PHPWord contributors
15+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16+
*/
17+
18+
namespace PhpOffice\PhpWord\Tests\Element;
19+
20+
use PhpOffice\PhpWord\Element\SDT;
21+
22+
/**
23+
* Test class for PhpOffice\PhpWord\Element\SDT
24+
*
25+
* @coversDefaultClass \PhpOffice\PhpWord\Element\SDT
26+
*/
27+
class SDTTest extends \PHPUnit_Framework_TestCase
28+
{
29+
/**
30+
* Create new instance
31+
*/
32+
public function testConstruct()
33+
{
34+
$types = array('comboBox', 'dropDownList', 'date');
35+
$type = $types[rand(0, 2)];
36+
$value = rand(0, 100);
37+
$object = new SDT($type);
38+
$object->setValue($value);;
39+
$object->setListItems($types);;
40+
41+
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\SDT', $object);
42+
$this->assertEquals($type, $object->getType());
43+
$this->assertEquals($types, $object->getListItems());
44+
$this->assertEquals($value, $object->getValue());
45+
}
46+
47+
/**
48+
* Test set type exception
49+
*
50+
* @expectedException \InvalidArgumentException
51+
* @expectedExceptionMessage Invalid style value
52+
*/
53+
public function testSetTypeException()
54+
{
55+
$object = new SDT('comboBox');
56+
$object->setType('foo');
57+
}
58+
59+
/**
60+
* Test set type
61+
*/
62+
public function testSetTypeNull()
63+
{
64+
$object = new SDT('comboBox');
65+
$object->setType(' ');
66+
67+
$this->assertEquals('comboBox', $object->getType());
68+
}
69+
}

tests/PhpWord/Tests/PhpWordTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,16 @@ public function testSave()
157157

158158
$this->assertTrue($phpWord->save('test.docx', 'Word2007', true));
159159
}
160+
161+
/**
162+
* Test calling undefined method
163+
*
164+
* @expectedException \BadMethodCallException
165+
* @expectedExceptionMessage is not defined
166+
*/
167+
public function testCallUndefinedMethod()
168+
{
169+
$phpWord = new PhpWord();
170+
$phpWord->undefinedMethod();
171+
}
160172
}

tests/PhpWord/Tests/Shared/StringTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,12 @@ public function testToUnicode()
6464
$this->assertEquals('\uc0{\u8364}', String::toUnicode(''));
6565
$this->assertEquals('\uc0{\u233}', String::toUnicode('é'));
6666
}
67+
68+
/**
69+
* Test remove underscore prefix
70+
*/
71+
public function testRemoveUnderscorePrefix()
72+
{
73+
$this->assertEquals('item', String::removeUnderscorePrefix('_item'));
74+
}
6775
}

0 commit comments

Comments
 (0)