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') }}
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"

View File

@ -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",

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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':

View File

@ -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 ?? '');
}
}

View File

@ -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;

View File

@ -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);

View File

@ -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);
}

View File

@ -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');
}

View File

@ -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());
}
}

View File

@ -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);

View File

@ -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());
}

View File

@ -156,7 +156,7 @@ class FooterTest extends AbstractWebServerEmbeddedTest
{
$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()
{
$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);
$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();
}

View File

@ -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();
}

View File

@ -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();

View File

@ -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());
}

View File

@ -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');
}

View File

@ -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');
}

View File

@ -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);
}

View File

@ -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');
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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');
}

View File

@ -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');
}
}

View File

@ -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');
}

View File

@ -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();
}

View File

@ -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');
}

View File

@ -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');
}

View File

@ -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');
}

View File

@ -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);

View File

@ -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'));

View File

@ -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'));

View File

@ -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);
}
}

View File

@ -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');
}

View File

@ -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')));

View File

@ -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);

View File

@ -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');
}

View File

@ -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');
}

View File

@ -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');
}

View File

@ -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);
}
}

View File

@ -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');
}

View File

@ -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);
}
/**

View File

@ -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');
}

View File

@ -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('<w:t>Superman</w:t>', $templateProcessor->getMainPart());
$this->assertContains('<w:t>Metropolis</w:t>', $templateProcessor->getMainPart());
$this->assertStringContainsString('<w:t>Superman</w:t>', $templateProcessor->getMainPart());
$this->assertStringContainsString('<w:t>Metropolis</w:t>', $templateProcessor->getMainPart());
}
/**
* @expectedException \Exception
* @test
*/
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>';
$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('<w:updateFields w:val="true"/>', $templateProcessor->getSettingsPart());
$this->assertStringContainsString('<w:updateFields w:val="true"/>', $templateProcessor->getSettingsPart());
$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);
$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
*
* @expectedException \PhpOffice\PhpWord\Exception\Exception
*/
public function testGetParentWriterException()
{
$this->expectException(\PhpOffice\PhpWord\Exception\Exception::class);
$object = new Body();
$object->getParentWriter();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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');

View File

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

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();

View File

@ -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();
}

View File

@ -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);
}
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();

View File

@ -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();
}

View File

@ -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/')) {