Update all PHP dependencies

This way we can share the same dependencies across PHP 7.4 to PHP 8.1,
and simplify our CI pipeline
This commit is contained in:
Adrien Crivelli 2022-09-16 11:27:29 +02:00
parent 207438270f
commit 25c56a3e2d
No known key found for this signature in database
GPG Key ID: 16D79B903B4B5874
83 changed files with 215 additions and 288 deletions

View File

@ -36,30 +36,8 @@ jobs:
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer- restore-keys: ${{ runner.os }}-composer-
- name: Update PHPUnit version for PHP 8
id: composer-lock
if: "startsWith(matrix.php-version, '8.')"
run: |
rm -f composer.lock
echo "::set-output name=flags::--ignore-platform-reqs"
composer remove phpunit/phpunit --dev --no-update --no-interaction
composer require phpunit/phpunit ^8.0 --dev --no-update
- name: Install dependencies - name: Install dependencies
run: composer update --no-progress --prefer-dist --optimize-autoloader ${{ steps.composer-lock.outputs.flags }} run: composer install --no-progress --prefer-dist --optimize-autoloader
- name: Update code to make PHPUnit 8 compatible
if: "startsWith(matrix.php-version, '8.')"
run: |
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/function setUpBeforeClass()$/function setUpBeforeClass(): void/' {} \;
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/function tearDownAfterClass()$/function tearDownAfterClass(): void/' {} \;
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/function setUp()$/function setUp(): void/' {} \;
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/function tearDown()$/function tearDown(): void/' {} \;
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/->assertContains(/->assertStringContainsString(/' {} \;
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/->assertNotContains(/->assertStringNotContainsString(/' {} \;
find ./tests/ -name "*.php" -type f -exec sed -i -e "s/->assertInternalType('array', /->assertIsArray(/" {} \;
sed -i "s/\$this->addWarning('The @expectedException,/\/\/\$this->addWarning('The @expectedException,/" ./vendor/phpunit/phpunit/src/Framework/TestCase.php
sed -i "s/self::createWarning('The optional \$delta/\/\/self::createWarning('The optional \$delta/" ./vendor/phpunit/phpunit/src/Framework/Assert.php
- name: Setup problem matchers for PHP - name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"

View File

@ -59,22 +59,24 @@
}, },
"require": { "require": {
"php": "^7.4 || ^8.0", "php": "^7.4 || ^8.0",
"ext-dom": "*",
"ext-json": "*",
"ext-xml": "*", "ext-xml": "*",
"laminas/laminas-escaper": "^2.2", "laminas/laminas-escaper": "^2.10",
"symfony/process": "^5.4" "symfony/process": "^5.4"
}, },
"require-dev": { "require-dev": {
"ext-zip": "*", "ext-zip": "*",
"ext-gd": "*", "ext-gd": "*",
"phpunit/phpunit": "^4.8.36 || ^7.0", "dompdf/dompdf": "^2.0",
"squizlabs/php_codesniffer": "^2.9 || ^3.5", "friendsofphp/php-cs-fixer": "^3.11",
"friendsofphp/php-cs-fixer": "^2.2", "mpdf/mpdf": "^8.1",
"phpmd/phpmd": "2.*", "php-coveralls/php-coveralls": "^2.5",
"phploc/phploc": "2.* || 3.* || 4.* || 5.* || 6.* || 7.*", "phploc/phploc": "^7.0",
"dompdf/dompdf":"0.8.* || 1.0.*", "phpmd/phpmd": "^2.13",
"tecnickcom/tcpdf": "^6.4", "phpunit/phpunit": "^9.5",
"mpdf/mpdf": "5.7.4 || 6.* || 7.* || 8.*", "squizlabs/php_codesniffer": "^3.7",
"php-coveralls/php-coveralls": "1.1.0 || ^2.0" "tecnickcom/tcpdf": "^6.5"
}, },
"suggest": { "suggest": {
"ext-zip": "Allows writing OOXML and ODF", "ext-zip": "Allows writing OOXML and ODF",

View File

@ -60,7 +60,7 @@ class PreserveText extends AbstractElement
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle); $this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
$this->text = SharedText::toUTF8($text); $this->text = SharedText::toUTF8($text);
$matches = preg_split('/({.*?})/', $this->text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); $matches = preg_split('/({.*?})/', $this->text ?? '', -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
if (isset($matches[0])) { if (isset($matches[0])) {
$this->text = $matches; $this->text = $matches;
} }

View File

@ -1499,9 +1499,9 @@ class MsDoc extends AbstractReader implements ReaderInterface
{ {
$oSprm = new \stdClass(); $oSprm = new \stdClass();
$oSprm->isPmd = $sprm & 0x01FF; $oSprm->isPmd = $sprm & 0x01FF;
$oSprm->f = ($sprm / 512) & 0x0001; $oSprm->f = (int)($sprm / 512) & 0x0001;
$oSprm->sgc = ($sprm / 1024) & 0x0007; $oSprm->sgc = (int)($sprm / 1024) & 0x0007;
$oSprm->spra = ($sprm / 8192); $oSprm->spra = (int)($sprm / 8192);
return $oSprm; return $oSprm;
} }

View File

@ -255,7 +255,7 @@ class Settings
*/ */
public static function setPdfRendererPath($libraryBaseDir) public static function setPdfRendererPath($libraryBaseDir)
{ {
if (false === file_exists($libraryBaseDir) || false === is_readable($libraryBaseDir)) { if (!$libraryBaseDir || false === file_exists($libraryBaseDir) || false === is_readable($libraryBaseDir)) {
return false; return false;
} }
self::$pdfRendererPath = $libraryBaseDir; self::$pdfRendererPath = $libraryBaseDir;

View File

@ -620,7 +620,7 @@ class Html
foreach ($properties as $property) { foreach ($properties as $property) {
list($cKey, $cValue) = array_pad(explode(':', $property, 2), 2, null); list($cKey, $cValue) = array_pad(explode(':', $property, 2), 2, null);
$cValue = trim($cValue); $cValue = trim($cValue ?? '');
$cKey = strtolower(trim($cKey)); $cKey = strtolower(trim($cKey));
switch ($cKey) { switch ($cKey) {
case 'text-decoration': case 'text-decoration':

View File

@ -59,7 +59,7 @@ class XMLWriter extends \XMLWriter
if ($pTemporaryStorage == self::STORAGE_MEMORY) { if ($pTemporaryStorage == self::STORAGE_MEMORY) {
$this->openMemory(); $this->openMemory();
} else { } else {
if (!is_dir($pTemporaryStorageDir)) { if (!$pTemporaryStorageDir || !is_dir($pTemporaryStorageDir)) {
$pTemporaryStorageDir = sys_get_temp_dir(); $pTemporaryStorageDir = sys_get_temp_dir();
} }
// Create temporary filename // Create temporary filename
@ -178,6 +178,6 @@ class XMLWriter extends \XMLWriter
$value = json_encode($value); $value = json_encode($value);
} }
return parent::writeAttribute($name, $value); return parent::writeAttribute($name, $value ?? '');
} }
} }

View File

@ -29,7 +29,7 @@ class Title extends Text
/** @var \PhpOffice\PhpWord\Element\Title $element Type hint */ /** @var \PhpOffice\PhpWord\Element\Title $element Type hint */
$element = $this->element; $element = $this->element;
$style = $element->getStyle(); $style = $element->getStyle();
$style = str_replace('Heading', 'Heading_', $style); $style = str_replace('Heading', 'Heading_', $style ?? '');
$style = \PhpOffice\PhpWord\Style::getStyle($style); $style = \PhpOffice\PhpWord\Style::getStyle($style);
if ($style instanceof \PhpOffice\PhpWord\Style\Font) { if ($style instanceof \PhpOffice\PhpWord\Style\Font) {
$this->fontStyle = $style; $this->fontStyle = $style;

View File

@ -65,8 +65,8 @@ class Paragraph extends AbstractStyle
$content .= $alignments[$style->getAlignment()]; $content .= $alignments[$style->getAlignment()];
} }
$content .= $this->writeIndentation($style->getIndentation()); $content .= $this->writeIndentation($style->getIndentation());
$content .= $this->getValueIf($spaceBefore !== null, '\sb' . round($spaceBefore)); $content .= $this->getValueIf($spaceBefore !== null, '\sb' . round($spaceBefore??0));
$content .= $this->getValueIf($spaceAfter !== null, '\sa' . round($spaceAfter)); $content .= $this->getValueIf($spaceAfter !== null, '\sa' . round($spaceAfter??0));
$lineHeight = $style->getLineHeight(); $lineHeight = $style->getLineHeight();
if ($lineHeight) { if ($lineHeight) {
$lineHeightAdjusted = (int) ($lineHeight * 240); $lineHeightAdjusted = (int) ($lineHeight * 240);

View File

@ -46,33 +46,30 @@ class FootnotePropertiesTest extends \PHPUnit\Framework\TestCase
/** /**
* Test throws exception if wrong position given * Test throws exception if wrong position given
*
* @expectedException \InvalidArgumentException
*/ */
public function testWrongPos() public function testWrongPos()
{ {
$this->expectException(\InvalidArgumentException::class);
$footnoteProp = new FootnoteProperties(); $footnoteProp = new FootnoteProperties();
$footnoteProp->setPos(NumberFormat::LOWER_ROMAN); $footnoteProp->setPos(NumberFormat::LOWER_ROMAN);
} }
/** /**
* Test throws exception if wrong number format given * Test throws exception if wrong number format given
*
* @expectedException \InvalidArgumentException
*/ */
public function testWrongNumFmt() public function testWrongNumFmt()
{ {
$this->expectException(\InvalidArgumentException::class);
$footnoteProp = new FootnoteProperties(); $footnoteProp = new FootnoteProperties();
$footnoteProp->setNumFmt(FootnoteProperties::POSITION_DOC_END); $footnoteProp->setNumFmt(FootnoteProperties::POSITION_DOC_END);
} }
/** /**
* Test throws exception if wrong number restart given * Test throws exception if wrong number restart given
*
* @expectedException \InvalidArgumentException
*/ */
public function testWrongNumRestart() public function testWrongNumRestart()
{ {
$this->expectException(\InvalidArgumentException::class);
$footnoteProp = new FootnoteProperties(); $footnoteProp = new FootnoteProperties();
$footnoteProp->setNumRestart(NumberFormat::LOWER_ROMAN); $footnoteProp->setNumRestart(NumberFormat::LOWER_ROMAN);
} }

View File

@ -39,22 +39,20 @@ class ProofStateTest extends \PHPUnit\Framework\TestCase
/** /**
* Test throws exception if wrong grammar proof state value given * Test throws exception if wrong grammar proof state value given
*
* @expectedException \InvalidArgumentException
*/ */
public function testWrongGrammar() public function testWrongGrammar()
{ {
$this->expectException(\InvalidArgumentException::class);
$pState = new ProofState(); $pState = new ProofState();
$pState->setGrammar('Wrong'); $pState->setGrammar('Wrong');
} }
/** /**
* Test throws exception if wrong spelling proof state value given * Test throws exception if wrong spelling proof state value given
*
* @expectedException \InvalidArgumentException
*/ */
public function testWrongSpelling() public function testWrongSpelling()
{ {
$this->expectException(\InvalidArgumentException::class);
$pState = new ProofState(); $pState = new ProofState();
$pState->setSpelling('Wrong'); $pState->setSpelling('Wrong');
} }

View File

@ -188,11 +188,10 @@ class CellTest extends AbstractWebServerEmbeddedTest
/** /**
* Test add object exception * Test add object exception
*
* @expectedException \PhpOffice\PhpWord\Exception\InvalidObjectException
*/ */
public function testAddObjectException() public function testAddObjectException()
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\InvalidObjectException::class);
$src = __DIR__ . '/../_files/xsl/passthrough.xsl'; $src = __DIR__ . '/../_files/xsl/passthrough.xsl';
$oCell = new Cell(); $oCell = new Cell();
$oCell->addObject($src); $oCell->addObject($src);
@ -227,11 +226,10 @@ class CellTest extends AbstractWebServerEmbeddedTest
/** /**
* Add preserve text exception * Add preserve text exception
*
* @expectedException \BadMethodCallException
*/ */
public function testAddPreserveTextException() public function testAddPreserveTextException()
{ {
$this->expectException(\BadMethodCallException::class);
$oCell = new Cell(); $oCell = new Cell();
$oCell->setDocPart('TextRun', 1); $oCell->setDocPart('TextRun', 1);
$oCell->addPreserveText('text'); $oCell->addPreserveText('text');
@ -268,6 +266,6 @@ class CellTest extends AbstractWebServerEmbeddedTest
{ {
$oCell = new Cell(); $oCell = new Cell();
$this->assertInternalType('array', $oCell->getElements()); $this->assertIsArray($oCell->getElements());
} }
} }

View File

@ -66,7 +66,7 @@ class CommentTest extends \PHPUnit\Framework\TestCase
{ {
$oComment = new Comment('Test User', new \DateTime(), 'my_initials'); $oComment = new Comment('Test User', new \DateTime(), 'my_initials');
$this->assertInternalType('array', $oComment->getElements()); $this->assertIsArray($oComment->getElements());
} }
/** /**
@ -81,21 +81,17 @@ class CommentTest extends \PHPUnit\Framework\TestCase
$this->assertEquals($iVal, $oComment->getRelationId()); $this->assertEquals($iVal, $oComment->getRelationId());
} }
/**
* @expectedException \InvalidArgumentException
*/
public function testExceptionOnCommentStartOnComment() public function testExceptionOnCommentStartOnComment()
{ {
$this->expectException(\InvalidArgumentException::class);
$dummyComment = new Comment('Test User', new \DateTime(), 'my_initials'); $dummyComment = new Comment('Test User', new \DateTime(), 'my_initials');
$oComment = new Comment('Test User', new \DateTime(), 'my_initials'); $oComment = new Comment('Test User', new \DateTime(), 'my_initials');
$oComment->setCommentRangeStart($dummyComment); $oComment->setCommentRangeStart($dummyComment);
} }
/**
* @expectedException \InvalidArgumentException
*/
public function testExceptionOnCommentEndOnComment() public function testExceptionOnCommentEndOnComment()
{ {
$this->expectException(\InvalidArgumentException::class);
$dummyComment = new Comment('Test User', new \DateTime(), 'my_initials'); $dummyComment = new Comment('Test User', new \DateTime(), 'my_initials');
$oComment = new Comment('Test User', new \DateTime(), 'my_initials'); $oComment = new Comment('Test User', new \DateTime(), 'my_initials');
$oComment->setCommentRangeEnd($dummyComment); $oComment->setCommentRangeEnd($dummyComment);

View File

@ -113,48 +113,44 @@ class FieldTest extends \PHPUnit\Framework\TestCase
/** /**
* Test setType exception * Test setType exception
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Invalid type
*/ */
public function testSetTypeException() public function testSetTypeException()
{ {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid type');
$object = new Field(); $object = new Field();
$object->setType('foo'); $object->setType('foo');
} }
/** /**
* Test setProperties exception * Test setProperties exception
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Invalid property
*/ */
public function testSetPropertiesException() public function testSetPropertiesException()
{ {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid property');
$object = new Field('PAGE'); $object = new Field('PAGE');
$object->setProperties(array('foo' => 'bar')); $object->setProperties(array('foo' => 'bar'));
} }
/** /**
* Test setOptions exception * Test setOptions exception
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Invalid option
*/ */
public function testSetOptionsException() public function testSetOptionsException()
{ {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid option');
$object = new Field('PAGE'); $object = new Field('PAGE');
$object->setOptions(array('foo' => 'bar')); $object->setOptions(array('foo' => 'bar'));
} }
/** /**
* Test setText exception * Test setText exception
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Invalid text
*/ */
public function testSetTextException() public function testSetTextException()
{ {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid text');
$object = new Field('XE'); $object = new Field('XE');
$object->setText(array()); $object->setText(array());
} }

View File

@ -156,7 +156,7 @@ class FooterTest extends AbstractWebServerEmbeddedTest
{ {
$oFooter = new Footer(1); $oFooter = new Footer(1);
$this->assertInternalType('array', $oFooter->getElements()); $this->assertIsArray($oFooter->getElements());
} }
/** /**

View File

@ -112,6 +112,6 @@ class FootnoteTest extends \PHPUnit\Framework\TestCase
public function testGetElements() public function testGetElements()
{ {
$oFootnote = new Footnote(); $oFootnote = new Footnote();
$this->assertInternalType('array', $oFootnote->getElements()); $this->assertIsArray($oFootnote->getElements());
} }
} }

View File

@ -178,7 +178,7 @@ class HeaderTest extends AbstractWebServerEmbeddedTest
{ {
$oHeader = new Header(1); $oHeader = new Header(1);
$this->assertInternalType('array', $oHeader->getElements()); $this->assertIsArray($oHeader->getElements());
} }
/** /**
@ -229,11 +229,10 @@ class HeaderTest extends AbstractWebServerEmbeddedTest
/** /**
* Add footnote exception * Add footnote exception
*
* @expectedException \BadMethodCallException
*/ */
public function testAddFootnoteException() public function testAddFootnoteException()
{ {
$this->expectException(\BadMethodCallException::class);
$header = new Header(1); $header = new Header(1);
$header->addFootnote(); $header->addFootnote();
} }

View File

@ -108,32 +108,29 @@ class ImageTest extends AbstractWebServerEmbeddedTest
/** /**
* Test invalid local image * Test invalid local image
*
* @expectedException \PhpOffice\PhpWord\Exception\InvalidImageException
*/ */
public function testInvalidImageLocal() public function testInvalidImageLocal()
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\InvalidImageException::class);
new Image(__DIR__ . '/../_files/images/thisisnotarealimage'); new Image(__DIR__ . '/../_files/images/thisisnotarealimage');
} }
/** /**
* Test invalid PHP Image * Test invalid PHP Image
*
* @expectedException \PhpOffice\PhpWord\Exception\InvalidImageException
*/ */
public function testInvalidImagePhp() public function testInvalidImagePhp()
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\InvalidImageException::class);
$object = new Image('test.php'); $object = new Image('test.php');
$object->getSource(); $object->getSource();
} }
/** /**
* Test unsupported image * Test unsupported image
*
* @expectedException \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException
*/ */
public function testUnsupportedImage() public function testUnsupportedImage()
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\UnsupportedImageTypeException::class);
//disable ssl verification, never do this in real application, you should pass the certificiate instead!!! //disable ssl verification, never do this in real application, you should pass the certificiate instead!!!
$arrContextOptions = array( $arrContextOptions = array(
'ssl' => array( 'ssl' => array(
@ -236,11 +233,10 @@ class ImageTest extends AbstractWebServerEmbeddedTest
/** /**
* Test invalid string image * Test invalid string image
*
* @expectedException \PhpOffice\PhpWord\Exception\InvalidImageException
*/ */
public function testInvalidImageString() public function testInvalidImageString()
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\InvalidImageException::class);
$object = new Image('this_is-a_non_valid_image'); $object = new Image('this_is-a_non_valid_image');
$object->getSource(); $object->getSource();
} }

View File

@ -53,11 +53,10 @@ class ObjectTest extends \PHPUnit\Framework\TestCase
/** /**
* Create new instance with non-supported files * Create new instance with non-supported files
*
* @expectedException \PhpOffice\PhpWord\Exception\InvalidObjectException
*/ */
public function testConstructWithNotSupportedFiles() public function testConstructWithNotSupportedFiles()
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\InvalidObjectException::class);
$src = __DIR__ . '/../_files/xsl/passthrough.xsl'; $src = __DIR__ . '/../_files/xsl/passthrough.xsl';
$oObject = new OLEObject($src); $oObject = new OLEObject($src);
$oObject->getSource(); $oObject->getSource();

View File

@ -34,7 +34,7 @@ class RowTest extends \PHPUnit\Framework\TestCase
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Row', $oRow); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Row', $oRow);
$this->assertNull($oRow->getHeight()); $this->assertNull($oRow->getHeight());
$this->assertInternalType('array', $oRow->getCells()); $this->assertIsArray($oRow->getCells());
$this->assertCount(0, $oRow->getCells()); $this->assertCount(0, $oRow->getCells());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Row', $oRow->getStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Row', $oRow->getStyle());
} }

