Skip to content

Commit a218202

Browse files
committed
Enhance unit tests
1 parent 8d2c6eb commit a218202

File tree

9 files changed

+65
-7
lines changed

9 files changed

+65
-7
lines changed

src/PhpWord/Container/Section.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ public function addPageBreak()
9797
*
9898
* @param mixed $styleFont
9999
* @param mixed $styleTOC
100+
* @param integer $minDepth
101+
* @param integer $maxDepth
100102
* @return TOC
101103
*/
102104
public function addTOC($styleFont = null, $styleTOC = null, $minDepth = 1, $maxDepth = 9)

src/PhpWord/Element/Image.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,13 @@ public function __construct($source, $style = null, $isWatermark = false)
102102
// Check supported types
103103
if ($this->isMemImage) {
104104
$supportedTypes = array('image/jpeg', 'image/gif', 'image/png');
105-
$imgData = getimagesize($source);
105+
$imgData = @getimagesize($source);
106+
if (!is_array($imgData)) {
107+
throw new InvalidImageException();
108+
}
106109
$this->imageType = $imgData['mime']; // string
107110
if (!in_array($this->imageType, $supportedTypes)) {
108-
throw new UnsupportedImageTypeException;
111+
throw new UnsupportedImageTypeException();
109112
}
110113
} else {
111114
$supportedTypes = array(
@@ -114,17 +117,19 @@ public function __construct($source, $style = null, $isWatermark = false)
114117
\IMAGETYPE_TIFF_II, \IMAGETYPE_TIFF_MM
115118
);
116119
if (!file_exists($source)) {
117-
throw new InvalidImageException;
120+
throw new InvalidImageException();
118121
}
119122
$imgData = getimagesize($source);
120123
if (function_exists('exif_imagetype')) {
121124
$this->imageType = exif_imagetype($source);
122125
} else {
126+
// @codeCoverageIgnoreStart
123127
$tmp = getimagesize($source);
124128
$this->imageType = $tmp[2];
129+
// @codeCoverageIgnoreEnd
125130
}
126131
if (!in_array($this->imageType, $supportedTypes)) {
127-
throw new UnsupportedImageTypeException;
132+
throw new UnsupportedImageTypeException();
128133
}
129134
$this->imageType = \image_type_to_mime_type($this->imageType);
130135
}

src/PhpWord/TOC.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class TOC
7373
*
7474
* @param mixed $styleFont
7575
* @param array $styleTOC
76+
* @param integer $minDepth
77+
* @param integer $maxDepth
7678
*/
7779
public function __construct($styleFont = null, $styleTOC = null, $minDepth = 1, $maxDepth = 9)
7880
{

src/PhpWord/Writer/Word2007.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ private function addHeaderFooterMedia($objZip, $docPart)
229229
/**
230230
* Add header/footer content
231231
*
232-
* @param PhpOffice\PhpWord\Container\Section $section
232+
* @param \PhpOffice\PhpWord\Container\Section $section
233+
* @param mixed $objZip
233234
* @param string $elmType
234235
* @param integer $rID
235236
*/

src/PhpWord/Writer/Word2007/ContentTypes.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ public function writeContentTypes($contentTypes)
6060
* Write content types element
6161
*
6262
* @param XMLWriter $xmlWriter XML Writer
63+
* @param array $parts
6364
* @param boolean $isDefault
64-
* @param string $partName Part name
65-
* @param string $contentType Content type
6665
* @throws Exception
6766
*/
6867
private function writeContentType(XMLWriter $xmlWriter, $parts, $isDefault)

tests/PhpWord/Tests/Container/FooterTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ public function testRelationID()
162162

163163
$iVal = rand(1, 1000);
164164
$oFooter->setRelationId($iVal);
165+
165166
$this->assertEquals($oFooter->getRelationId(), $iVal);
167+
$this->assertEquals(Footer::AUTO, $oFooter->getType());
166168
}
167169
}

tests/PhpWord/Tests/Container/HeaderTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,16 @@ public function testAddFootnoteException()
231231
$header = new Header(1);
232232
$header->addFootnote();
233233
}
234+
235+
/**
236+
* Set/get type
237+
*/
238+
public function testSetGetType()
239+
{
240+
$object = new Header(1);
241+
$this->assertEquals(Header::AUTO, $object->getType());
242+
243+
$object->setType('ODD');
244+
$this->assertEquals(Header::AUTO, $object->getType());
245+
}
234246
}

tests/PhpWord/Tests/Container/SectionTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
namespace PhpOffice\PhpWord\Tests\Container;
1111

12+
use PhpOffice\PhpWord\Exception\Exception;
1213
use PhpOffice\PhpWord\Container\Section;
14+
use PhpOffice\PhpWord\Container\Header;
1315
use PhpOffice\PhpWord\Style;
1416

1517
/**
@@ -141,4 +143,27 @@ public function testCreateHeaderFooter()
141143
}
142144
$this->assertFalse($object->hasDifferentFirstPage());
143145
}
146+
147+
/**
148+
* Add header has different first page
149+
*/
150+
public function testHasDifferentFirstPage()
151+
{
152+
$object = new Section(1);
153+
$header = $object->addHeader();
154+
$header->setType(Header::FIRST);
155+
$this->assertTrue($object->hasDifferentFirstPage());
156+
}
157+
158+
/**
159+
* Add header exception
160+
*
161+
* @expectedException Exception
162+
* @expectedExceptionMesssage Invalid header/footer type.
163+
*/
164+
public function testAddHeaderException()
165+
{
166+
$object = new Section(1);
167+
$header = $object->addHeader('ODD');
168+
}
144169
}

tests/PhpWord/Tests/Element/ImageTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,14 @@ public function testTIFF()
192192
$this->assertEquals($oImage->getImageFunction(), null);
193193
$this->assertEquals($oImage->getImageType(), 'image/tiff');
194194
}
195+
196+
/**
197+
* Test PHP Image
198+
*
199+
* @expectedException \PhpOffice\PhpWord\Exception\InvalidImageException
200+
*/
201+
public function testPhpImage()
202+
{
203+
$object = new Image('test.php');
204+
}
195205
}

0 commit comments

Comments
 (0)