From 25c56a3e2db957a745a592a4a5c3fb69366f85d7 Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Fri, 16 Sep 2022 11:27:29 +0200 Subject: [PATCH] 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 --- .github/workflows/ci.yml | 24 +-------- composer.json | 22 ++++---- src/PhpWord/Element/PreserveText.php | 2 +- src/PhpWord/Reader/MsDoc.php | 6 +-- src/PhpWord/Settings.php | 2 +- src/PhpWord/Shared/Html.php | 2 +- src/PhpWord/Shared/XMLWriter.php | 4 +- src/PhpWord/Writer/RTF/Element/Title.php | 2 +- src/PhpWord/Writer/RTF/Style/Paragraph.php | 4 +- .../ComplexType/FootnotePropertiesTest.php | 9 ++-- tests/PhpWord/ComplexType/ProofStateTest.php | 6 +-- tests/PhpWord/Element/CellTest.php | 8 ++- tests/PhpWord/Element/CommentTest.php | 10 ++-- tests/PhpWord/Element/FieldTest.php | 20 +++---- tests/PhpWord/Element/FooterTest.php | 2 +- tests/PhpWord/Element/FootnoteTest.php | 2 +- tests/PhpWord/Element/HeaderTest.php | 5 +- tests/PhpWord/Element/ImageTest.php | 12 ++--- tests/PhpWord/Element/ObjectTest.php | 3 +- tests/PhpWord/Element/RowTest.php | 2 +- tests/PhpWord/Element/SDTTest.php | 5 +- tests/PhpWord/Element/SectionTest.php | 6 +-- tests/PhpWord/Element/TitleTest.php | 4 +- .../Exception/CopyFileExceptionTest.php | 2 +- .../CreateTemporaryFileExceptionTest.php | 2 +- tests/PhpWord/Exception/ExceptionTest.php | 2 +- .../Exception/InvalidImageExceptionTest.php | 2 +- .../Exception/InvalidStyleExceptionTest.php | 2 +- .../UnsupportedImageTypeExceptionTest.php | 2 +- tests/PhpWord/IOFactoryTest.php | 6 +-- tests/PhpWord/MediaTest.php | 5 +- tests/PhpWord/Metadata/SettingsTest.php | 10 ++-- tests/PhpWord/PhpWordTest.php | 8 ++- tests/PhpWord/Reader/HTMLTest.php | 5 +- tests/PhpWord/Reader/MsDocTest.php | 4 +- tests/PhpWord/Reader/RTFTest.php | 5 +- tests/PhpWord/SettingsTest.php | 4 +- tests/PhpWord/Shared/ConverterTest.php | 48 ++++++++--------- tests/PhpWord/Shared/DrawingTest.php | 2 +- tests/PhpWord/Shared/HtmlTest.php | 5 +- tests/PhpWord/Shared/XMLReaderTest.php | 6 +-- tests/PhpWord/Style/AbstractStyleTest.php | 3 +- tests/PhpWord/Style/ChartTest.php | 2 +- tests/PhpWord/Style/FontTest.php | 7 ++- tests/PhpWord/Style/ImageTest.php | 3 +- tests/PhpWord/Style/LanguageTest.php | 3 +- tests/PhpWord/Style/PaperTest.php | 10 ++-- tests/PhpWord/Style/ParagraphTest.php | 5 +- tests/PhpWord/Style/SectionTest.php | 20 +++---- tests/PhpWord/Style/TextBoxTest.php | 3 +- tests/PhpWord/TemplateProcessorTest.php | 52 +++++++++---------- tests/PhpWord/Writer/HTML/ElementTest.php | 2 +- tests/PhpWord/Writer/HTML/PartTest.php | 3 +- tests/PhpWord/Writer/HTMLTest.php | 5 +- .../Writer/ODText/Element/ImageTest.php | 2 +- tests/PhpWord/Writer/ODText/ElementTest.php | 2 +- .../Writer/ODText/Part/AbstractPartTest.php | 5 +- .../Writer/ODText/Part/ContentTest.php | 2 +- .../PhpWord/Writer/ODText/Style/FontTest.php | 2 +- .../Writer/ODText/Style/ParagraphTest.php | 2 +- .../Writer/ODText/Style/SectionTest.php | 2 +- tests/PhpWord/Writer/ODTextTest.php | 8 ++- tests/PhpWord/Writer/PDFTest.php | 5 +- tests/PhpWord/Writer/RTFTest.php | 5 +- .../Writer/Word2007/Element/ChartTest.php | 4 +- .../Writer/Word2007/Element/FormFieldTest.php | 2 +- tests/PhpWord/Writer/Word2007/ElementTest.php | 2 +- .../Writer/Word2007/Part/AbstractPartTest.php | 5 +- .../Writer/Word2007/Part/CommentsTest.php | 2 +- .../Writer/Word2007/Part/DocumentTest.php | 4 +- .../Writer/Word2007/Part/FootnotesTest.php | 2 +- .../Writer/Word2007/Part/NumberingTest.php | 2 +- .../Writer/Word2007/Part/SettingsTest.php | 2 +- .../Writer/Word2007/Part/StylesTest.php | 2 +- tests/PhpWord/Writer/Word2007/PartTest.php | 4 +- .../Writer/Word2007/Style/FontTest.php | 2 +- .../Writer/Word2007/Style/ImageTest.php | 18 +++---- .../Writer/Word2007/Style/ParagraphTest.php | 2 +- .../Writer/Word2007/Style/SectionTest.php | 2 +- .../Writer/Word2007/Style/TableTest.php | 2 +- tests/PhpWord/Writer/Word2007Test.php | 5 +- .../AbstractWebServerEmbeddedTest.php | 4 +- tests/PhpWord/_includes/TestHelperDOCX.php | 2 +- 83 files changed, 215 insertions(+), 288 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a8318e33..56b4a86b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,30 +36,8 @@ jobs: key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} 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 - run: composer update --no-progress --prefer-dist --optimize-autoloader ${{ steps.composer-lock.outputs.flags }} - - - 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 + run: composer install --no-progress --prefer-dist --optimize-autoloader - name: Setup problem matchers for PHP run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" diff --git a/composer.json b/composer.json index 4c212072..5dad8507 100644 --- a/composer.json +++ b/composer.json @@ -59,22 +59,24 @@ }, "require": { "php": "^7.4 || ^8.0", + "ext-dom": "*", + "ext-json": "*", "ext-xml": "*", - "laminas/laminas-escaper": "^2.2", + "laminas/laminas-escaper": "^2.10", "symfony/process": "^5.4" }, "require-dev": { "ext-zip": "*", "ext-gd": "*", - "phpunit/phpunit": "^4.8.36 || ^7.0", - "squizlabs/php_codesniffer": "^2.9 || ^3.5", - "friendsofphp/php-cs-fixer": "^2.2", - "phpmd/phpmd": "2.*", - "phploc/phploc": "2.* || 3.* || 4.* || 5.* || 6.* || 7.*", - "dompdf/dompdf":"0.8.* || 1.0.*", - "tecnickcom/tcpdf": "^6.4", - "mpdf/mpdf": "5.7.4 || 6.* || 7.* || 8.*", - "php-coveralls/php-coveralls": "1.1.0 || ^2.0" + "dompdf/dompdf": "^2.0", + "friendsofphp/php-cs-fixer": "^3.11", + "mpdf/mpdf": "^8.1", + "php-coveralls/php-coveralls": "^2.5", + "phploc/phploc": "^7.0", + "phpmd/phpmd": "^2.13", + "phpunit/phpunit": "^9.5", + "squizlabs/php_codesniffer": "^3.7", + "tecnickcom/tcpdf": "^6.5" }, "suggest": { "ext-zip": "Allows writing OOXML and ODF", diff --git a/src/PhpWord/Element/PreserveText.php b/src/PhpWord/Element/PreserveText.php index 803ee4f3..a6210bab 100644 --- a/src/PhpWord/Element/PreserveText.php +++ b/src/PhpWord/Element/PreserveText.php @@ -60,7 +60,7 @@ class PreserveText extends AbstractElement $this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle); $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])) { $this->text = $matches; } diff --git a/src/PhpWord/Reader/MsDoc.php b/src/PhpWord/Reader/MsDoc.php index b4c194ca..3a7967b3 100644 --- a/src/PhpWord/Reader/MsDoc.php +++ b/src/PhpWord/Reader/MsDoc.php @@ -1499,9 +1499,9 @@ class MsDoc extends AbstractReader implements ReaderInterface { $oSprm = new \stdClass(); $oSprm->isPmd = $sprm & 0x01FF; - $oSprm->f = ($sprm / 512) & 0x0001; - $oSprm->sgc = ($sprm / 1024) & 0x0007; - $oSprm->spra = ($sprm / 8192); + $oSprm->f = (int)($sprm / 512) & 0x0001; + $oSprm->sgc = (int)($sprm / 1024) & 0x0007; + $oSprm->spra = (int)($sprm / 8192); return $oSprm; } diff --git a/src/PhpWord/Settings.php b/src/PhpWord/Settings.php index 79663317..457156aa 100644 --- a/src/PhpWord/Settings.php +++ b/src/PhpWord/Settings.php @@ -255,7 +255,7 @@ class Settings */ 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; } self::$pdfRendererPath = $libraryBaseDir; diff --git a/src/PhpWord/Shared/Html.php b/src/PhpWord/Shared/Html.php index f57fb0a9..530074e1 100644 --- a/src/PhpWord/Shared/Html.php +++ b/src/PhpWord/Shared/Html.php @@ -620,7 +620,7 @@ class Html foreach ($properties as $property) { list($cKey, $cValue) = array_pad(explode(':', $property, 2), 2, null); - $cValue = trim($cValue); + $cValue = trim($cValue ?? ''); $cKey = strtolower(trim($cKey)); switch ($cKey) { case 'text-decoration': diff --git a/src/PhpWord/Shared/XMLWriter.php b/src/PhpWord/Shared/XMLWriter.php index 882492e0..4d0afc5e 100644 --- a/src/PhpWord/Shared/XMLWriter.php +++ b/src/PhpWord/Shared/XMLWriter.php @@ -59,7 +59,7 @@ class XMLWriter extends \XMLWriter if ($pTemporaryStorage == self::STORAGE_MEMORY) { $this->openMemory(); } else { - if (!is_dir($pTemporaryStorageDir)) { + if (!$pTemporaryStorageDir || !is_dir($pTemporaryStorageDir)) { $pTemporaryStorageDir = sys_get_temp_dir(); } // Create temporary filename @@ -178,6 +178,6 @@ class XMLWriter extends \XMLWriter $value = json_encode($value); } - return parent::writeAttribute($name, $value); + return parent::writeAttribute($name, $value ?? ''); } } diff --git a/src/PhpWord/Writer/RTF/Element/Title.php b/src/PhpWord/Writer/RTF/Element/Title.php index 77ebff17..7fc6a653 100644 --- a/src/PhpWord/Writer/RTF/Element/Title.php +++ b/src/PhpWord/Writer/RTF/Element/Title.php @@ -29,7 +29,7 @@ class Title extends Text /** @var \PhpOffice\PhpWord\Element\Title $element Type hint */ $element = $this->element; $style = $element->getStyle(); - $style = str_replace('Heading', 'Heading_', $style); + $style = str_replace('Heading', 'Heading_', $style ?? ''); $style = \PhpOffice\PhpWord\Style::getStyle($style); if ($style instanceof \PhpOffice\PhpWord\Style\Font) { $this->fontStyle = $style; diff --git a/src/PhpWord/Writer/RTF/Style/Paragraph.php b/src/PhpWord/Writer/RTF/Style/Paragraph.php index 9f8cf9df..59d4ebaf 100644 --- a/src/PhpWord/Writer/RTF/Style/Paragraph.php +++ b/src/PhpWord/Writer/RTF/Style/Paragraph.php @@ -65,8 +65,8 @@ class Paragraph extends AbstractStyle $content .= $alignments[$style->getAlignment()]; } $content .= $this->writeIndentation($style->getIndentation()); - $content .= $this->getValueIf($spaceBefore !== null, '\sb' . round($spaceBefore)); - $content .= $this->getValueIf($spaceAfter !== null, '\sa' . round($spaceAfter)); + $content .= $this->getValueIf($spaceBefore !== null, '\sb' . round($spaceBefore??0)); + $content .= $this->getValueIf($spaceAfter !== null, '\sa' . round($spaceAfter??0)); $lineHeight = $style->getLineHeight(); if ($lineHeight) { $lineHeightAdjusted = (int) ($lineHeight * 240); diff --git a/tests/PhpWord/ComplexType/FootnotePropertiesTest.php b/tests/PhpWord/ComplexType/FootnotePropertiesTest.php index 4448daf8..e8ca7b3a 100644 --- a/tests/PhpWord/ComplexType/FootnotePropertiesTest.php +++ b/tests/PhpWord/ComplexType/FootnotePropertiesTest.php @@ -46,33 +46,30 @@ class FootnotePropertiesTest extends \PHPUnit\Framework\TestCase /** * Test throws exception if wrong position given - * - * @expectedException \InvalidArgumentException */ public function testWrongPos() { + $this->expectException(\InvalidArgumentException::class); $footnoteProp = new FootnoteProperties(); $footnoteProp->setPos(NumberFormat::LOWER_ROMAN); } /** * Test throws exception if wrong number format given - * - * @expectedException \InvalidArgumentException */ public function testWrongNumFmt() { + $this->expectException(\InvalidArgumentException::class); $footnoteProp = new FootnoteProperties(); $footnoteProp->setNumFmt(FootnoteProperties::POSITION_DOC_END); } /** * Test throws exception if wrong number restart given - * - * @expectedException \InvalidArgumentException */ public function testWrongNumRestart() { + $this->expectException(\InvalidArgumentException::class); $footnoteProp = new FootnoteProperties(); $footnoteProp->setNumRestart(NumberFormat::LOWER_ROMAN); } diff --git a/tests/PhpWord/ComplexType/ProofStateTest.php b/tests/PhpWord/ComplexType/ProofStateTest.php index cd1e77f7..ace51803 100644 --- a/tests/PhpWord/ComplexType/ProofStateTest.php +++ b/tests/PhpWord/ComplexType/ProofStateTest.php @@ -39,22 +39,20 @@ class ProofStateTest extends \PHPUnit\Framework\TestCase /** * Test throws exception if wrong grammar proof state value given - * - * @expectedException \InvalidArgumentException */ public function testWrongGrammar() { + $this->expectException(\InvalidArgumentException::class); $pState = new ProofState(); $pState->setGrammar('Wrong'); } /** * Test throws exception if wrong spelling proof state value given - * - * @expectedException \InvalidArgumentException */ public function testWrongSpelling() { + $this->expectException(\InvalidArgumentException::class); $pState = new ProofState(); $pState->setSpelling('Wrong'); } diff --git a/tests/PhpWord/Element/CellTest.php b/tests/PhpWord/Element/CellTest.php index f0d639bc..0cac9bb7 100644 --- a/tests/PhpWord/Element/CellTest.php +++ b/tests/PhpWord/Element/CellTest.php @@ -188,11 +188,10 @@ class CellTest extends AbstractWebServerEmbeddedTest /** * Test add object exception - * - * @expectedException \PhpOffice\PhpWord\Exception\InvalidObjectException */ public function testAddObjectException() { + $this->expectException(\PhpOffice\PhpWord\Exception\InvalidObjectException::class); $src = __DIR__ . '/../_files/xsl/passthrough.xsl'; $oCell = new Cell(); $oCell->addObject($src); @@ -227,11 +226,10 @@ class CellTest extends AbstractWebServerEmbeddedTest /** * Add preserve text exception - * - * @expectedException \BadMethodCallException */ public function testAddPreserveTextException() { + $this->expectException(\BadMethodCallException::class); $oCell = new Cell(); $oCell->setDocPart('TextRun', 1); $oCell->addPreserveText('text'); @@ -268,6 +266,6 @@ class CellTest extends AbstractWebServerEmbeddedTest { $oCell = new Cell(); - $this->assertInternalType('array', $oCell->getElements()); + $this->assertIsArray($oCell->getElements()); } } diff --git a/tests/PhpWord/Element/CommentTest.php b/tests/PhpWord/Element/CommentTest.php index b9c3dfce..eea944d5 100644 --- a/tests/PhpWord/Element/CommentTest.php +++ b/tests/PhpWord/Element/CommentTest.php @@ -66,7 +66,7 @@ class CommentTest extends \PHPUnit\Framework\TestCase { $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()); } - /** - * @expectedException \InvalidArgumentException - */ public function testExceptionOnCommentStartOnComment() { + $this->expectException(\InvalidArgumentException::class); $dummyComment = new Comment('Test User', new \DateTime(), 'my_initials'); $oComment = new Comment('Test User', new \DateTime(), 'my_initials'); $oComment->setCommentRangeStart($dummyComment); } - /** - * @expectedException \InvalidArgumentException - */ public function testExceptionOnCommentEndOnComment() { + $this->expectException(\InvalidArgumentException::class); $dummyComment = new Comment('Test User', new \DateTime(), 'my_initials'); $oComment = new Comment('Test User', new \DateTime(), 'my_initials'); $oComment->setCommentRangeEnd($dummyComment); diff --git a/tests/PhpWord/Element/FieldTest.php b/tests/PhpWord/Element/FieldTest.php index 1c1c0ca1..df7f8b79 100644 --- a/tests/PhpWord/Element/FieldTest.php +++ b/tests/PhpWord/Element/FieldTest.php @@ -113,48 +113,44 @@ class FieldTest extends \PHPUnit\Framework\TestCase /** * Test setType exception - * - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid type */ public function testSetTypeException() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid type'); $object = new Field(); $object->setType('foo'); } /** * Test setProperties exception - * - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid property */ public function testSetPropertiesException() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid property'); $object = new Field('PAGE'); $object->setProperties(array('foo' => 'bar')); } /** * Test setOptions exception - * - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid option */ public function testSetOptionsException() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid option'); $object = new Field('PAGE'); $object->setOptions(array('foo' => 'bar')); } /** * Test setText exception - * - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid text */ public function testSetTextException() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid text'); $object = new Field('XE'); $object->setText(array()); } diff --git a/tests/PhpWord/Element/FooterTest.php b/tests/PhpWord/Element/FooterTest.php index b1ef4677..360a9005 100644 --- a/tests/PhpWord/Element/FooterTest.php +++ b/tests/PhpWord/Element/FooterTest.php @@ -156,7 +156,7 @@ class FooterTest extends AbstractWebServerEmbeddedTest { $oFooter = new Footer(1); - $this->assertInternalType('array', $oFooter->getElements()); + $this->assertIsArray($oFooter->getElements()); } /** diff --git a/tests/PhpWord/Element/FootnoteTest.php b/tests/PhpWord/Element/FootnoteTest.php index 4ea330f5..86ee0143 100644 --- a/tests/PhpWord/Element/FootnoteTest.php +++ b/tests/PhpWord/Element/FootnoteTest.php @@ -112,6 +112,6 @@ class FootnoteTest extends \PHPUnit\Framework\TestCase public function testGetElements() { $oFootnote = new Footnote(); - $this->assertInternalType('array', $oFootnote->getElements()); + $this->assertIsArray($oFootnote->getElements()); } } diff --git a/tests/PhpWord/Element/HeaderTest.php b/tests/PhpWord/Element/HeaderTest.php index 4bbf7b74..3b97f887 100644 --- a/tests/PhpWord/Element/HeaderTest.php +++ b/tests/PhpWord/Element/HeaderTest.php @@ -178,7 +178,7 @@ class HeaderTest extends AbstractWebServerEmbeddedTest { $oHeader = new Header(1); - $this->assertInternalType('array', $oHeader->getElements()); + $this->assertIsArray($oHeader->getElements()); } /** @@ -229,11 +229,10 @@ class HeaderTest extends AbstractWebServerEmbeddedTest /** * Add footnote exception - * - * @expectedException \BadMethodCallException */ public function testAddFootnoteException() { + $this->expectException(\BadMethodCallException::class); $header = new Header(1); $header->addFootnote(); } diff --git a/tests/PhpWord/Element/ImageTest.php b/tests/PhpWord/Element/ImageTest.php index e83be708..da3bdca2 100644 --- a/tests/PhpWord/Element/ImageTest.php +++ b/tests/PhpWord/Element/ImageTest.php @@ -108,32 +108,29 @@ class ImageTest extends AbstractWebServerEmbeddedTest /** * Test invalid local image - * - * @expectedException \PhpOffice\PhpWord\Exception\InvalidImageException */ public function testInvalidImageLocal() { + $this->expectException(\PhpOffice\PhpWord\Exception\InvalidImageException::class); new Image(__DIR__ . '/../_files/images/thisisnotarealimage'); } /** * Test invalid PHP Image - * - * @expectedException \PhpOffice\PhpWord\Exception\InvalidImageException */ public function testInvalidImagePhp() { + $this->expectException(\PhpOffice\PhpWord\Exception\InvalidImageException::class); $object = new Image('test.php'); $object->getSource(); } /** * Test unsupported image - * - * @expectedException \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException */ 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!!! $arrContextOptions = array( 'ssl' => array( @@ -236,11 +233,10 @@ class ImageTest extends AbstractWebServerEmbeddedTest /** * Test invalid string image - * - * @expectedException \PhpOffice\PhpWord\Exception\InvalidImageException */ public function testInvalidImageString() { + $this->expectException(\PhpOffice\PhpWord\Exception\InvalidImageException::class); $object = new Image('this_is-a_non_valid_image'); $object->getSource(); } diff --git a/tests/PhpWord/Element/ObjectTest.php b/tests/PhpWord/Element/ObjectTest.php index 9fbe1bb5..3a763708 100644 --- a/tests/PhpWord/Element/ObjectTest.php +++ b/tests/PhpWord/Element/ObjectTest.php @@ -53,11 +53,10 @@ class ObjectTest extends \PHPUnit\Framework\TestCase /** * Create new instance with non-supported files - * - * @expectedException \PhpOffice\PhpWord\Exception\InvalidObjectException */ public function testConstructWithNotSupportedFiles() { + $this->expectException(\PhpOffice\PhpWord\Exception\InvalidObjectException::class); $src = __DIR__ . '/../_files/xsl/passthrough.xsl'; $oObject = new OLEObject($src); $oObject->getSource(); diff --git a/tests/PhpWord/Element/RowTest.php b/tests/PhpWord/Element/RowTest.php index 3c534502..01c39981 100644 --- a/tests/PhpWord/Element/RowTest.php +++ b/tests/PhpWord/Element/RowTest.php @@ -34,7 +34,7 @@ class RowTest extends \PHPUnit\Framework\TestCase $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Row', $oRow); $this->assertNull($oRow->getHeight()); - $this->assertInternalType('array', $oRow->getCells()); + $this->assertIsArray($oRow->getCells()); $this->assertCount(0, $oRow->getCells()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Row', $oRow->getStyle()); } diff --git a/tests/PhpWord/Element/SDTTest.php b/tests/PhpWord/Element/SDTTest.php index 2328dd76..d969eb77 100644 --- a/tests/PhpWord/Element/SDTTest.php +++ b/tests/PhpWord/Element/SDTTest.php @@ -50,12 +50,11 @@ class SDTTest extends \PHPUnit\Framework\TestCase /** * Test set type exception - * - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid style value */ public function testSetTypeException() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid style value'); $object = new SDT('comboBox'); $object->setType('foo'); } diff --git a/tests/PhpWord/Element/SectionTest.php b/tests/PhpWord/Element/SectionTest.php index 83d1214e..f49d2ba2 100644 --- a/tests/PhpWord/Element/SectionTest.php +++ b/tests/PhpWord/Element/SectionTest.php @@ -109,10 +109,10 @@ class SectionTest extends \PHPUnit\Framework\TestCase /** * @coversNothing - * @expectedException \PhpOffice\PhpWord\Exception\InvalidObjectException */ public function testAddObjectException() { + $this->expectException(\PhpOffice\PhpWord\Exception\InvalidObjectException::class); $source = __DIR__ . '/_files/xsl/passthrough.xsl'; $section = new Section(0); $section->addObject($source); @@ -176,11 +176,11 @@ class SectionTest extends \PHPUnit\Framework\TestCase /** * @covers ::addHeader - * @expectedException \Exception - * @expectedExceptionMessage Invalid header/footer type. */ public function testAddHeaderException() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Invalid header/footer type.'); $object = new Section(1); $object->addHeader('ODD'); } diff --git a/tests/PhpWord/Element/TitleTest.php b/tests/PhpWord/Element/TitleTest.php index 6ef87c3e..53d3f2ab 100644 --- a/tests/PhpWord/Element/TitleTest.php +++ b/tests/PhpWord/Element/TitleTest.php @@ -58,11 +58,9 @@ class TitleTest extends \PHPUnit\Framework\TestCase $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\TextRun', $oTitle->getText()); } - /** - * @expectedException \InvalidArgumentException - */ public function testConstructWithInvalidArgument() { + $this->expectException(\InvalidArgumentException::class); $oPageBreak = new PageBreak(); new Title($oPageBreak); } diff --git a/tests/PhpWord/Exception/CopyFileExceptionTest.php b/tests/PhpWord/Exception/CopyFileExceptionTest.php index 5fed9c9f..1a69e4de 100644 --- a/tests/PhpWord/Exception/CopyFileExceptionTest.php +++ b/tests/PhpWord/Exception/CopyFileExceptionTest.php @@ -27,11 +27,11 @@ class CopyFileExceptionTest extends \PHPUnit\Framework\TestCase * CopyFileException can be thrown. * * @covers ::__construct() - * @expectedException \PhpOffice\PhpWord\Exception\CopyFileException * @test */ public function testCopyFileExceptionCanBeThrown() { + $this->expectException(\PhpOffice\PhpWord\Exception\CopyFileException::class); throw new CopyFileException('C:\source\dummy.txt', 'C:\destination\dummy.txt'); } } diff --git a/tests/PhpWord/Exception/CreateTemporaryFileExceptionTest.php b/tests/PhpWord/Exception/CreateTemporaryFileExceptionTest.php index f879285e..f5bd5f4e 100644 --- a/tests/PhpWord/Exception/CreateTemporaryFileExceptionTest.php +++ b/tests/PhpWord/Exception/CreateTemporaryFileExceptionTest.php @@ -27,11 +27,11 @@ class CreateTemporaryFileExceptionTest extends \PHPUnit\Framework\TestCase * CreateTemporaryFileException can be thrown. * * @covers ::__construct() - * @expectedException \PhpOffice\PhpWord\Exception\CreateTemporaryFileException * @test */ public function testCreateTemporaryFileExceptionCanBeThrown() { + $this->expectException(\PhpOffice\PhpWord\Exception\CreateTemporaryFileException::class); throw new CreateTemporaryFileException(); } } diff --git a/tests/PhpWord/Exception/ExceptionTest.php b/tests/PhpWord/Exception/ExceptionTest.php index 8c7bce57..4d4e20d1 100644 --- a/tests/PhpWord/Exception/ExceptionTest.php +++ b/tests/PhpWord/Exception/ExceptionTest.php @@ -28,11 +28,11 @@ class ExceptionTest extends \PHPUnit\Framework\TestCase /** * Throw new exception * - * @expectedException \PhpOffice\PhpWord\Exception\Exception * @covers \PhpOffice\PhpWord\Exception\Exception */ public function testThrowException() { + $this->expectException(\PhpOffice\PhpWord\Exception\Exception::class); throw new Exception(); } } diff --git a/tests/PhpWord/Exception/InvalidImageExceptionTest.php b/tests/PhpWord/Exception/InvalidImageExceptionTest.php index 71da1aa9..e150747a 100644 --- a/tests/PhpWord/Exception/InvalidImageExceptionTest.php +++ b/tests/PhpWord/Exception/InvalidImageExceptionTest.php @@ -28,11 +28,11 @@ class InvalidImageExceptionTest extends \PHPUnit\Framework\TestCase /** * Throw new exception * - * @expectedException \PhpOffice\PhpWord\Exception\InvalidImageException * @covers \PhpOffice\PhpWord\Exception\InvalidImageException */ public function testThrowException() { + $this->expectException(\PhpOffice\PhpWord\Exception\InvalidImageException::class); throw new InvalidImageException(); } } diff --git a/tests/PhpWord/Exception/InvalidStyleExceptionTest.php b/tests/PhpWord/Exception/InvalidStyleExceptionTest.php index 1d981449..b8386803 100644 --- a/tests/PhpWord/Exception/InvalidStyleExceptionTest.php +++ b/tests/PhpWord/Exception/InvalidStyleExceptionTest.php @@ -28,11 +28,11 @@ class InvalidStyleExceptionTest extends \PHPUnit\Framework\TestCase /** * Throw new exception * - * @expectedException \PhpOffice\PhpWord\Exception\InvalidStyleException * @covers \PhpOffice\PhpWord\Exception\InvalidStyleException */ public function testThrowException() { + $this->expectException(\PhpOffice\PhpWord\Exception\InvalidStyleException::class); throw new InvalidStyleException(); } } diff --git a/tests/PhpWord/Exception/UnsupportedImageTypeExceptionTest.php b/tests/PhpWord/Exception/UnsupportedImageTypeExceptionTest.php index 5b03f5e3..add8a1ca 100644 --- a/tests/PhpWord/Exception/UnsupportedImageTypeExceptionTest.php +++ b/tests/PhpWord/Exception/UnsupportedImageTypeExceptionTest.php @@ -28,11 +28,11 @@ class UnsupportedImageTypeExceptionTest extends \PHPUnit\Framework\TestCase /** * Throw new exception * - * @expectedException \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException * @covers \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException */ public function testThrowException() { + $this->expectException(\PhpOffice\PhpWord\Exception\UnsupportedImageTypeException::class); throw new UnsupportedImageTypeException(); } } diff --git a/tests/PhpWord/IOFactoryTest.php b/tests/PhpWord/IOFactoryTest.php index 4a59e702..f286dcc6 100644 --- a/tests/PhpWord/IOFactoryTest.php +++ b/tests/PhpWord/IOFactoryTest.php @@ -37,11 +37,10 @@ class IOFactoryTest extends \PHPUnit\Framework\TestCase /** * Create non-existing writer - * - * @expectedException \PhpOffice\PhpWord\Exception\Exception */ public function testNonexistentWriterCanNotBeCreated() { + $this->expectException(\PhpOffice\PhpWord\Exception\Exception::class); IOFactory::createWriter(new PhpWord(), 'Word2006'); } @@ -58,11 +57,10 @@ class IOFactoryTest extends \PHPUnit\Framework\TestCase /** * Create non-existing reader - * - * @expectedException \PhpOffice\PhpWord\Exception\Exception */ public function testNonexistentReaderCanNotBeCreated() { + $this->expectException(\PhpOffice\PhpWord\Exception\Exception::class); IOFactory::createReader('Word2006'); } diff --git a/tests/PhpWord/MediaTest.php b/tests/PhpWord/MediaTest.php index cca413f5..de42e91c 100644 --- a/tests/PhpWord/MediaTest.php +++ b/tests/PhpWord/MediaTest.php @@ -121,12 +121,11 @@ class MediaTest extends AbstractWebServerEmbeddedTest /** * Add image element exception - * - * @expectedException \Exception - * @expectedExceptionMessage Image object not assigned. */ public function testAddElementImageException() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Image object not assigned.'); Media::addElement('section', 'image', __DIR__ . '/_files/images/mars.jpg'); } } diff --git a/tests/PhpWord/Metadata/SettingsTest.php b/tests/PhpWord/Metadata/SettingsTest.php index 9670f1d9..12be752c 100644 --- a/tests/PhpWord/Metadata/SettingsTest.php +++ b/tests/PhpWord/Metadata/SettingsTest.php @@ -71,10 +71,10 @@ class SettingsTest extends \PHPUnit\Framework\TestCase /** * Test setting an invalid salt - * @expectedException \InvalidArgumentException */ public function testInvalidSalt() { + $this->expectException(\InvalidArgumentException::class); $protection = new Protection(); $protection->setSalt('123'); } @@ -125,20 +125,16 @@ class SettingsTest extends \PHPUnit\Framework\TestCase $this->assertEquals(ProofState::DIRTY, $oSettings->getProofState()->getSpelling()); } - /** - * @expectedException \InvalidArgumentException - */ public function testWrongProofStateGrammar() { + $this->expectException(\InvalidArgumentException::class); $proofState = new ProofState(); $proofState->setGrammar('wrong'); } - /** - * @expectedException \InvalidArgumentException - */ public function testWrongProofStateSpelling() { + $this->expectException(\InvalidArgumentException::class); $proofState = new ProofState(); $proofState->setSpelling('wrong'); } diff --git a/tests/PhpWord/PhpWordTest.php b/tests/PhpWord/PhpWordTest.php index 4acd0fe6..09081334 100644 --- a/tests/PhpWord/PhpWordTest.php +++ b/tests/PhpWord/PhpWordTest.php @@ -133,11 +133,10 @@ class PhpWordTest extends \PHPUnit\Framework\TestCase * Test load template exception * * @deprecated 0.12.0 - * - * @expectedException \PhpOffice\PhpWord\Exception\Exception */ public function testLoadTemplateException() { + $this->expectException(\PhpOffice\PhpWord\Exception\Exception::class); $templateFqfn = implode( DIRECTORY_SEPARATOR, 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 - * - * @expectedException \BadMethodCallException - * @expectedExceptionMessage is not defined */ public function testCallUndefinedMethod() { + $this->expectException(\BadMethodCallException::class); + $this->expectExceptionMessage('is not defined'); $phpWord = new PhpWord(); $phpWord->undefinedMethod(); } diff --git a/tests/PhpWord/Reader/HTMLTest.php b/tests/PhpWord/Reader/HTMLTest.php index 38588afc..f903198d 100644 --- a/tests/PhpWord/Reader/HTMLTest.php +++ b/tests/PhpWord/Reader/HTMLTest.php @@ -39,12 +39,11 @@ class HTMLTest extends \PHPUnit\Framework\TestCase /** * Test load exception - * - * @expectedException \Exception - * @expectedExceptionMessage Cannot read */ public function testLoadException() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Cannot read'); $filename = __DIR__ . '/../_files/documents/foo.html'; IOFactory::load($filename, 'HTML'); } diff --git a/tests/PhpWord/Reader/MsDocTest.php b/tests/PhpWord/Reader/MsDocTest.php index 3ce39939..63bebef2 100644 --- a/tests/PhpWord/Reader/MsDocTest.php +++ b/tests/PhpWord/Reader/MsDocTest.php @@ -59,20 +59,20 @@ class MsDocTest extends \PHPUnit\Framework\TestCase /** * Test exception on not existing file - * @expectedException \Exception */ public function testFailIfFileNotReadable() { + $this->expectException(\Exception::class); $filename = __DIR__ . '/../_files/documents/not_existing_reader.doc'; IOFactory::load($filename, 'MsDoc'); } /** * Test exception on non OLE document - * @expectedException \Exception */ public function testFailIfFileNotOle() { + $this->expectException(\Exception::class); $filename = __DIR__ . '/../_files/documents/reader.odt'; IOFactory::load($filename, 'MsDoc'); } diff --git a/tests/PhpWord/Reader/RTFTest.php b/tests/PhpWord/Reader/RTFTest.php index fed00ceb..387dd911 100644 --- a/tests/PhpWord/Reader/RTFTest.php +++ b/tests/PhpWord/Reader/RTFTest.php @@ -39,12 +39,11 @@ class RTFTest extends \PHPUnit\Framework\TestCase /** * Test load exception - * - * @expectedException \Exception - * @expectedExceptionMessage Cannot read */ public function testLoadException() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Cannot read'); $filename = __DIR__ . '/../_files/documents/foo.rtf'; IOFactory::load($filename, 'RTF'); } diff --git a/tests/PhpWord/SettingsTest.php b/tests/PhpWord/SettingsTest.php index 748ec71b..ce072c75 100644 --- a/tests/PhpWord/SettingsTest.php +++ b/tests/PhpWord/SettingsTest.php @@ -36,7 +36,7 @@ class SettingsTest extends \PHPUnit\Framework\TestCase private $tempDir; private $zipClass; - public function setUp() + public function setUp(): void { $this->compatibility = Settings::hasCompatibility(); $this->defaultFontSize = Settings::getDefaultFontSize(); @@ -50,7 +50,7 @@ class SettingsTest extends \PHPUnit\Framework\TestCase $this->zipClass = Settings::getZipClass(); } - public function tearDown() + public function tearDown(): void { Settings::setCompatibility($this->compatibility); Settings::setDefaultFontSize($this->defaultFontSize); diff --git a/tests/PhpWord/Shared/ConverterTest.php b/tests/PhpWord/Shared/ConverterTest.php index 82bcaf84..f6c0479e 100644 --- a/tests/PhpWord/Shared/ConverterTest.php +++ b/tests/PhpWord/Shared/ConverterTest.php @@ -36,70 +36,70 @@ class ConverterTest extends \PHPUnit\Framework\TestCase foreach ($values as $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); - $this->assertEquals($value / 2.54, $result, '', 0.00001); + $this->assertEqualsWithDelta($value / 2.54, $result, 0.00001); $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); - $this->assertEquals($value / 2.54 * 72, $result, '', 0.00001); + $this->assertEqualsWithDelta($value / 2.54 * 72, $result, 0.00001); $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); - $this->assertEquals($value * 1440, $result, '', 0.00001); + $this->assertEqualsWithDelta($value * 1440, $result, 0.00001); $result = Converter::inchToCm($value); - $this->assertEquals($value * 2.54, $result, '', 0.00001); + $this->assertEqualsWithDelta($value * 2.54, $result, 0.00001); $result = Converter::inchToPixel($value); - $this->assertEquals($value * 96, $result, '', 0.00001); + $this->assertEqualsWithDelta($value * 96, $result, 0.00001); $result = Converter::inchToPoint($value); - $this->assertEquals($value * 72, $result, '', 0.00001); + $this->assertEqualsWithDelta($value * 72, $result, 0.00001); $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); - $this->assertEquals($value / 96 * 1440, $result, '', 0.00001); + $this->assertEqualsWithDelta($value / 96 * 1440, $result, 0.00001); $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); - $this->assertEquals($value / 96 * 72, $result, '', 0.00001); + $this->assertEqualsWithDelta($value / 96 * 72, $result, 0.00001); $result = Converter::pixelToEmu($value); - $this->assertEquals(round($value * 9525), $result, '', 0.00001); + $this->assertEqualsWithDelta(round($value * 9525), $result, 0.00001); $result = Converter::pointToTwip($value); - $this->assertEquals($value * 20, $result, '', 0.00001); + $this->assertEqualsWithDelta($value * 20, $result, 0.00001); $result = Converter::pointToCm($value); - $this->assertEquals($value * 0.035277778, $result, '', 0.00001); + $this->assertEqualsWithDelta($value * 0.035277778, $result, 0.00001); $result = Converter::pointToPixel($value); - $this->assertEquals($value / 72 * 96, $result, '', 0.00001); + $this->assertEqualsWithDelta($value / 72 * 96, $result, 0.00001); $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); - $this->assertEquals(round($value / 9525), $result, '', 0.00001); + $this->assertEqualsWithDelta(round($value / 9525), $result, 0.00001); $result = Converter::picaToPoint($value); - $this->assertEquals($value / 6 * 72, $result, '', 0.00001); + $this->assertEqualsWithDelta($value / 6 * 72, $result, 0.00001); $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); - $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(7.2, Converter::cssToPoint('0.1in')); $this->assertEquals(120, Converter::cssToPoint('10pc')); - $this->assertEquals(28.346457, Converter::cssToPoint('10mm'), '', 0.000001); - $this->assertEquals(283.464567, Converter::cssToPoint('10cm'), '', 0.000001); + $this->assertEqualsWithDelta(28.346457, Converter::cssToPoint('10mm'), 0.000001); + $this->assertEqualsWithDelta(283.464567, Converter::cssToPoint('10cm'), 0.000001); $this->assertEquals(40, Converter::cssToPixel('30pt')); $this->assertEquals(1.27, Converter::cssToCm('36pt')); $this->assertEquals(127000, Converter::cssToEmu('10pt')); diff --git a/tests/PhpWord/Shared/DrawingTest.php b/tests/PhpWord/Shared/DrawingTest.php index b7110923..49f42663 100644 --- a/tests/PhpWord/Shared/DrawingTest.php +++ b/tests/PhpWord/Shared/DrawingTest.php @@ -102,7 +102,7 @@ class DrawingTest extends \PHPUnit\Framework\TestCase $this->assertFalse(Drawing::htmlToRGB('0000')); $this->assertFalse(Drawing::htmlToRGB('00000')); - $this->assertInternalType('array', Drawing::htmlToRGB('ABCDEF')); + $this->assertIsArray(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')); diff --git a/tests/PhpWord/Shared/HtmlTest.php b/tests/PhpWord/Shared/HtmlTest.php index fdf3e37c..20377056 100644 --- a/tests/PhpWord/Shared/HtmlTest.php +++ b/tests/PhpWord/Shared/HtmlTest.php @@ -607,11 +607,10 @@ class HtmlTest extends AbstractWebServerEmbeddedTest /** * Test parsing of remote img that can be found locally - * - * @expectedException \Exception */ public function testCouldNotLoadImage() { + $this->expectException(\Exception::class); $src = 'https://fakedomain.io/images/firefox.png'; $phpWord = new \PhpOffice\PhpWord\PhpWord(); @@ -973,6 +972,6 @@ HTML; Html::addHtml($section, $html); $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007'); - $this->assertInternalType('object', $doc); + $this->assertIsObject($doc); } } diff --git a/tests/PhpWord/Shared/XMLReaderTest.php b/tests/PhpWord/Shared/XMLReaderTest.php index 4d0ee64c..3f6775bb 100644 --- a/tests/PhpWord/Shared/XMLReaderTest.php +++ b/tests/PhpWord/Shared/XMLReaderTest.php @@ -56,11 +56,10 @@ class XMLReaderTest extends \PHPUnit\Framework\TestCase /** * Test that read from non existing archive throws exception - * - * @expectedException \Exception */ public function testThrowsExceptionOnNonExistingArchive() { + $this->expectException(\Exception::class); $archiveFile = __DIR__ . '/../_files/xml/readers.zip'; $reader = new XMLReader(); @@ -123,11 +122,10 @@ class XMLReaderTest extends \PHPUnit\Framework\TestCase /** * Test that xpath fails if custom namespace is not registered - * - * @expectedException \InvalidArgumentException */ public function testShouldThowExceptionIfTryingToRegisterNamespaceBeforeReadingDoc() { + $this->expectException(\InvalidArgumentException::class); $reader = new XMLReader(); $reader->registerNamespace('test', 'http://phpword.com/my/custom/namespace'); } diff --git a/tests/PhpWord/Style/AbstractStyleTest.php b/tests/PhpWord/Style/AbstractStyleTest.php index 7ec272bb..43952cb4 100644 --- a/tests/PhpWord/Style/AbstractStyleTest.php +++ b/tests/PhpWord/Style/AbstractStyleTest.php @@ -64,11 +64,10 @@ class AbstractStyleTest extends \PHPUnit\Framework\TestCase /** * Test setEnumVal exception - * - * @expectedException \InvalidArgumentException */ public function testSetValEnumException() { + $this->expectException(\InvalidArgumentException::class); $stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Style\AbstractStyle'); $this->assertEquals('b', self::callProtectedMethod($stub, 'setEnumVal', array('z', array('a', 'b'), 'b'))); diff --git a/tests/PhpWord/Style/ChartTest.php b/tests/PhpWord/Style/ChartTest.php index 9929a8f5..e23b891e 100644 --- a/tests/PhpWord/Style/ChartTest.php +++ b/tests/PhpWord/Style/ChartTest.php @@ -74,7 +74,7 @@ class ChartTest extends \PHPUnit\Framework\TestCase { $chart = new Chart(); - $this->assertInternalType('array', $chart->getColors()); + $this->assertIsArray($chart->getColors()); $this->assertEquals(count($chart->getColors()), 0); diff --git a/tests/PhpWord/Style/FontTest.php b/tests/PhpWord/Style/FontTest.php index 84916fc2..fa31f070 100644 --- a/tests/PhpWord/Style/FontTest.php +++ b/tests/PhpWord/Style/FontTest.php @@ -31,7 +31,7 @@ class FontTest extends \PHPUnit\Framework\TestCase /** * Tear down after each test */ - public function tearDown() + public function tearDown(): void { TestHelperDOCX::clear(); } @@ -45,7 +45,7 @@ class FontTest extends \PHPUnit\Framework\TestCase $this->assertEquals('text', $object->getStyleType()); $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 - * - * @expectedException \PhpOffice\PhpWord\Exception\InvalidStyleException */ public function testLineHeightException() { + $this->expectException(\PhpOffice\PhpWord\Exception\InvalidStyleException::class); $object = new Font(); $object->setLineHeight('a'); } diff --git a/tests/PhpWord/Style/ImageTest.php b/tests/PhpWord/Style/ImageTest.php index 1d43d921..8e272a6b 100644 --- a/tests/PhpWord/Style/ImageTest.php +++ b/tests/PhpWord/Style/ImageTest.php @@ -87,11 +87,10 @@ class ImageTest extends \PHPUnit\Framework\TestCase /** * Test setWrappingStyle exception - * - * @expectedException \InvalidArgumentException */ public function testSetWrappingStyleException() { + $this->expectException(\InvalidArgumentException::class); $object = new Image(); $object->setWrappingStyle('foo'); } diff --git a/tests/PhpWord/Style/LanguageTest.php b/tests/PhpWord/Style/LanguageTest.php index 3bf516f8..3d8ef0b7 100644 --- a/tests/PhpWord/Style/LanguageTest.php +++ b/tests/PhpWord/Style/LanguageTest.php @@ -53,11 +53,10 @@ class LanguageTest extends \PHPUnit\Framework\TestCase /** * Test throws exception if wrong locale is given - * - * @expectedException \InvalidArgumentException */ public function testWrongLanguage() { + $this->expectException(\InvalidArgumentException::class); $language = new Language(); $language->setLatin('fra'); } diff --git a/tests/PhpWord/Style/PaperTest.php b/tests/PhpWord/Style/PaperTest.php index f8f00701..66b99d6a 100644 --- a/tests/PhpWord/Style/PaperTest.php +++ b/tests/PhpWord/Style/PaperTest.php @@ -29,7 +29,7 @@ class PaperTest extends \PHPUnit\Framework\TestCase /** * Tear down after each test */ - public function tearDown() + public function tearDown(): void { TestHelperDOCX::clear(); } @@ -52,8 +52,8 @@ class PaperTest extends \PHPUnit\Framework\TestCase $object = new Paper('B5'); $this->assertEquals('B5', $object->getSize()); - $this->assertEquals(9977.9527559055, $object->getWidth(), '', 0.000000001); - $this->assertEquals(14173.228346457, $object->getHeight(), '', 0.000000001); + $this->assertEqualsWithDelta(9977.9527559055, $object->getWidth(), 0.000000001); + $this->assertEqualsWithDelta(14173.228346457, $object->getHeight(), 0.000000001); } /** @@ -65,7 +65,7 @@ class PaperTest extends \PHPUnit\Framework\TestCase $object->setSize('Folio'); $this->assertEquals('Folio', $object->getSize()); - $this->assertEquals(12240, $object->getWidth(), '', 0.1); - $this->assertEquals(18720, $object->getHeight(), '', 0.1); + $this->assertEqualsWithDelta(12240, $object->getWidth(), 0.1); + $this->assertEqualsWithDelta(18720, $object->getHeight(), 0.1); } } diff --git a/tests/PhpWord/Style/ParagraphTest.php b/tests/PhpWord/Style/ParagraphTest.php index 4fa0ef5a..d9fd96d6 100644 --- a/tests/PhpWord/Style/ParagraphTest.php +++ b/tests/PhpWord/Style/ParagraphTest.php @@ -31,7 +31,7 @@ class ParagraphTest extends \PHPUnit\Framework\TestCase /** * Tear down after each test */ - public function tearDown() + public function tearDown(): void { TestHelperDOCX::clear(); } @@ -177,11 +177,10 @@ class ParagraphTest extends \PHPUnit\Framework\TestCase /** * Test line height exception by using nonnumeric value - * - * @expectedException \PhpOffice\PhpWord\Exception\InvalidStyleException */ public function testLineHeightException() { + $this->expectException(\PhpOffice\PhpWord\Exception\InvalidStyleException::class); $object = new Paragraph(); $object->setLineHeight('a'); } diff --git a/tests/PhpWord/Style/SectionTest.php b/tests/PhpWord/Style/SectionTest.php index 59d18167..1e974166 100644 --- a/tests/PhpWord/Style/SectionTest.php +++ b/tests/PhpWord/Style/SectionTest.php @@ -35,14 +35,14 @@ class SectionTest extends \PHPUnit\Framework\TestCase $oSettings = new Section(); $this->assertEquals('portrait', $oSettings->getOrientation()); - $this->assertEquals(Section::DEFAULT_WIDTH, $oSettings->getPageSizeW(), '', 0.000000001); - $this->assertEquals(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeH(), '', 0.000000001); + $this->assertEqualsWithDelta(Section::DEFAULT_WIDTH, $oSettings->getPageSizeW(), 0.000000001); + $this->assertEqualsWithDelta(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeH(), 0.000000001); $this->assertEquals('A4', $oSettings->getPaperSize()); $oSettings->setSettingValue('orientation', 'landscape'); $this->assertEquals('landscape', $oSettings->getOrientation()); - $this->assertEquals(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeW(), '', 0.000000001); - $this->assertEquals(Section::DEFAULT_WIDTH, $oSettings->getPageSizeH(), '', 0.000000001); + $this->assertEqualsWithDelta(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeW(), 0.000000001); + $this->assertEqualsWithDelta(Section::DEFAULT_WIDTH, $oSettings->getPageSizeH(), 0.000000001); $iVal = rand(1, 1000); $oSettings->setSettingValue('borderSize', $iVal); @@ -112,7 +112,7 @@ class SectionTest extends \PHPUnit\Framework\TestCase // Section Settings $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); $oSettings->setSettingValue('pageSizeW', $iVal); $this->assertEquals($iVal, $oSettings->getPageSizeW()); @@ -126,7 +126,7 @@ class SectionTest extends \PHPUnit\Framework\TestCase // Section Settings $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); $oSettings->setSettingValue('pageSizeH', $iVal); $this->assertEquals($iVal, $oSettings->getPageSizeH()); @@ -142,8 +142,8 @@ class SectionTest extends \PHPUnit\Framework\TestCase $oSettings->setLandscape(); $this->assertEquals('landscape', $oSettings->getOrientation()); - $this->assertEquals(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeW(), '', 0.000000001); - $this->assertEquals(Section::DEFAULT_WIDTH, $oSettings->getPageSizeH(), '', 0.000000001); + $this->assertEqualsWithDelta(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeW(), 0.000000001); + $this->assertEqualsWithDelta(Section::DEFAULT_WIDTH, $oSettings->getPageSizeH(), 0.000000001); } /** @@ -156,8 +156,8 @@ class SectionTest extends \PHPUnit\Framework\TestCase $oSettings->setPortrait(); $this->assertEquals('portrait', $oSettings->getOrientation()); - $this->assertEquals(Section::DEFAULT_WIDTH, $oSettings->getPageSizeW(), '', 0.000000001); - $this->assertEquals(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeH(), '', 0.000000001); + $this->assertEqualsWithDelta(Section::DEFAULT_WIDTH, $oSettings->getPageSizeW(), 0.000000001); + $this->assertEqualsWithDelta(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeH(), 0.000000001); } /** diff --git a/tests/PhpWord/Style/TextBoxTest.php b/tests/PhpWord/Style/TextBoxTest.php index 803189cd..d583fc24 100644 --- a/tests/PhpWord/Style/TextBoxTest.php +++ b/tests/PhpWord/Style/TextBoxTest.php @@ -96,11 +96,10 @@ class TextBoxTest extends \PHPUnit\Framework\TestCase /** * Test setWrappingStyle exception - * - * @expectedException \InvalidArgumentException */ public function testSetWrappingStyleException() { + $this->expectException(\InvalidArgumentException::class); $object = new TextBox(); $object->setWrappingStyle('foo'); } diff --git a/tests/PhpWord/TemplateProcessorTest.php b/tests/PhpWord/TemplateProcessorTest.php index 391daa2d..13b6148d 100644 --- a/tests/PhpWord/TemplateProcessorTest.php +++ b/tests/PhpWord/TemplateProcessorTest.php @@ -134,12 +134,12 @@ final class TemplateProcessorTest extends \PHPUnit\Framework\TestCase * XSL stylesheet cannot be applied on failure in setting parameter value. * * @covers ::applyXslStyleSheet - * @expectedException \PhpOffice\PhpWord\Exception\Exception - * @expectedExceptionMessage Could not set values for the given XSL style sheet parameters. * @test */ 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. if (\PHP_VERSION_ID >= 80000) { $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. * * @covers ::applyXslStyleSheet - * @expectedException \PhpOffice\PhpWord\Exception\Exception - * @expectedExceptionMessage Could not load the given XML document. * @test */ 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'); $xslDomDocument = new \DOMDocument(); @@ -261,16 +261,16 @@ final class TemplateProcessorTest extends \PHPUnit\Framework\TestCase ); $templateProcessor->setValue('tableHeader', 'My clonable table'); $templateProcessor->cloneRowAndSetValues('userId', $values); - $this->assertContains('Superman', $templateProcessor->getMainPart()); - $this->assertContains('Metropolis', $templateProcessor->getMainPart()); + $this->assertStringContainsString('Superman', $templateProcessor->getMainPart()); + $this->assertStringContainsString('Metropolis', $templateProcessor->getMainPart()); } /** - * @expectedException \Exception * @test */ public function testCloneNotExistingRowShouldThrowException() { + $this->expectException(\Exception::class); $mainPart = 'text'; $templateProcessor = new TestableTemplateProcesor($mainPart); @@ -384,7 +384,7 @@ final class TemplateProcessorTest extends \PHPUnit\Framework\TestCase $templateProcessor = new TestableTemplateProcesor($mainPart); $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->assertContains('/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->assertContains('/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->assertNotContains('${headerValue}', $expectedHeaderPartXml, 'word/header1.xml has no image.'); - $this->assertNotContains('${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->assertContains('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('/word/media/image_rId11_document.jpeg', $expectedContentTypesXml, '[Content_Types].xml missed "/word/media/image5_document.jpeg"'); + $this->assertStringContainsString('/word/_rels/header1.xml.rels', $expectedContentTypesXml, '[Content_Types].xml missed "/word/_rels/header1.xml.rels"'); + $this->assertStringContainsString('/word/_rels/footer1.xml.rels', $expectedContentTypesXml, '[Content_Types].xml missed "/word/_rels/footer1.xml.rels"'); + $this->assertStringNotContainsString('${documentContent}', $expectedMainPartXml, 'word/document.xml has no image.'); + $this->assertStringNotContainsString('${headerValue}', $expectedHeaderPartXml, 'word/header1.xml has no image.'); + $this->assertStringNotContainsString('${footerValue}', $expectedFooterPartXml, 'word/footer1.xml has no image.'); + $this->assertStringContainsString('media/image_rId11_document.jpeg', $expectedDocumentRelationsXml, 'word/_rels/document.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->assertStringContainsString('media/image_rId11_document.jpeg', $expectedFooterRelationsXml, 'word/_rels/footer1.xml.rels missed "media/image5_document.jpeg"'); unlink($docName); @@ -463,7 +463,7 @@ final class TemplateProcessorTest extends \PHPUnit\Framework\TestCase } 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->cloneBlock('CLONEME', 3, true, true); - $this->assertContains('Address ${address#1}, Street ${street#1}', $templateProcessor->getMainPart()); - $this->assertContains('Address ${address#2}, Street ${street#2}', $templateProcessor->getMainPart()); - $this->assertContains('Address ${address#3}, Street ${street#3}', $templateProcessor->getMainPart()); + $this->assertStringContainsString('Address ${address#1}, Street ${street#1}', $templateProcessor->getMainPart()); + $this->assertStringContainsString('Address ${address#2}, Street ${street#2}', $templateProcessor->getMainPart()); + $this->assertStringContainsString('Address ${address#3}, Street ${street#3}', $templateProcessor->getMainPart()); } public function testCloneBlockWithVariableReplacements() @@ -673,9 +673,9 @@ final class TemplateProcessorTest extends \PHPUnit\Framework\TestCase $templateProcessor = new TestableTemplateProcesor($mainPart); $templateProcessor->cloneBlock('CLONEME', 0, true, false, $replacements); - $this->assertContains('City: London, Street: Baker Street', $templateProcessor->getMainPart()); - $this->assertContains('City: New York, Street: 5th Avenue', $templateProcessor->getMainPart()); - $this->assertContains('City: Rome, Street: Via della Conciliazione', $templateProcessor->getMainPart()); + $this->assertStringContainsString('City: London, Street: Baker Street', $templateProcessor->getMainPart()); + $this->assertStringContainsString('City: New York, Street: 5th Avenue', $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->setUpdateFields(true); - $this->assertContains('', $templateProcessor->getSettingsPart()); + $this->assertStringContainsString('', $templateProcessor->getSettingsPart()); $templateProcessor->setUpdateFields(false); - $this->assertContains('', $templateProcessor->getSettingsPart()); + $this->assertStringContainsString('', $templateProcessor->getSettingsPart()); } } diff --git a/tests/PhpWord/Writer/HTML/ElementTest.php b/tests/PhpWord/Writer/HTML/ElementTest.php index 4eb92fe5..b6fde2e5 100644 --- a/tests/PhpWord/Writer/HTML/ElementTest.php +++ b/tests/PhpWord/Writer/HTML/ElementTest.php @@ -160,7 +160,7 @@ class ElementTest extends \PHPUnit\Framework\TestCase $htmlWriter = new HTML($phpWord); $content = $htmlWriter->getContent(); - $this->assertContains($expected, $content); + $this->assertStringContainsString($expected, $content); } /** diff --git a/tests/PhpWord/Writer/HTML/PartTest.php b/tests/PhpWord/Writer/HTML/PartTest.php index f8303414..15bdcaaa 100644 --- a/tests/PhpWord/Writer/HTML/PartTest.php +++ b/tests/PhpWord/Writer/HTML/PartTest.php @@ -26,11 +26,10 @@ class PartTest extends \PHPUnit\Framework\TestCase { /** * Test get parent writer exception - * - * @expectedException \PhpOffice\PhpWord\Exception\Exception */ public function testGetParentWriterException() { + $this->expectException(\PhpOffice\PhpWord\Exception\Exception::class); $object = new Body(); $object->getParentWriter(); } diff --git a/tests/PhpWord/Writer/HTMLTest.php b/tests/PhpWord/Writer/HTMLTest.php index 24a8bca3..c4326ff5 100644 --- a/tests/PhpWord/Writer/HTMLTest.php +++ b/tests/PhpWord/Writer/HTMLTest.php @@ -41,12 +41,11 @@ class HTMLTest extends AbstractWebServerEmbeddedTest /** * Construct with null - * - * @expectedException \PhpOffice\PhpWord\Exception\Exception - * @expectedExceptionMessage No PhpWord assigned. */ public function testConstructWithNull() { + $this->expectException(\PhpOffice\PhpWord\Exception\Exception::class); + $this->expectExceptionMessage('No PhpWord assigned.'); $object = new HTML(); $object->getPhpWord(); } diff --git a/tests/PhpWord/Writer/ODText/Element/ImageTest.php b/tests/PhpWord/Writer/ODText/Element/ImageTest.php index 2e0fdeef..7b9b038d 100644 --- a/tests/PhpWord/Writer/ODText/Element/ImageTest.php +++ b/tests/PhpWord/Writer/ODText/Element/ImageTest.php @@ -30,7 +30,7 @@ class ImageTest extends \PHPUnit\Framework\TestCase /** * Executed after each method of the class */ - public function tearDown() + public function tearDown(): void { TestHelperDOCX::clear(); } diff --git a/tests/PhpWord/Writer/ODText/ElementTest.php b/tests/PhpWord/Writer/ODText/ElementTest.php index 8b827347..5a253561 100644 --- a/tests/PhpWord/Writer/ODText/ElementTest.php +++ b/tests/PhpWord/Writer/ODText/ElementTest.php @@ -30,7 +30,7 @@ class ElementTest extends \PHPUnit\Framework\TestCase /** * Executed after each method of the class */ - public function tearDown() + public function tearDown(): void { TestHelperDOCX::clear(); } diff --git a/tests/PhpWord/Writer/ODText/Part/AbstractPartTest.php b/tests/PhpWord/Writer/ODText/Part/AbstractPartTest.php index 3f0c8129..9208ce68 100644 --- a/tests/PhpWord/Writer/ODText/Part/AbstractPartTest.php +++ b/tests/PhpWord/Writer/ODText/Part/AbstractPartTest.php @@ -39,12 +39,11 @@ class AbstractPartTest extends \PHPUnit\Framework\TestCase /** * covers ::getParentWriter - * - * @expectedException \Exception - * @expectedExceptionMessage No parent WriterInterface assigned. */ public function testSetGetParentWriterNull() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('No parent WriterInterface assigned.'); $object = $this->getMockForAbstractClass('PhpOffice\\PhpWord\\Writer\\ODText\\Part\\AbstractPart'); $object->getParentWriter(); } diff --git a/tests/PhpWord/Writer/ODText/Part/ContentTest.php b/tests/PhpWord/Writer/ODText/Part/ContentTest.php index 55d1a00e..015528d8 100644 --- a/tests/PhpWord/Writer/ODText/Part/ContentTest.php +++ b/tests/PhpWord/Writer/ODText/Part/ContentTest.php @@ -31,7 +31,7 @@ class ContentTest extends \PHPUnit\Framework\TestCase /** * Executed before each method of the class */ - public function tearDown() + public function tearDown(): void { TestHelperDOCX::clear(); } diff --git a/tests/PhpWord/Writer/ODText/Style/FontTest.php b/tests/PhpWord/Writer/ODText/Style/FontTest.php index 22a7151c..92ad107a 100644 --- a/tests/PhpWord/Writer/ODText/Style/FontTest.php +++ b/tests/PhpWord/Writer/ODText/Style/FontTest.php @@ -28,7 +28,7 @@ class FontTest extends \PHPUnit\Framework\TestCase /** * Executed after each method of the class */ - public function tearDown() + public function tearDown(): void { TestHelperDOCX::clear(); } diff --git a/tests/PhpWord/Writer/ODText/Style/ParagraphTest.php b/tests/PhpWord/Writer/ODText/Style/ParagraphTest.php index 9ddb5fe1..f18528a4 100644 --- a/tests/PhpWord/Writer/ODText/Style/ParagraphTest.php +++ b/tests/PhpWord/Writer/ODText/Style/ParagraphTest.php @@ -29,7 +29,7 @@ class ParagraphTest extends \PHPUnit\Framework\TestCase /** * Executed after each method of the class */ - public function tearDown() + public function tearDown(): void { TestHelperDOCX::clear(); } diff --git a/tests/PhpWord/Writer/ODText/Style/SectionTest.php b/tests/PhpWord/Writer/ODText/Style/SectionTest.php index d471c7f0..b93d210a 100644 --- a/tests/PhpWord/Writer/ODText/Style/SectionTest.php +++ b/tests/PhpWord/Writer/ODText/Style/SectionTest.php @@ -28,7 +28,7 @@ class SectionTest extends \PHPUnit\Framework\TestCase /** * Executed after each method of the class */ - public function tearDown() + public function tearDown(): void { TestHelperDOCX::clear(); } diff --git a/tests/PhpWord/Writer/ODTextTest.php b/tests/PhpWord/Writer/ODTextTest.php index a576a68d..f24cd2ab 100644 --- a/tests/PhpWord/Writer/ODTextTest.php +++ b/tests/PhpWord/Writer/ODTextTest.php @@ -51,12 +51,11 @@ class ODTextTest extends \PHPUnit\Framework\TestCase /** * Construct with null - * - * @expectedException \PhpOffice\PhpWord\Exception\Exception - * @expectedExceptionMessage No PhpWord assigned. */ public function testConstructWithNull() { + $this->expectException(\PhpOffice\PhpWord\Exception\Exception::class); + $this->expectExceptionMessage('No PhpWord assigned.'); $object = new ODText(); $object->getPhpWord(); } @@ -135,11 +134,10 @@ class ODTextTest extends \PHPUnit\Framework\TestCase /** * Use disk caching exception - * - * @expectedException \PhpOffice\PhpWord\Exception\Exception */ public function testSetUseDiskCachingException() { + $this->expectException(\PhpOffice\PhpWord\Exception\Exception::class); $dir = implode(DIRECTORY_SEPARATOR, array(PHPWORD_TESTS_BASE_DIR, 'foo')); $object = new ODText(); diff --git a/tests/PhpWord/Writer/PDFTest.php b/tests/PhpWord/Writer/PDFTest.php index f699385c..5eeab099 100644 --- a/tests/PhpWord/Writer/PDFTest.php +++ b/tests/PhpWord/Writer/PDFTest.php @@ -48,12 +48,11 @@ class PDFTest extends \PHPUnit\Framework\TestCase /** * Test construct exception - * - * @expectedException \PhpOffice\PhpWord\Exception\Exception - * @expectedExceptionMessage PDF rendering library or library path has not been defined. */ 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->save(); } diff --git a/tests/PhpWord/Writer/RTFTest.php b/tests/PhpWord/Writer/RTFTest.php index 010720bd..88ede4ad 100644 --- a/tests/PhpWord/Writer/RTFTest.php +++ b/tests/PhpWord/Writer/RTFTest.php @@ -39,12 +39,11 @@ class RTFTest extends \PHPUnit\Framework\TestCase /** * Construct with null - * - * @expectedException \PhpOffice\PhpWord\Exception\Exception - * @expectedExceptionMessage No PhpWord assigned. */ public function testConstructWithNull() { + $this->expectException(\PhpOffice\PhpWord\Exception\Exception::class); + $this->expectExceptionMessage('No PhpWord assigned.'); $object = new RTF(); $object->getPhpWord(); } diff --git a/tests/PhpWord/Writer/Word2007/Element/ChartTest.php b/tests/PhpWord/Writer/Word2007/Element/ChartTest.php index a69838a9..26bc0bab 100644 --- a/tests/PhpWord/Writer/Word2007/Element/ChartTest.php +++ b/tests/PhpWord/Writer/Word2007/Element/ChartTest.php @@ -31,7 +31,7 @@ class ChartTest extends \PHPUnit\Framework\TestCase /** * Executed before each method of the class */ - public function setUp() + public function setUp(): void { $this->outputEscapingEnabled = Settings::isOutputEscapingEnabled(); } @@ -39,7 +39,7 @@ class ChartTest extends \PHPUnit\Framework\TestCase /** * Executed after each method of the class */ - public function tearDown() + public function tearDown(): void { Settings::setOutputEscapingEnabled($this->outputEscapingEnabled); TestHelperDOCX::clear(); diff --git a/tests/PhpWord/Writer/Word2007/Element/FormFieldTest.php b/tests/PhpWord/Writer/Word2007/Element/FormFieldTest.php index f3ee1790..bc2077b5 100644 --- a/tests/PhpWord/Writer/Word2007/Element/FormFieldTest.php +++ b/tests/PhpWord/Writer/Word2007/Element/FormFieldTest.php @@ -28,7 +28,7 @@ class FormFieldTest extends \PHPUnit\Framework\TestCase /** * Executed before each method of the class */ - public function tearDown() + public function tearDown(): void { TestHelperDOCX::clear(); } diff --git a/tests/PhpWord/Writer/Word2007/ElementTest.php b/tests/PhpWord/Writer/Word2007/ElementTest.php index 38b1ba75..db6b9a13 100644 --- a/tests/PhpWord/Writer/Word2007/ElementTest.php +++ b/tests/PhpWord/Writer/Word2007/ElementTest.php @@ -32,7 +32,7 @@ class ElementTest extends \PHPUnit\Framework\TestCase /** * Executed before each method of the class */ - public function tearDown() + public function tearDown(): void { TestHelperDOCX::clear(); } diff --git a/tests/PhpWord/Writer/Word2007/Part/AbstractPartTest.php b/tests/PhpWord/Writer/Word2007/Part/AbstractPartTest.php index fac94882..39340017 100644 --- a/tests/PhpWord/Writer/Word2007/Part/AbstractPartTest.php +++ b/tests/PhpWord/Writer/Word2007/Part/AbstractPartTest.php @@ -40,12 +40,11 @@ class AbstractPartTest extends \PHPUnit\Framework\TestCase /** * covers ::getParentWriter - * - * @expectedException \Exception - * @expectedExceptionMessage No parent WriterInterface assigned. */ public function testSetGetParentWriterNull() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('No parent WriterInterface assigned.'); $object = $this->getMockForAbstractClass('PhpOffice\\PhpWord\\Writer\\Word2007\\Part\\AbstractPart'); $object->getParentWriter(); } diff --git a/tests/PhpWord/Writer/Word2007/Part/CommentsTest.php b/tests/PhpWord/Writer/Word2007/Part/CommentsTest.php index 0233abdf..8ecf6abd 100644 --- a/tests/PhpWord/Writer/Word2007/Part/CommentsTest.php +++ b/tests/PhpWord/Writer/Word2007/Part/CommentsTest.php @@ -30,7 +30,7 @@ class CommentsTest extends \PHPUnit\Framework\TestCase /** * Executed before each method of the class */ - public function tearDown() + public function tearDown(): void { TestHelperDOCX::clear(); } diff --git a/tests/PhpWord/Writer/Word2007/Part/DocumentTest.php b/tests/PhpWord/Writer/Word2007/Part/DocumentTest.php index b35f9327..07161d81 100644 --- a/tests/PhpWord/Writer/Word2007/Part/DocumentTest.php +++ b/tests/PhpWord/Writer/Word2007/Part/DocumentTest.php @@ -36,7 +36,7 @@ class DocumentTest extends \PHPUnit\Framework\TestCase /** * Executed before each method of the class */ - public function tearDown() + public function tearDown(): void { TestHelperDOCX::clear(); } @@ -407,7 +407,7 @@ class DocumentTest extends \PHPUnit\Framework\TestCase // behind $element = $doc->getElement('/w:document/w:body/w:p[2]/w:r/w:pict/v:shape'); $style = $element->getAttribute('style'); - $this->assertRegExp('/z\-index:\-[0-9]*/', $style); + $this->assertMatchesRegularExpression('/z\-index:\-[0-9]*/', $style); // square $element = $doc->getElement('/w:document/w:body/w:p[4]/w:r/w:pict/v:shape/w10:wrap'); diff --git a/tests/PhpWord/Writer/Word2007/Part/FootnotesTest.php b/tests/PhpWord/Writer/Word2007/Part/FootnotesTest.php index 4b0e94df..8c6404ed 100644 --- a/tests/PhpWord/Writer/Word2007/Part/FootnotesTest.php +++ b/tests/PhpWord/Writer/Word2007/Part/FootnotesTest.php @@ -27,7 +27,7 @@ use PhpOffice\PhpWord\TestHelperDOCX; */ class FootnotesTest extends \PHPUnit\Framework\TestCase { - public function tearDown() + public function tearDown(): void { TestHelperDOCX::clear(); } diff --git a/tests/PhpWord/Writer/Word2007/Part/NumberingTest.php b/tests/PhpWord/Writer/Word2007/Part/NumberingTest.php index fb5a220e..914d3fa1 100644 --- a/tests/PhpWord/Writer/Word2007/Part/NumberingTest.php +++ b/tests/PhpWord/Writer/Word2007/Part/NumberingTest.php @@ -34,7 +34,7 @@ class NumberingTest extends \PHPUnit\Framework\TestCase /** * Executed before each method of the class */ - public function tearDown() + public function tearDown(): void { TestHelperDOCX::clear(); } diff --git a/tests/PhpWord/Writer/Word2007/Part/SettingsTest.php b/tests/PhpWord/Writer/Word2007/Part/SettingsTest.php index d3c1c1dd..045976e5 100644 --- a/tests/PhpWord/Writer/Word2007/Part/SettingsTest.php +++ b/tests/PhpWord/Writer/Word2007/Part/SettingsTest.php @@ -35,7 +35,7 @@ class SettingsTest extends \PHPUnit\Framework\TestCase /** * Executed before each method of the class */ - public function tearDown() + public function tearDown(): void { TestHelperDOCX::clear(); } diff --git a/tests/PhpWord/Writer/Word2007/Part/StylesTest.php b/tests/PhpWord/Writer/Word2007/Part/StylesTest.php index 91f37184..763f5468 100644 --- a/tests/PhpWord/Writer/Word2007/Part/StylesTest.php +++ b/tests/PhpWord/Writer/Word2007/Part/StylesTest.php @@ -34,7 +34,7 @@ class StylesTest extends \PHPUnit\Framework\TestCase /** * Executed before each method of the class */ - public function tearDown() + public function tearDown(): void { TestHelperDOCX::clear(); } diff --git a/tests/PhpWord/Writer/Word2007/PartTest.php b/tests/PhpWord/Writer/Word2007/PartTest.php index 277f61e1..771b6d82 100644 --- a/tests/PhpWord/Writer/Word2007/PartTest.php +++ b/tests/PhpWord/Writer/Word2007/PartTest.php @@ -30,11 +30,11 @@ class PartTest extends \PHPUnit\Framework\TestCase * Test exception when no type or target assigned to a relation * * @covers \PhpOffice\PhpWord\Writer\Word2007\Part\Rels::writeRel - * @expectedException \PhpOffice\PhpWord\Exception\Exception - * @expectedExceptionMessage Invalid parameters passed. */ public function testRelsWriteRelException() { + $this->expectException(\PhpOffice\PhpWord\Exception\Exception::class); + $this->expectExceptionMessage('Invalid parameters passed.'); $object = new RelsPart(); $object->setMedia(array(array('type' => '', 'target' => ''))); $object->write(); diff --git a/tests/PhpWord/Writer/Word2007/Style/FontTest.php b/tests/PhpWord/Writer/Word2007/Style/FontTest.php index 41e52ab0..ae44d943 100644 --- a/tests/PhpWord/Writer/Word2007/Style/FontTest.php +++ b/tests/PhpWord/Writer/Word2007/Style/FontTest.php @@ -30,7 +30,7 @@ class FontTest extends \PHPUnit\Framework\TestCase /** * Executed before each method of the class */ - public function tearDown() + public function tearDown(): void { TestHelperDOCX::clear(); } diff --git a/tests/PhpWord/Writer/Word2007/Style/ImageTest.php b/tests/PhpWord/Writer/Word2007/Style/ImageTest.php index c2cbfcae..efeb0f27 100644 --- a/tests/PhpWord/Writer/Word2007/Style/ImageTest.php +++ b/tests/PhpWord/Writer/Word2007/Style/ImageTest.php @@ -31,7 +31,7 @@ class ImageTest extends \PHPUnit\Framework\TestCase /** * Executed before each method of the class */ - public function tearDown() + public function tearDown(): void { TestHelperDOCX::clear(); } @@ -63,10 +63,10 @@ class ImageTest extends \PHPUnit\Framework\TestCase $this->assertTrue($doc->elementExists($path)); $style = $doc->getElement($path)->getAttribute('style'); $this->assertNotNull($style); - $this->assertContains('mso-wrap-distance-left:10pt;', $style); - $this->assertContains('mso-wrap-distance-right:20pt;', $style); - $this->assertContains('mso-wrap-distance-top:30pt;', $style); - $this->assertContains('mso-wrap-distance-bottom:40pt;', $style); + $this->assertStringContainsString('mso-wrap-distance-left:10pt;', $style); + $this->assertStringContainsString('mso-wrap-distance-right:20pt;', $style); + $this->assertStringContainsString('mso-wrap-distance-top:30pt;', $style); + $this->assertStringContainsString('mso-wrap-distance-bottom:40pt;', $style); } /** @@ -97,9 +97,9 @@ class ImageTest extends \PHPUnit\Framework\TestCase $this->assertTrue($doc->elementExists($path)); $style = $doc->getElement($path)->getAttribute('style'); $this->assertNotNull($style); - $this->assertContains('mso-wrap-distance-left:10pt;', $style); - $this->assertContains('mso-wrap-distance-right:20pt;', $style); - $this->assertContains('mso-wrap-distance-top:30pt;', $style); - $this->assertContains('mso-wrap-distance-bottom:40pt;', $style); + $this->assertStringContainsString('mso-wrap-distance-left:10pt;', $style); + $this->assertStringContainsString('mso-wrap-distance-right:20pt;', $style); + $this->assertStringContainsString('mso-wrap-distance-top:30pt;', $style); + $this->assertStringContainsString('mso-wrap-distance-bottom:40pt;', $style); } } diff --git a/tests/PhpWord/Writer/Word2007/Style/ParagraphTest.php b/tests/PhpWord/Writer/Word2007/Style/ParagraphTest.php index 843f9880..119f997f 100644 --- a/tests/PhpWord/Writer/Word2007/Style/ParagraphTest.php +++ b/tests/PhpWord/Writer/Word2007/Style/ParagraphTest.php @@ -31,7 +31,7 @@ class ParagraphTest extends \PHPUnit\Framework\TestCase /** * Executed before each method of the class */ - public function tearDown() + public function tearDown(): void { TestHelperDOCX::clear(); } diff --git a/tests/PhpWord/Writer/Word2007/Style/SectionTest.php b/tests/PhpWord/Writer/Word2007/Style/SectionTest.php index 74e1eadd..d4909a9d 100644 --- a/tests/PhpWord/Writer/Word2007/Style/SectionTest.php +++ b/tests/PhpWord/Writer/Word2007/Style/SectionTest.php @@ -31,7 +31,7 @@ class SectionTest extends \PHPUnit\Framework\TestCase /** * Executed before each method of the class */ - public function tearDown() + public function tearDown(): void { TestHelperDOCX::clear(); } diff --git a/tests/PhpWord/Writer/Word2007/Style/TableTest.php b/tests/PhpWord/Writer/Word2007/Style/TableTest.php index 8e5cb634..16bb6940 100644 --- a/tests/PhpWord/Writer/Word2007/Style/TableTest.php +++ b/tests/PhpWord/Writer/Word2007/Style/TableTest.php @@ -34,7 +34,7 @@ class TableTest extends \PHPUnit\Framework\TestCase /** * Executed before each method of the class */ - public function tearDown() + public function tearDown(): void { TestHelperDOCX::clear(); } diff --git a/tests/PhpWord/Writer/Word2007Test.php b/tests/PhpWord/Writer/Word2007Test.php index 563475b4..1baf5592 100644 --- a/tests/PhpWord/Writer/Word2007Test.php +++ b/tests/PhpWord/Writer/Word2007Test.php @@ -32,7 +32,7 @@ class Word2007Test extends AbstractWebServerEmbeddedTest /** * Tear down after each test */ - public function tearDown() + public function tearDown(): void { TestHelperDOCX::clear(); } @@ -182,11 +182,10 @@ class Word2007Test extends AbstractWebServerEmbeddedTest /** * Use disk caching exception - * - * @expectedException \PhpOffice\PhpWord\Exception\Exception */ public function testSetUseDiskCachingException() { + $this->expectException(\PhpOffice\PhpWord\Exception\Exception::class); $dir = implode(DIRECTORY_SEPARATOR, array(PHPWORD_TESTS_BASE_DIR, 'foo')); $object = new Word2007(); diff --git a/tests/PhpWord/_includes/AbstractWebServerEmbeddedTest.php b/tests/PhpWord/_includes/AbstractWebServerEmbeddedTest.php index bb010aa1..38fa493e 100644 --- a/tests/PhpWord/_includes/AbstractWebServerEmbeddedTest.php +++ b/tests/PhpWord/_includes/AbstractWebServerEmbeddedTest.php @@ -23,7 +23,7 @@ abstract class AbstractWebServerEmbeddedTest extends \PHPUnit\Framework\TestCase { private static $httpServer; - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { $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(); } diff --git a/tests/PhpWord/_includes/TestHelperDOCX.php b/tests/PhpWord/_includes/TestHelperDOCX.php index d35f0e3f..1f8e953a 100644 --- a/tests/PhpWord/_includes/TestHelperDOCX.php +++ b/tests/PhpWord/_includes/TestHelperDOCX.php @@ -76,7 +76,7 @@ class TestHelperDOCX */ public static function clear() { - if (file_exists(self::$file)) { + if (self::$file && file_exists(self::$file)) { unlink(self::$file); } if (is_dir(Settings::getTempDir() . '/PhpWord_Unit_Test/')) {