View File

@ -50,12 +50,11 @@ class SDTTest extends \PHPUnit\Framework\TestCase
/** /**
* Test set type exception * Test set type exception
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Invalid style value
*/ */
public function testSetTypeException() public function testSetTypeException()
{ {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid style value');
$object = new SDT('comboBox'); $object = new SDT('comboBox');
$object->setType('foo'); $object->setType('foo');
} }

View File

@ -109,10 +109,10 @@ class SectionTest extends \PHPUnit\Framework\TestCase
/** /**
* @coversNothing * @coversNothing
* @expectedException \PhpOffice\PhpWord\Exception\InvalidObjectException
*/ */
public function testAddObjectException() public function testAddObjectException()
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\InvalidObjectException::class);
$source = __DIR__ . '/_files/xsl/passthrough.xsl'; $source = __DIR__ . '/_files/xsl/passthrough.xsl';
$section = new Section(0); $section = new Section(0);
$section->addObject($source); $section->addObject($source);
@ -176,11 +176,11 @@ class SectionTest extends \PHPUnit\Framework\TestCase
/** /**
* @covers ::addHeader * @covers ::addHeader
* @expectedException \Exception
* @expectedExceptionMessage Invalid header/footer type.
*/ */
public function testAddHeaderException() public function testAddHeaderException()
{ {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Invalid header/footer type.');
$object = new Section(1); $object = new Section(1);
$object->addHeader('ODD'); $object->addHeader('ODD');
} }

View File

@ -58,11 +58,9 @@ class TitleTest extends \PHPUnit\Framework\TestCase
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\TextRun', $oTitle->getText()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\TextRun', $oTitle->getText());
} }
/**
* @expectedException \InvalidArgumentException
*/
public function testConstructWithInvalidArgument() public function testConstructWithInvalidArgument()
{ {
$this->expectException(\InvalidArgumentException::class);
$oPageBreak = new PageBreak(); $oPageBreak = new PageBreak();
new Title($oPageBreak); new Title($oPageBreak);
} }

View File

@ -27,11 +27,11 @@ class CopyFileExceptionTest extends \PHPUnit\Framework\TestCase
* CopyFileException can be thrown. * CopyFileException can be thrown.
* *
* @covers ::__construct() * @covers ::__construct()
* @expectedException \PhpOffice\PhpWord\Exception\CopyFileException
* @test * @test
*/ */
public function testCopyFileExceptionCanBeThrown() public function testCopyFileExceptionCanBeThrown()
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\CopyFileException::class);
throw new CopyFileException('C:\source\dummy.txt', 'C:\destination\dummy.txt'); throw new CopyFileException('C:\source\dummy.txt', 'C:\destination\dummy.txt');
} }
} }

View File

@ -27,11 +27,11 @@ class CreateTemporaryFileExceptionTest extends \PHPUnit\Framework\TestCase
* CreateTemporaryFileException can be thrown. * CreateTemporaryFileException can be thrown.
* *
* @covers ::__construct() * @covers ::__construct()
* @expectedException \PhpOffice\PhpWord\Exception\CreateTemporaryFileException
* @test * @test
*/ */
public function testCreateTemporaryFileExceptionCanBeThrown() public function testCreateTemporaryFileExceptionCanBeThrown()
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\CreateTemporaryFileException::class);
throw new CreateTemporaryFileException(); throw new CreateTemporaryFileException();
} }
} }

View File

@ -28,11 +28,11 @@ class ExceptionTest extends \PHPUnit\Framework\TestCase
/** /**
* Throw new exception * Throw new exception
* *
* @expectedException \PhpOffice\PhpWord\Exception\Exception
* @covers \PhpOffice\PhpWord\Exception\Exception * @covers \PhpOffice\PhpWord\Exception\Exception
*/ */
public function testThrowException() public function testThrowException()
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\Exception::class);
throw new Exception(); throw new Exception();
} }
} }

View File

@ -28,11 +28,11 @@ class InvalidImageExceptionTest extends \PHPUnit\Framework\TestCase
/** /**
* Throw new exception * Throw new exception
* *
* @expectedException \PhpOffice\PhpWord\Exception\InvalidImageException
* @covers \PhpOffice\PhpWord\Exception\InvalidImageException * @covers \PhpOffice\PhpWord\Exception\InvalidImageException
*/ */
public function testThrowException() public function testThrowException()
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\InvalidImageException::class);
throw new InvalidImageException(); throw new InvalidImageException();
} }
} }

View File

@ -28,11 +28,11 @@ class InvalidStyleExceptionTest extends \PHPUnit\Framework\TestCase
/** /**
* Throw new exception * Throw new exception
* *
* @expectedException \PhpOffice\PhpWord\Exception\InvalidStyleException
* @covers \PhpOffice\PhpWord\Exception\InvalidStyleException * @covers \PhpOffice\PhpWord\Exception\InvalidStyleException
*/ */
public function testThrowException() public function testThrowException()
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\InvalidStyleException::class);
throw new InvalidStyleException(); throw new InvalidStyleException();
} }
} }

View File

@ -28,11 +28,11 @@ class UnsupportedImageTypeExceptionTest extends \PHPUnit\Framework\TestCase
/** /**
* Throw new exception * Throw new exception
* *
* @expectedException \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException
* @covers \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException * @covers \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException
*/ */
public function testThrowException() public function testThrowException()
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\UnsupportedImageTypeException::class);
throw new UnsupportedImageTypeException(); throw new UnsupportedImageTypeException();
} }
} }

View File

@ -37,11 +37,10 @@ class IOFactoryTest extends \PHPUnit\Framework\TestCase
/** /**
* Create non-existing writer * Create non-existing writer
*
* @expectedException \PhpOffice\PhpWord\Exception\Exception
*/ */
public function testNonexistentWriterCanNotBeCreated() public function testNonexistentWriterCanNotBeCreated()
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\Exception::class);
IOFactory::createWriter(new PhpWord(), 'Word2006'); IOFactory::createWriter(new PhpWord(), 'Word2006');
} }
@ -58,11 +57,10 @@ class IOFactoryTest extends \PHPUnit\Framework\TestCase
/** /**
* Create non-existing reader * Create non-existing reader
*
* @expectedException \PhpOffice\PhpWord\Exception\Exception
*/ */
public function testNonexistentReaderCanNotBeCreated() public function testNonexistentReaderCanNotBeCreated()
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\Exception::class);
IOFactory::createReader('Word2006'); IOFactory::createReader('Word2006');
} }

View File

@ -121,12 +121,11 @@ class MediaTest extends AbstractWebServerEmbeddedTest
/** /**
* Add image element exception * Add image element exception
*
* @expectedException \Exception
* @expectedExceptionMessage Image object not assigned.
*/ */
public function testAddElementImageException() public function testAddElementImageException()
{ {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Image object not assigned.');
Media::addElement('section', 'image', __DIR__ . '/_files/images/mars.jpg'); Media::addElement('section', 'image', __DIR__ . '/_files/images/mars.jpg');
} }
} }

View File

@ -71,10 +71,10 @@ class SettingsTest extends \PHPUnit\Framework\TestCase
/** /**
* Test setting an invalid salt * Test setting an invalid salt
* @expectedException \InvalidArgumentException
*/ */
public function testInvalidSalt() public function testInvalidSalt()
{ {
$this->expectException(\InvalidArgumentException::class);
$protection = new Protection(); $protection = new Protection();
$protection->setSalt('123'); $protection->setSalt('123');
} }
@ -125,20 +125,16 @@ class SettingsTest extends \PHPUnit\Framework\TestCase
$this->assertEquals(ProofState::DIRTY, $oSettings->getProofState()->getSpelling()); $this->assertEquals(ProofState::DIRTY, $oSettings->getProofState()->getSpelling());
} }
/**
* @expectedException \InvalidArgumentException
*/
public function testWrongProofStateGrammar() public function testWrongProofStateGrammar()
{ {
$this->expectException(\InvalidArgumentException::class);
$proofState = new ProofState(); $proofState = new ProofState();
$proofState->setGrammar('wrong'); $proofState->setGrammar('wrong');
} }
/**
* @expectedException \InvalidArgumentException
*/
public function testWrongProofStateSpelling() public function testWrongProofStateSpelling()
{ {
$this->expectException(\InvalidArgumentException::class);
$proofState = new ProofState(); $proofState = new ProofState();
$proofState->setSpelling('wrong'); $proofState->setSpelling('wrong');
} }

View File

@ -133,11 +133,10 @@ class PhpWordTest extends \PHPUnit\Framework\TestCase
* Test load template exception * Test load template exception
* *
* @deprecated 0.12.0 * @deprecated 0.12.0
*
* @expectedException \PhpOffice\PhpWord\Exception\Exception
*/ */
public function testLoadTemplateException() public function testLoadTemplateException()
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\Exception::class);
$templateFqfn = implode( $templateFqfn = implode(
DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR,
array(PHPWORD_TESTS_BASE_DIR, 'PhpWord', 'Tests', '_files', 'templates', 'blanks.docx') array(PHPWORD_TESTS_BASE_DIR, 'PhpWord', 'Tests', '_files', 'templates', 'blanks.docx')
@ -162,12 +161,11 @@ class PhpWordTest extends \PHPUnit\Framework\TestCase
/** /**
* Test calling undefined method * Test calling undefined method
*
* @expectedException \BadMethodCallException
* @expectedExceptionMessage is not defined
*/ */
public function testCallUndefinedMethod() public function testCallUndefinedMethod()
{ {
$this->expectException(\BadMethodCallException::class);
$this->expectExceptionMessage('is not defined');
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$phpWord->undefinedMethod(); $phpWord->undefinedMethod();
} }

View File

@ -39,12 +39,11 @@ class HTMLTest extends \PHPUnit\Framework\TestCase
/** /**
* Test load exception * Test load exception
*
* @expectedException \Exception
* @expectedExceptionMessage Cannot read
*/ */
public function testLoadException() public function testLoadException()
{ {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Cannot read');
$filename = __DIR__ . '/../_files/documents/foo.html'; $filename = __DIR__ . '/../_files/documents/foo.html';
IOFactory::load($filename, 'HTML'); IOFactory::load($filename, 'HTML');
} }

View File

@ -59,20 +59,20 @@ class MsDocTest extends \PHPUnit\Framework\TestCase
/** /**
* Test exception on not existing file * Test exception on not existing file
* @expectedException \Exception
*/ */
public function testFailIfFileNotReadable() public function testFailIfFileNotReadable()
{ {
$this->expectException(\Exception::class);
$filename = __DIR__ . '/../_files/documents/not_existing_reader.doc'; $filename = __DIR__ . '/../_files/documents/not_existing_reader.doc';
IOFactory::load($filename, 'MsDoc'); IOFactory::load($filename, 'MsDoc');
} }
/** /**
* Test exception on non OLE document * Test exception on non OLE document
* @expectedException \Exception
*/ */
public function testFailIfFileNotOle() public function testFailIfFileNotOle()
{ {
$this->expectException(\Exception::class);
$filename = __DIR__ . '/../_files/documents/reader.odt'; $filename = __DIR__ . '/../_files/documents/reader.odt';
IOFactory::load($filename, 'MsDoc'); IOFactory::load($filename, 'MsDoc');
} }

View File

@ -39,12 +39,11 @@ class RTFTest extends \PHPUnit\Framework\TestCase
/** /**
* Test load exception * Test load exception
*
* @expectedException \Exception
* @expectedExceptionMessage Cannot read
*/ */
public function testLoadException() public function testLoadException()
{ {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Cannot read');
$filename = __DIR__ . '/../_files/documents/foo.rtf'; $filename = __DIR__ . '/../_files/documents/foo.rtf';
IOFactory::load($filename, 'RTF'); IOFactory::load($filename, 'RTF');
} }

View File

@ -36,7 +36,7 @@ class SettingsTest extends \PHPUnit\Framework\TestCase
private $tempDir; private $tempDir;
private $zipClass; private $zipClass;
public function setUp() public function setUp(): void
{ {
$this->compatibility = Settings::hasCompatibility(); $this->compatibility = Settings::hasCompatibility();
$this->defaultFontSize = Settings::getDefaultFontSize(); $this->defaultFontSize = Settings::getDefaultFontSize();
@ -50,7 +50,7 @@ class SettingsTest extends \PHPUnit\Framework\TestCase
$this->zipClass = Settings::getZipClass(); $this->zipClass = Settings::getZipClass();
} }
public function tearDown() public function tearDown(): void
{ {
Settings::setCompatibility($this->compatibility); Settings::setCompatibility($this->compatibility);
Settings::setDefaultFontSize($this->defaultFontSize); Settings::setDefaultFontSize($this->defaultFontSize);

View File

@ -36,70 +36,70 @@ class ConverterTest extends \PHPUnit\Framework\TestCase
foreach ($values as $value) { foreach ($values as $value) {
$result = Converter::cmToTwip($value); $result = Converter::cmToTwip($value);
$this->assertEquals($value / 2.54 * 1440, $result, '', 0.00001); $this->assertEqualsWithDelta($value / 2.54 * 1440, $result, 0.00001);
$result = Converter::cmToInch($value); $result = Converter::cmToInch($value);
$this->assertEquals($value / 2.54, $result, '', 0.00001); $this->assertEqualsWithDelta($value / 2.54, $result, 0.00001);
$result = Converter::cmToPixel($value); $result = Converter::cmToPixel($value);
$this->assertEquals($value / 2.54 * 96, $result, '', 0.00001); $this->assertEqualsWithDelta($value / 2.54 * 96, $result, 0.00001);
$result = Converter::cmToPoint($value); $result = Converter::cmToPoint($value);
$this->assertEquals($value / 2.54 * 72, $result, '', 0.00001); $this->assertEqualsWithDelta($value / 2.54 * 72, $result, 0.00001);
$result = Converter::cmToEmu($value); $result = Converter::cmToEmu($value);
$this->assertEquals(round($value / 2.54 * 96 * 9525), $result, '', 0.00001); $this->assertEqualsWithDelta(round($value / 2.54 * 96 * 9525), $result, 0.00001);
$result = Converter::inchToTwip($value); $result = Converter::inchToTwip($value);
$this->assertEquals($value * 1440, $result, '', 0.00001); $this->assertEqualsWithDelta($value * 1440, $result, 0.00001);
$result = Converter::inchToCm($value); $result = Converter::inchToCm($value);
$this->assertEquals($value * 2.54, $result, '', 0.00001); $this->assertEqualsWithDelta($value * 2.54, $result, 0.00001);
$result = Converter::inchToPixel($value); $result = Converter::inchToPixel($value);
$this->assertEquals($value * 96, $result, '', 0.00001); $this->assertEqualsWithDelta($value * 96, $result, 0.00001);
$result = Converter::inchToPoint($value); $result = Converter::inchToPoint($value);
$this->assertEquals($value * 72, $result, '', 0.00001); $this->assertEqualsWithDelta($value * 72, $result, 0.00001);
$result = Converter::inchToEmu($value); $result = Converter::inchToEmu($value);
$this->assertEquals(round($value * 96 * 9525), $result, '', 0.00001); $this->assertEqualsWithDelta(round($value * 96 * 9525), $result, 0.00001);
$result = Converter::pixelToTwip($value); $result = Converter::pixelToTwip($value);
$this->assertEquals($value / 96 * 1440, $result, '', 0.00001); $this->assertEqualsWithDelta($value / 96 * 1440, $result, 0.00001);
$result = Converter::pixelToCm($value); $result = Converter::pixelToCm($value);
$this->assertEquals($value / 96 * 2.54, $result, '', 0.00001); $this->assertEqualsWithDelta($value / 96 * 2.54, $result, 0.00001);
$result = Converter::pixelToPoint($value); $result = Converter::pixelToPoint($value);
$this->assertEquals($value / 96 * 72, $result, '', 0.00001); $this->assertEqualsWithDelta($value / 96 * 72, $result, 0.00001);
$result = Converter::pixelToEmu($value); $result = Converter::pixelToEmu($value);
$this->assertEquals(round($value * 9525), $result, '', 0.00001); $this->assertEqualsWithDelta(round($value * 9525), $result, 0.00001);
$result = Converter::pointToTwip($value); $result = Converter::pointToTwip($value);
$this->assertEquals($value * 20, $result, '', 0.00001); $this->assertEqualsWithDelta($value * 20, $result, 0.00001);
$result = Converter::pointToCm($value); $result = Converter::pointToCm($value);
$this->assertEquals($value * 0.035277778, $result, '', 0.00001); $this->assertEqualsWithDelta($value * 0.035277778, $result, 0.00001);
$result = Converter::pointToPixel($value); $result = Converter::pointToPixel($value);
$this->assertEquals($value / 72 * 96, $result, '', 0.00001); $this->assertEqualsWithDelta($value / 72 * 96, $result, 0.00001);
$result = Converter::pointToEmu($value); $result = Converter::pointToEmu($value);
$this->assertEquals(round($value / 72 * 96 * 9525), $result, '', 0.00001); $this->assertEqualsWithDelta(round($value / 72 * 96 * 9525), $result, 0.00001);
$result = Converter::emuToPixel($value); $result = Converter::emuToPixel($value);
$this->assertEquals(round($value / 9525), $result, '', 0.00001); $this->assertEqualsWithDelta(round($value / 9525), $result, 0.00001);
$result = Converter::picaToPoint($value); $result = Converter::picaToPoint($value);
$this->assertEquals($value / 6 * 72, $result, '', 0.00001); $this->assertEqualsWithDelta($value / 6 * 72, $result, 0.00001);
$result = Converter::degreeToAngle($value); $result = Converter::degreeToAngle($value);
$this->assertEquals((int) round($value * 60000), $result, '', 0.00001); $this->assertEqualsWithDelta((int) round($value * 60000), $result, 0.00001);
$result = Converter::angleToDegree($value); $result = Converter::angleToDegree($value);
$this->assertEquals(round($value / 60000), $result, '', 0.00001); $this->assertEqualsWithDelta(round($value / 60000), $result, 0.00001);
} }
} }
@ -129,8 +129,8 @@ class ConverterTest extends \PHPUnit\Framework\TestCase
$this->assertEquals(720, Converter::cssToPoint('10in')); $this->assertEquals(720, Converter::cssToPoint('10in'));
$this->assertEquals(7.2, Converter::cssToPoint('0.1in')); $this->assertEquals(7.2, Converter::cssToPoint('0.1in'));
$this->assertEquals(120, Converter::cssToPoint('10pc')); $this->assertEquals(120, Converter::cssToPoint('10pc'));
$this->assertEquals(28.346457, Converter::cssToPoint('10mm'), '', 0.000001); $this->assertEqualsWithDelta(28.346457, Converter::cssToPoint('10mm'), 0.000001);
$this->assertEquals(283.464567, Converter::cssToPoint('10cm'), '', 0.000001); $this->assertEqualsWithDelta(283.464567, Converter::cssToPoint('10cm'), 0.000001);
$this->assertEquals(40, Converter::cssToPixel('30pt')); $this->assertEquals(40, Converter::cssToPixel('30pt'));
$this->assertEquals(1.27, Converter::cssToCm('36pt')); $this->assertEquals(1.27, Converter::cssToCm('36pt'));
$this->assertEquals(127000, Converter::cssToEmu('10pt')); $this->assertEquals(127000, Converter::cssToEmu('10pt'));

View File

@ -102,7 +102,7 @@ class DrawingTest extends \PHPUnit\Framework\TestCase
$this->assertFalse(Drawing::htmlToRGB('0000')); $this->assertFalse(Drawing::htmlToRGB('0000'));
$this->assertFalse(Drawing::htmlToRGB('00000')); $this->assertFalse(Drawing::htmlToRGB('00000'));
$this->assertInternalType('array', Drawing::htmlToRGB('ABCDEF')); $this->assertIsArray(Drawing::htmlToRGB('ABCDEF'));
$this->assertCount(3, Drawing::htmlToRGB('ABCDEF')); $this->assertCount(3, Drawing::htmlToRGB('ABCDEF'));
$this->assertEquals(array(0xAB, 0xCD, 0xEF), Drawing::htmlToRGB('ABCDEF')); $this->assertEquals(array(0xAB, 0xCD, 0xEF), Drawing::htmlToRGB('ABCDEF'));
$this->assertEquals(array(0xAB, 0xCD, 0xEF), Drawing::htmlToRGB('#ABCDEF')); $this->assertEquals(array(0xAB, 0xCD, 0xEF), Drawing::htmlToRGB('#ABCDEF'));

View File

@ -607,11 +607,10 @@ class HtmlTest extends AbstractWebServerEmbeddedTest
/** /**
* Test parsing of remote img that can be found locally * Test parsing of remote img that can be found locally
*
* @expectedException \Exception
*/ */
public function testCouldNotLoadImage() public function testCouldNotLoadImage()
{ {
$this->expectException(\Exception::class);
$src = 'https://fakedomain.io/images/firefox.png'; $src = 'https://fakedomain.io/images/firefox.png';
$phpWord = new \PhpOffice\PhpWord\PhpWord(); $phpWord = new \PhpOffice\PhpWord\PhpWord();
@ -973,6 +972,6 @@ HTML;
Html::addHtml($section, $html); Html::addHtml($section, $html);
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007'); $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
$this->assertInternalType('object', $doc); $this->assertIsObject($doc);
} }
} }

View File

@ -56,11 +56,10 @@ class XMLReaderTest extends \PHPUnit\Framework\TestCase
/** /**
* Test that read from non existing archive throws exception * Test that read from non existing archive throws exception
*
* @expectedException \Exception
*/ */
public function testThrowsExceptionOnNonExistingArchive() public function testThrowsExceptionOnNonExistingArchive()
{ {
$this->expectException(\Exception::class);
$archiveFile = __DIR__ . '/../_files/xml/readers.zip'; $archiveFile = __DIR__ . '/../_files/xml/readers.zip';
$reader = new XMLReader(); $reader = new XMLReader();
@ -123,11 +122,10 @@ class XMLReaderTest extends \PHPUnit\Framework\TestCase
/** /**
* Test that xpath fails if custom namespace is not registered * Test that xpath fails if custom namespace is not registered
*
* @expectedException \InvalidArgumentException
*/ */
public function testShouldThowExceptionIfTryingToRegisterNamespaceBeforeReadingDoc() public function testShouldThowExceptionIfTryingToRegisterNamespaceBeforeReadingDoc()
{ {
$this->expectException(\InvalidArgumentException::class);
$reader = new XMLReader(); $reader = new XMLReader();
$reader->registerNamespace('test', 'http://phpword.com/my/custom/namespace'); $reader->registerNamespace('test', 'http://phpword.com/my/custom/namespace');
} }

View File

@ -64,11 +64,10 @@ class AbstractStyleTest extends \PHPUnit\Framework\TestCase
/** /**
* Test setEnumVal exception * Test setEnumVal exception
*
* @expectedException \InvalidArgumentException
*/ */
public function testSetValEnumException() public function testSetValEnumException()
{ {
$this->expectException(\InvalidArgumentException::class);
$stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Style\AbstractStyle'); $stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Style\AbstractStyle');
$this->assertEquals('b', self::callProtectedMethod($stub, 'setEnumVal', array('z', array('a', 'b'), 'b'))); $this->assertEquals('b', self::callProtectedMethod($stub, 'setEnumVal', array('z', array('a', 'b'), 'b')));

View File

@ -74,7 +74,7 @@ class ChartTest extends \PHPUnit\Framework\TestCase
{ {
$chart = new Chart(); $chart = new Chart();
$this->assertInternalType('array', $chart->getColors()); $this->assertIsArray($chart->getColors());
$this->assertEquals(count($chart->getColors()), 0); $this->assertEquals(count($chart->getColors()), 0);

View File

@ -31,7 +31,7 @@ class FontTest extends \PHPUnit\Framework\TestCase
/** /**
* Tear down after each test * Tear down after each test
*/ */
public function tearDown() public function tearDown(): void
{ {
TestHelperDOCX::clear(); TestHelperDOCX::clear();
} }
@ -45,7 +45,7 @@ class FontTest extends \PHPUnit\Framework\TestCase
$this->assertEquals('text', $object->getStyleType()); $this->assertEquals('text', $object->getStyleType());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $object->getParagraphStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $object->getParagraphStyle());
$this->assertInternalType('array', $object->getStyleValues()); $this->assertIsArray($object->getStyleValues());
} }
/** /**
@ -171,11 +171,10 @@ class FontTest extends \PHPUnit\Framework\TestCase
/** /**
* Test line height exception by using nonnumeric value * Test line height exception by using nonnumeric value
*
* @expectedException \PhpOffice\PhpWord\Exception\InvalidStyleException
*/ */
public function testLineHeightException() public function testLineHeightException()
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\InvalidStyleException::class);
$object = new Font(); $object = new Font();
$object->setLineHeight('a'); $object->setLineHeight('a');
} }

View File

@ -87,11 +87,10 @@ class ImageTest extends \PHPUnit\Framework\TestCase
/** /**
* Test setWrappingStyle exception * Test setWrappingStyle exception
*
* @expectedException \InvalidArgumentException
*/ */
public function testSetWrappingStyleException() public function testSetWrappingStyleException()
{ {
$this->expectException(\InvalidArgumentException::class);
$object = new Image(); $object = new Image();
$object->setWrappingStyle('foo'); $object->setWrappingStyle('foo');
} }

View File

@ -53,11 +53,10 @@ class LanguageTest extends \PHPUnit\Framework\TestCase
/** /**
* Test throws exception if wrong locale is given * Test throws exception if wrong locale is given
*
* @expectedException \InvalidArgumentException
*/ */
public function testWrongLanguage() public function testWrongLanguage()
{ {
$this->expectException(\InvalidArgumentException::class);
$language = new Language(); $language = new Language();
$language->setLatin('fra'); $language->setLatin('fra');
} }

View File

@ -29,7 +29,7 @@ class PaperTest extends \PHPUnit\Framework\TestCase
/** /**
* Tear down after each test * Tear down after each test
*/ */
public function tearDown() public function tearDown(): void
{ {
TestHelperDOCX::clear(); TestHelperDOCX::clear();
} }
@ -52,8 +52,8 @@ class PaperTest extends \PHPUnit\Framework\TestCase
$object = new Paper('B5'); $object = new Paper('B5');
$this->assertEquals('B5', $object->getSize()); $this->assertEquals('B5', $object->getSize());
$this->assertEquals(9977.9527559055, $object->getWidth(), '', 0.000000001); $this->assertEqualsWithDelta(9977.9527559055, $object->getWidth(), 0.000000001);
$this->assertEquals(14173.228346457, $object->getHeight(), '', 0.000000001); $this->assertEqualsWithDelta(14173.228346457, $object->getHeight(), 0.000000001);
} }
/** /**
@ -65,7 +65,7 @@ class PaperTest extends \PHPUnit\Framework\TestCase
$object->setSize('Folio'); $object->setSize('Folio');
$this->assertEquals('Folio', $object->getSize()); $this->assertEquals('Folio', $object->getSize());
$this->assertEquals(12240, $object->getWidth(), '', 0.1); $this->assertEqualsWithDelta(12240, $object->getWidth(), 0.1);
$this->assertEquals(18720, $object->getHeight(), '', 0.1); $this->assertEqualsWithDelta(18720, $object->getHeight(), 0.1);
} }
} }

View File

@ -31,7 +31,7 @@ class ParagraphTest extends \PHPUnit\Framework\TestCase
/** /**
* Tear down after each test * Tear down after each test
*/ */
public function tearDown() public function tearDown(): void
{ {
TestHelperDOCX::clear(); TestHelperDOCX::clear();
} }
@ -177,11 +177,10 @@ class ParagraphTest extends \PHPUnit\Framework\TestCase
/** /**
* Test line height exception by using nonnumeric value * Test line height exception by using nonnumeric value
*
* @expectedException \PhpOffice\PhpWord\Exception\InvalidStyleException
*/ */
public function testLineHeightException() public function testLineHeightException()
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\InvalidStyleException::class);
$object = new Paragraph(); $object = new Paragraph();
$object->setLineHeight('a'); $object->setLineHeight('a');
} }

View File

@ -35,14 +35,14 @@ class SectionTest extends \PHPUnit\Framework\TestCase
$oSettings = new Section(); $oSettings = new Section();
$this->assertEquals('portrait', $oSettings->getOrientation()); $this->assertEquals('portrait', $oSettings->getOrientation());
$this->assertEquals(Section::DEFAULT_WIDTH, $oSettings->getPageSizeW(), '', 0.000000001); $this->assertEqualsWithDelta(Section::DEFAULT_WIDTH, $oSettings->getPageSizeW(), 0.000000001);
$this->assertEquals(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeH(), '', 0.000000001); $this->assertEqualsWithDelta(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeH(), 0.000000001);
$this->assertEquals('A4', $oSettings->getPaperSize()); $this->assertEquals('A4', $oSettings->getPaperSize());
$oSettings->setSettingValue('orientation', 'landscape'); $oSettings->setSettingValue('orientation', 'landscape');
$this->assertEquals('landscape', $oSettings->getOrientation()); $this->assertEquals('landscape', $oSettings->getOrientation());
$this->assertEquals(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeW(), '', 0.000000001); $this->assertEqualsWithDelta(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeW(), 0.000000001);
$this->assertEquals(Section::DEFAULT_WIDTH, $oSettings->getPageSizeH(), '', 0.000000001); $this->assertEqualsWithDelta(Section::DEFAULT_WIDTH, $oSettings->getPageSizeH(), 0.000000001);
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oSettings->setSettingValue('borderSize', $iVal); $oSettings->setSettingValue('borderSize', $iVal);
@ -112,7 +112,7 @@ class SectionTest extends \PHPUnit\Framework\TestCase
// Section Settings // Section Settings
$oSettings = new Section(); $oSettings = new Section();
$this->assertEquals(Section::DEFAULT_WIDTH, $oSettings->getPageSizeW(), '', 0.000000001); $this->assertEqualsWithDelta(Section::DEFAULT_WIDTH, $oSettings->getPageSizeW(), 0.000000001);
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oSettings->setSettingValue('pageSizeW', $iVal); $oSettings->setSettingValue('pageSizeW', $iVal);
$this->assertEquals($iVal, $oSettings->getPageSizeW()); $this->assertEquals($iVal, $oSettings->getPageSizeW());
@ -126,7 +126,7 @@ class SectionTest extends \PHPUnit\Framework\TestCase
// Section Settings // Section Settings
$oSettings = new Section(); $oSettings = new Section();
$this->assertEquals(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeH(), '', 0.000000001); $this->assertEqualsWithDelta(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeH(), 0.000000001);
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oSettings->setSettingValue('pageSizeH', $iVal); $oSettings->setSettingValue('pageSizeH', $iVal);
$this->assertEquals($iVal, $oSettings->getPageSizeH()); $this->assertEquals($iVal, $oSettings->getPageSizeH());
@ -142,8 +142,8 @@ class SectionTest extends \PHPUnit\Framework\TestCase
$oSettings->setLandscape(); $oSettings->setLandscape();
$this->assertEquals('landscape', $oSettings->getOrientation()); $this->assertEquals('landscape', $oSettings->getOrientation());
$this->assertEquals(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeW(), '', 0.000000001); $this->assertEqualsWithDelta(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeW(), 0.000000001);
$this->assertEquals(Section::DEFAULT_WIDTH, $oSettings->getPageSizeH(), '', 0.000000001); $this->assertEqualsWithDelta(Section::DEFAULT_WIDTH, $oSettings->getPageSizeH(), 0.000000001);
} }
/** /**
@ -156,8 +156,8 @@ class SectionTest extends \PHPUnit\Framework\TestCase
$oSettings->setPortrait(); $oSettings->setPortrait();
$this->assertEquals('portrait', $oSettings->getOrientation()); $this->assertEquals('portrait', $oSettings->getOrientation());
$this->assertEquals(Section::DEFAULT_WIDTH, $oSettings->getPageSizeW(), '', 0.000000001); $this->assertEqualsWithDelta(Section::DEFAULT_WIDTH, $oSettings->getPageSizeW(), 0.000000001);
$this->assertEquals(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeH(), '', 0.000000001); $this->assertEqualsWithDelta(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeH(), 0.000000001);
} }
/** /**

View File

@ -96,11 +96,10 @@ class TextBoxTest extends \PHPUnit\Framework\TestCase
/** /**
* Test setWrappingStyle exception * Test setWrappingStyle exception
*
* @expectedException \InvalidArgumentException
*/ */
public function testSetWrappingStyleException() public function testSetWrappingStyleException()
{ {
$this->expectException(\InvalidArgumentException::class);
$object = new TextBox(); $object = new TextBox();
$object->setWrappingStyle('foo'); $object->setWrappingStyle('foo');
} }

View File

@ -134,12 +134,12 @@ final class TemplateProcessorTest extends \PHPUnit\Framework\TestCase
* XSL stylesheet cannot be applied on failure in setting parameter value. * XSL stylesheet cannot be applied on failure in setting parameter value.
* *
* @covers ::applyXslStyleSheet * @covers ::applyXslStyleSheet
* @expectedException \PhpOffice\PhpWord\Exception\Exception
* @expectedExceptionMessage Could not set values for the given XSL style sheet parameters.
* @test * @test
*/ */
final public function testXslStyleSheetCanNotBeAppliedOnFailureOfSettingParameterValue() final public function testXslStyleSheetCanNotBeAppliedOnFailureOfSettingParameterValue()
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\Exception::class);
$this->expectExceptionMessage('Could not set values for the given XSL style sheet parameters.');
// Test is not needed for PHP 8.0, because internally validation throws TypeError exception. // Test is not needed for PHP 8.0, because internally validation throws TypeError exception.
if (\PHP_VERSION_ID >= 80000) { if (\PHP_VERSION_ID >= 80000) {
$this->markTestSkipped('not needed for PHP 8.0'); $this->markTestSkipped('not needed for PHP 8.0');
@ -161,12 +161,12 @@ final class TemplateProcessorTest extends \PHPUnit\Framework\TestCase
* XSL stylesheet can be applied on failure of loading XML from template. * XSL stylesheet can be applied on failure of loading XML from template.
* *
* @covers ::applyXslStyleSheet * @covers ::applyXslStyleSheet
* @expectedException \PhpOffice\PhpWord\Exception\Exception
* @expectedExceptionMessage Could not load the given XML document.
* @test * @test
*/ */
final public function testXslStyleSheetCanNotBeAppliedOnFailureOfLoadingXmlFromTemplate() final public function testXslStyleSheetCanNotBeAppliedOnFailureOfLoadingXmlFromTemplate()
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\Exception::class);
$this->expectExceptionMessage('Could not load the given XML document.');
$templateProcessor = new TemplateProcessor(__DIR__ . '/_files/templates/corrupted_main_document_part.docx'); $templateProcessor = new TemplateProcessor(__DIR__ . '/_files/templates/corrupted_main_document_part.docx');
$xslDomDocument = new \DOMDocument(); $xslDomDocument = new \DOMDocument();
@ -261,16 +261,16 @@ final class TemplateProcessorTest extends \PHPUnit\Framework\TestCase
); );
$templateProcessor->setValue('tableHeader', 'My clonable table'); $templateProcessor->setValue('tableHeader', 'My clonable table');
$templateProcessor->cloneRowAndSetValues('userId', $values); $templateProcessor->cloneRowAndSetValues('userId', $values);
$this->assertContains('<w:t>Superman</w:t>', $templateProcessor->getMainPart()); $this->assertStringContainsString('<w:t>Superman</w:t>', $templateProcessor->getMainPart());
$this->assertContains('<w:t>Metropolis</w:t>', $templateProcessor->getMainPart()); $this->assertStringContainsString('<w:t>Metropolis</w:t>', $templateProcessor->getMainPart());
} }
/** /**
* @expectedException \Exception
* @test * @test
*/ */
public function testCloneNotExistingRowShouldThrowException() public function testCloneNotExistingRowShouldThrowException()
{ {
$this->expectException(\Exception::class);
$mainPart = '<?xml version="1.0" encoding="UTF-8"?><w:p><w:r><w:rPr></w:rPr><w:t>text</w:t></w:r></w:p>'; $mainPart = '<?xml version="1.0" encoding="UTF-8"?><w:p><w:r><w:rPr></w:rPr><w:t>text</w:t></w:r></w:p>';
$templateProcessor = new TestableTemplateProcesor($mainPart); $templateProcessor = new TestableTemplateProcesor($mainPart);
@ -384,7 +384,7 @@ final class TemplateProcessorTest extends \PHPUnit\Framework\TestCase
$templateProcessor = new TestableTemplateProcesor($mainPart); $templateProcessor = new TestableTemplateProcesor($mainPart);
$templateProcessor->setValues(array('firstname' => 'John', 'lastname' => 'Doe')); $templateProcessor->setValues(array('firstname' => 'John', 'lastname' => 'Doe'));
$this->assertContains('Hello John Doe', $templateProcessor->getMainPart()); $this->assertStringContainsString('Hello John Doe', $templateProcessor->getMainPart());
} }
/** /**
@ -425,15 +425,15 @@ final class TemplateProcessorTest extends \PHPUnit\Framework\TestCase
} }
$this->assertNotEmpty($expectedImage, 'Embed image doesn\'t found.'); $this->assertNotEmpty($expectedImage, 'Embed image doesn\'t found.');
$this->assertContains('/word/media/image_rId11_document.jpeg', $expectedContentTypesXml, '[Content_Types].xml missed "/word/media/image5_document.jpeg"'); $this->assertStringContainsString('/word/media/image_rId11_document.jpeg', $expectedContentTypesXml, '[Content_Types].xml missed "/word/media/image5_document.jpeg"');
$this->assertContains('/word/_rels/header1.xml.rels', $expectedContentTypesXml, '[Content_Types].xml missed "/word/_rels/header1.xml.rels"'); $this->assertStringContainsString('/word/_rels/header1.xml.rels', $expectedContentTypesXml, '[Content_Types].xml missed "/word/_rels/header1.xml.rels"');
$this->assertContains('/word/_rels/footer1.xml.rels', $expectedContentTypesXml, '[Content_Types].xml missed "/word/_rels/footer1.xml.rels"'); $this->assertStringContainsString('/word/_rels/footer1.xml.rels', $expectedContentTypesXml, '[Content_Types].xml missed "/word/_rels/footer1.xml.rels"');
$this->assertNotContains('${documentContent}', $expectedMainPartXml, 'word/document.xml has no image.'); $this->assertStringNotContainsString('${documentContent}', $expectedMainPartXml, 'word/document.xml has no image.');
$this->assertNotContains('${headerValue}', $expectedHeaderPartXml, 'word/header1.xml has no image.'); $this->assertStringNotContainsString('${headerValue}', $expectedHeaderPartXml, 'word/header1.xml has no image.');
$this->assertNotContains('${footerValue}', $expectedFooterPartXml, 'word/footer1.xml has no image.'); $this->assertStringNotContainsString('${footerValue}', $expectedFooterPartXml, 'word/footer1.xml has no image.');
$this->assertContains('media/image_rId11_document.jpeg', $expectedDocumentRelationsXml, 'word/_rels/document.xml.rels missed "media/image5_document.jpeg"'); $this->assertStringContainsString('media/image_rId11_document.jpeg', $expectedDocumentRelationsXml, 'word/_rels/document.xml.rels missed "media/image5_document.jpeg"');
$this->assertContains('media/image_rId11_document.jpeg', $expectedHeaderRelationsXml, 'word/_rels/header1.xml.rels missed "media/image5_document.jpeg"'); $this->assertStringContainsString('media/image_rId11_document.jpeg', $expectedHeaderRelationsXml, 'word/_rels/header1.xml.rels missed "media/image5_document.jpeg"');
$this->assertContains('media/image_rId11_document.jpeg', $expectedFooterRelationsXml, 'word/_rels/footer1.xml.rels missed "media/image5_document.jpeg"'); $this->assertStringContainsString('media/image_rId11_document.jpeg', $expectedFooterRelationsXml, 'word/_rels/footer1.xml.rels missed "media/image5_document.jpeg"');
unlink($docName); unlink($docName);
@ -463,7 +463,7 @@ final class TemplateProcessorTest extends \PHPUnit\Framework\TestCase
} }
unlink($resultFileName); unlink($resultFileName);
$this->assertNotContains('${Test}', $expectedMainPartXml, 'word/document.xml has no image.'); $this->assertStringNotContainsString('${Test}', $expectedMainPartXml, 'word/document.xml has no image.');
} }
/** /**
@ -640,9 +640,9 @@ final class TemplateProcessorTest extends \PHPUnit\Framework\TestCase
$templateProcessor = new TestableTemplateProcesor($mainPart); $templateProcessor = new TestableTemplateProcesor($mainPart);
$templateProcessor->cloneBlock('CLONEME', 3, true, true); $templateProcessor->cloneBlock('CLONEME', 3, true, true);
$this->assertContains('Address ${address#1}, Street ${street#1}', $templateProcessor->getMainPart()); $this->assertStringContainsString('Address ${address#1}, Street ${street#1}', $templateProcessor->getMainPart());
$this->assertContains('Address ${address#2}, Street ${street#2}', $templateProcessor->getMainPart()); $this->assertStringContainsString('Address ${address#2}, Street ${street#2}', $templateProcessor->getMainPart());
$this->assertContains('Address ${address#3}, Street ${street#3}', $templateProcessor->getMainPart()); $this->assertStringContainsString('Address ${address#3}, Street ${street#3}', $templateProcessor->getMainPart());
} }
public function testCloneBlockWithVariableReplacements() public function testCloneBlockWithVariableReplacements()
@ -673,9 +673,9 @@ final class TemplateProcessorTest extends \PHPUnit\Framework\TestCase
$templateProcessor = new TestableTemplateProcesor($mainPart); $templateProcessor = new TestableTemplateProcesor($mainPart);
$templateProcessor->cloneBlock('CLONEME', 0, true, false, $replacements); $templateProcessor->cloneBlock('CLONEME', 0, true, false, $replacements);
$this->assertContains('City: London, Street: Baker Street', $templateProcessor->getMainPart()); $this->assertStringContainsString('City: London, Street: Baker Street', $templateProcessor->getMainPart());
$this->assertContains('City: New York, Street: 5th Avenue', $templateProcessor->getMainPart()); $this->assertStringContainsString('City: New York, Street: 5th Avenue', $templateProcessor->getMainPart());
$this->assertContains('City: Rome, Street: Via della Conciliazione', $templateProcessor->getMainPart()); $this->assertStringContainsString('City: Rome, Street: Via della Conciliazione', $templateProcessor->getMainPart());
} }
/** /**
@ -846,9 +846,9 @@ final class TemplateProcessorTest extends \PHPUnit\Framework\TestCase
$templateProcessor = new TestableTemplateProcesor(null, $settingsPart); $templateProcessor = new TestableTemplateProcesor(null, $settingsPart);
$templateProcessor->setUpdateFields(true); $templateProcessor->setUpdateFields(true);
$this->assertContains('<w:updateFields w:val="true"/>', $templateProcessor->getSettingsPart()); $this->assertStringContainsString('<w:updateFields w:val="true"/>', $templateProcessor->getSettingsPart());
$templateProcessor->setUpdateFields(false); $templateProcessor->setUpdateFields(false);
$this->assertContains('<w:updateFields w:val="false"/>', $templateProcessor->getSettingsPart()); $this->assertStringContainsString('<w:updateFields w:val="false"/>', $templateProcessor->getSettingsPart());
} }
} }

View File

@ -160,7 +160,7 @@ class ElementTest extends \PHPUnit\Framework\TestCase
$htmlWriter = new HTML($phpWord); $htmlWriter = new HTML($phpWord);
$content = $htmlWriter->getContent(); $content = $htmlWriter->getContent();
$this->assertContains($expected, $content); $this->assertStringContainsString($expected, $content);
} }
/** /**

View File

@ -26,11 +26,10 @@ class PartTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* Test get parent writer exception * Test get parent writer exception
*
* @expectedException \PhpOffice\PhpWord\Exception\Exception
*/ */
public function testGetParentWriterException() public function testGetParentWriterException()
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\Exception::class);
$object = new Body(); $object = new Body();
$object->getParentWriter(); $object->getParentWriter();
} }

View File

@ -41,12 +41,11 @@ class HTMLTest extends AbstractWebServerEmbeddedTest
/** /**
* Construct with null * Construct with null
*
* @expectedException \PhpOffice\PhpWord\Exception\Exception
* @expectedExceptionMessage No PhpWord assigned.
*/ */
public function testConstructWithNull() public function testConstructWithNull()
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\Exception::class);
$this->expectExceptionMessage('No PhpWord assigned.');
$object = new HTML(); $object = new HTML();
$object->getPhpWord(); $object->getPhpWord();
} }

View File

@ -30,7 +30,7 @@ class ImageTest extends \PHPUnit\Framework\TestCase
/** /**
* Executed after each method of the class * Executed after each method of the class
*/ */
public function tearDown() public function tearDown(): void
{ {
TestHelperDOCX::clear(); TestHelperDOCX::clear();
} }

View File

@ -30,7 +30,7 @@ class ElementTest extends \PHPUnit\Framework\TestCase
/** /**
* Executed after each method of the class * Executed after each method of the class
*/ */
public function tearDown() public function tearDown(): void
{ {
TestHelperDOCX::clear(); TestHelperDOCX::clear();
} }

View File

@ -39,12 +39,11 @@ class AbstractPartTest extends \PHPUnit\Framework\TestCase
/** /**
* covers ::getParentWriter * covers ::getParentWriter
*
* @expectedException \Exception
* @expectedExceptionMessage No parent WriterInterface assigned.
*/ */
public function testSetGetParentWriterNull() public function testSetGetParentWriterNull()
{ {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('No parent WriterInterface assigned.');
$object = $this->getMockForAbstractClass('PhpOffice\\PhpWord\\Writer\\ODText\\Part\\AbstractPart'); $object = $this->getMockForAbstractClass('PhpOffice\\PhpWord\\Writer\\ODText\\Part\\AbstractPart');
$object->getParentWriter(); $object->getParentWriter();
} }

View File

@ -31,7 +31,7 @@ class ContentTest extends \PHPUnit\Framework\TestCase
/** /**
* Executed before each method of the class * Executed before each method of the class
*/ */
public function tearDown() public function tearDown(): void
{ {
TestHelperDOCX::clear(); TestHelperDOCX::clear();
} }

View File

@ -28,7 +28,7 @@ class FontTest extends \PHPUnit\Framework\TestCase
/** /**
* Executed after each method of the class * Executed after each method of the class
*/ */
public function tearDown() public function tearDown(): void
{ {
TestHelperDOCX::clear(); TestHelperDOCX::clear();
} }

View File

@ -29,7 +29,7 @@ class ParagraphTest extends \PHPUnit\Framework\TestCase
/** /**
* Executed after each method of the class * Executed after each method of the class
*/ */
public function tearDown() public function tearDown(): void
{ {
TestHelperDOCX::clear(); TestHelperDOCX::clear();
} }

View File

@ -28,7 +28,7 @@ class SectionTest extends \PHPUnit\Framework\TestCase
/** /**
* Executed after each method of the class * Executed after each method of the class
*/ */
public function tearDown() public function tearDown(): void
{ {
TestHelperDOCX::clear(); TestHelperDOCX::clear();
} }

View File

@ -51,12 +51,11 @@ class ODTextTest extends \PHPUnit\Framework\TestCase
/** /**
* Construct with null * Construct with null
*
* @expectedException \PhpOffice\PhpWord\Exception\Exception
* @expectedExceptionMessage No PhpWord assigned.
*/ */
public function testConstructWithNull() public function testConstructWithNull()
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\Exception::class);
$this->expectExceptionMessage('No PhpWord assigned.');
$object = new ODText(); $object = new ODText();
$object->getPhpWord(); $object->getPhpWord();
} }
@ -135,11 +134,10 @@ class ODTextTest extends \PHPUnit\Framework\TestCase
/** /**
* Use disk caching exception * Use disk caching exception
*
* @expectedException \PhpOffice\PhpWord\Exception\Exception
*/ */
public function testSetUseDiskCachingException() public function testSetUseDiskCachingException()
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\Exception::class);
$dir = implode(DIRECTORY_SEPARATOR, array(PHPWORD_TESTS_BASE_DIR, 'foo')); $dir = implode(DIRECTORY_SEPARATOR, array(PHPWORD_TESTS_BASE_DIR, 'foo'));
$object = new ODText(); $object = new ODText();

View File

@ -48,12 +48,11 @@ class PDFTest extends \PHPUnit\Framework\TestCase
/** /**
* Test construct exception * Test construct exception
*
* @expectedException \PhpOffice\PhpWord\Exception\Exception
* @expectedExceptionMessage PDF rendering library or library path has not been defined.
*/ */
public function testConstructException() public function testConstructException()
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\Exception::class);
$this->expectExceptionMessage('PDF rendering library or library path has not been defined.');
$writer = new PDF(new PhpWord()); $writer = new PDF(new PhpWord());
$writer->save(); $writer->save();
} }

View File

@ -39,12 +39,11 @@ class RTFTest extends \PHPUnit\Framework\TestCase
/** /**
* Construct with null * Construct with null
*
* @expectedException \PhpOffice\PhpWord\Exception\Exception
* @expectedExceptionMessage No PhpWord assigned.
*/ */
public function testConstructWithNull() public function testConstructWithNull()
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\Exception::class);
$this->expectExceptionMessage('No PhpWord assigned.');
$object = new RTF(); $object = new RTF();
$object->getPhpWord(); $object->getPhpWord();
} }

View File

@ -31,7 +31,7 @@ class ChartTest extends \PHPUnit\Framework\TestCase
/** /**
* Executed before each method of the class * Executed before each method of the class
*/ */
public function setUp() public function setUp(): void
{ {
$this->outputEscapingEnabled = Settings::isOutputEscapingEnabled(); $this->outputEscapingEnabled = Settings::isOutputEscapingEnabled();
} }
@ -39,7 +39,7 @@ class ChartTest extends \PHPUnit\Framework\TestCase
/** /**
* Executed after each method of the class * Executed after each method of the class
*/ */
public function tearDown() public function tearDown(): void
{ {
Settings::setOutputEscapingEnabled($this->outputEscapingEnabled); Settings::setOutputEscapingEnabled($this->outputEscapingEnabled);
TestHelperDOCX::clear(); TestHelperDOCX::clear();

View File

@ -28,7 +28,7 @@ class FormFieldTest extends \PHPUnit\Framework\TestCase
/** /**
* Executed before each method of the class * Executed before each method of the class
*/ */
public function tearDown() public function tearDown(): void
{ {
TestHelperDOCX::clear(); TestHelperDOCX::clear();
} }

View File

@ -32,7 +32,7 @@ class ElementTest extends \PHPUnit\Framework\TestCase
/** /**
* Executed before each method of the class * Executed before each method of the class
*/ */
public function tearDown() public function tearDown(): void
{ {
TestHelperDOCX::clear(); TestHelperDOCX::clear();
} }

View File

@ -40,12 +40,11 @@ class AbstractPartTest extends \PHPUnit\Framework\TestCase
/** /**
* covers ::getParentWriter * covers ::getParentWriter
*
* @expectedException \Exception
* @expectedExceptionMessage No parent WriterInterface assigned.
*/ */
public function testSetGetParentWriterNull() public function testSetGetParentWriterNull()
{ {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('No parent WriterInterface assigned.');
$object = $this->getMockForAbstractClass('PhpOffice\\PhpWord\\Writer\\Word2007\\Part\\AbstractPart'); $object = $this->getMockForAbstractClass('PhpOffice\\PhpWord\\Writer\\Word2007\\Part\\AbstractPart');
$object->getParentWriter(); $object->getParentWriter();
} }

View File

@ -30,7 +30,7 @@ class CommentsTest extends \PHPUnit\Framework\TestCase
/** /**
* Executed before each method of the class * Executed before each method of the class
*/ */
public function tearDown() public function tearDown(): void
{ {
TestHelperDOCX::clear(); TestHelperDOCX::clear();
} }

View File

@ -36,7 +36,7 @@ class DocumentTest extends \PHPUnit\Framework\TestCase
/** /**
* Executed before each method of the class * Executed before each method of the class
*/ */
public function tearDown() public function tearDown(): void
{ {
TestHelperDOCX::clear(); TestHelperDOCX::clear();
} }
@ -407,7 +407,7 @@ class DocumentTest extends \PHPUnit\Framework\TestCase
// behind // behind
$element = $doc->getElement('/w:document/w:body/w:p[2]/w:r/w:pict/v:shape'); $element = $doc->getElement('/w:document/w:body/w:p[2]/w:r/w:pict/v:shape');
$style = $element->getAttribute('style'); $style = $element->getAttribute('style');
$this->assertRegExp('/z\-index:\-[0-9]*/', $style); $this->assertMatchesRegularExpression('/z\-index:\-[0-9]*/', $style);
// square // square
$element = $doc->getElement('/w:document/w:body/w:p[4]/w:r/w:pict/v:shape/w10:wrap'); $element = $doc->getElement('/w:document/w:body/w:p[4]/w:r/w:pict/v:shape/w10:wrap');

View File

@ -27,7 +27,7 @@ use PhpOffice\PhpWord\TestHelperDOCX;
*/ */
class FootnotesTest extends \PHPUnit\Framework\TestCase class FootnotesTest extends \PHPUnit\Framework\TestCase
{ {
public function tearDown() public function tearDown(): void
{ {
TestHelperDOCX::clear(); TestHelperDOCX::clear();
} }

View File

@ -34,7 +34,7 @@ class NumberingTest extends \PHPUnit\Framework\TestCase
/** /**
* Executed before each method of the class * Executed before each method of the class
*/ */
public function tearDown() public function tearDown(): void
{ {
TestHelperDOCX::clear(); TestHelperDOCX::clear();
} }

View File

@ -35,7 +35,7 @@ class SettingsTest extends \PHPUnit\Framework\TestCase
/** /**
* Executed before each method of the class * Executed before each method of the class
*/ */
public function tearDown() public function tearDown(): void
{ {
TestHelperDOCX::clear(); TestHelperDOCX::clear();
} }

View File

@ -34,7 +34,7 @@ class StylesTest extends \PHPUnit\Framework\TestCase
/** /**
* Executed before each method of the class * Executed before each method of the class
*/ */
public function tearDown() public function tearDown(): void
{ {
TestHelperDOCX::clear(); TestHelperDOCX::clear();
} }

View File

@ -30,11 +30,11 @@ class PartTest extends \PHPUnit\Framework\TestCase
* Test exception when no type or target assigned to a relation * Test exception when no type or target assigned to a relation
* *
* @covers \PhpOffice\PhpWord\Writer\Word2007\Part\Rels::writeRel * @covers \PhpOffice\PhpWord\Writer\Word2007\Part\Rels::writeRel
* @expectedException \PhpOffice\PhpWord\Exception\Exception
* @expectedExceptionMessage Invalid parameters passed.
*/ */
public function testRelsWriteRelException() public function testRelsWriteRelException()
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\Exception::class);
$this->expectExceptionMessage('Invalid parameters passed.');
$object = new RelsPart(); $object = new RelsPart();
$object->setMedia(array(array('type' => '', 'target' => ''))); $object->setMedia(array(array('type' => '', 'target' => '')));
$object->write(); $object->write();

View File

@ -30,7 +30,7 @@ class FontTest extends \PHPUnit\Framework\TestCase
/** /**
* Executed before each method of the class * Executed before each method of the class
*/ */
public function tearDown() public function tearDown(): void
{ {
TestHelperDOCX::clear(); TestHelperDOCX::clear();
} }

View File

@ -31,7 +31,7 @@ class ImageTest extends \PHPUnit\Framework\TestCase
/** /**
* Executed before each method of the class * Executed before each method of the class
*/ */
public function tearDown() public function tearDown(): void
{ {
TestHelperDOCX::clear(); TestHelperDOCX::clear();
} }
@ -63,10 +63,10 @@ class ImageTest extends \PHPUnit\Framework\TestCase
$this->assertTrue($doc->elementExists($path)); $this->assertTrue($doc->elementExists($path));
$style = $doc->getElement($path)->getAttribute('style'); $style = $doc->getElement($path)->getAttribute('style');
$this->assertNotNull($style); $this->assertNotNull($style);
$this->assertContains('mso-wrap-distance-left:10pt;', $style); $this->assertStringContainsString('mso-wrap-distance-left:10pt;', $style);
$this->assertContains('mso-wrap-distance-right:20pt;', $style); $this->assertStringContainsString('mso-wrap-distance-right:20pt;', $style);
$this->assertContains('mso-wrap-distance-top:30pt;', $style); $this->assertStringContainsString('mso-wrap-distance-top:30pt;', $style);
$this->assertContains('mso-wrap-distance-bottom:40pt;', $style); $this->assertStringContainsString('mso-wrap-distance-bottom:40pt;', $style);
} }
/** /**
@ -97,9 +97,9 @@ class ImageTest extends \PHPUnit\Framework\TestCase
$this->assertTrue($doc->elementExists($path)); $this->assertTrue($doc->elementExists($path));
$style = $doc->getElement($path)->getAttribute('style'); $style = $doc->getElement($path)->getAttribute('style');
$this->assertNotNull($style); $this->assertNotNull($style);
$this->assertContains('mso-wrap-distance-left:10pt;', $style); $this->assertStringContainsString('mso-wrap-distance-left:10pt;', $style);
$this->assertContains('mso-wrap-distance-right:20pt;', $style); $this->assertStringContainsString('mso-wrap-distance-right:20pt;', $style);
$this->assertContains('mso-wrap-distance-top:30pt;', $style); $this->assertStringContainsString('mso-wrap-distance-top:30pt;', $style);
$this->assertContains('mso-wrap-distance-bottom:40pt;', $style); $this->assertStringContainsString('mso-wrap-distance-bottom:40pt;', $style);
} }
} }

View File

@ -31,7 +31,7 @@ class ParagraphTest extends \PHPUnit\Framework\TestCase
/** /**
* Executed before each method of the class * Executed before each method of the class
*/ */
public function tearDown() public function tearDown(): void
{ {
TestHelperDOCX::clear(); TestHelperDOCX::clear();
} }

View File

@ -31,7 +31,7 @@ class SectionTest extends \PHPUnit\Framework\TestCase
/** /**
* Executed before each method of the class * Executed before each method of the class
*/ */
public function tearDown() public function tearDown(): void
{ {
TestHelperDOCX::clear(); TestHelperDOCX::clear();
} }

View File

@ -34,7 +34,7 @@ class TableTest extends \PHPUnit\Framework\TestCase
/** /**
* Executed before each method of the class * Executed before each method of the class
*/ */
public function tearDown() public function tearDown(): void
{ {
TestHelperDOCX::clear(); TestHelperDOCX::clear();
} }

View File

@ -32,7 +32,7 @@ class Word2007Test extends AbstractWebServerEmbeddedTest
/** /**
* Tear down after each test * Tear down after each test
*/ */
public function tearDown() public function tearDown(): void
{ {
TestHelperDOCX::clear(); TestHelperDOCX::clear();
} }
@ -182,11 +182,10 @@ class Word2007Test extends AbstractWebServerEmbeddedTest
/** /**
* Use disk caching exception * Use disk caching exception
*
* @expectedException \PhpOffice\PhpWord\Exception\Exception
*/ */
public function testSetUseDiskCachingException() public function testSetUseDiskCachingException()
{ {
$this->expectException(\PhpOffice\PhpWord\Exception\Exception::class);
$dir = implode(DIRECTORY_SEPARATOR, array(PHPWORD_TESTS_BASE_DIR, 'foo')); $dir = implode(DIRECTORY_SEPARATOR, array(PHPWORD_TESTS_BASE_DIR, 'foo'));
$object = new Word2007(); $object = new Word2007();

View File

@ -23,7 +23,7 @@ abstract class AbstractWebServerEmbeddedTest extends \PHPUnit\Framework\TestCase
{ {
private static $httpServer; private static $httpServer;
public static function setUpBeforeClass() public static function setUpBeforeClass(): void
{ {
$commandLine = 'php -S localhost:8080 -t tests/PhpWord/_files'; $commandLine = 'php -S localhost:8080 -t tests/PhpWord/_files';
@ -34,7 +34,7 @@ abstract class AbstractWebServerEmbeddedTest extends \PHPUnit\Framework\TestCase
} }
} }
public static function tearDownAfterClass() public static function tearDownAfterClass(): void
{ {
self::$httpServer->stop(); self::$httpServer->stop();
} }

View File

@ -76,7 +76,7 @@ class TestHelperDOCX
*/ */
public static function clear() public static function clear()
{ {
if (file_exists(self::$file)) { if (self::$file && file_exists(self::$file)) {
unlink(self::$file); unlink(self::$file);
} }
if (is_dir(Settings::getTempDir() . '/PhpWord_Unit_Test/')) { if (is_dir(Settings::getTempDir() . '/PhpWord_Unit_Test/')) {