Skip to content

Commit

Permalink
Update all PHP dependencies
Browse files Browse the repository at this point in the history
This way we can share the same dependencies across PHP 7.4 to PHP 8.1,
and simplify our CI pipeline
  • Loading branch information
PowerKiKi committed Sep 16, 2022
1 parent 2074382 commit 25c56a3
Show file tree
Hide file tree
Showing 83 changed files with 215 additions and 288 deletions.
24 changes: 1 addition & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
22 changes: 12 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Element/PreserveText.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct($text = null, $fontStyle = null, $paragraphStyle = n
$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;
}
Expand Down
6 changes: 3 additions & 3 deletions src/PhpWord/Reader/MsDoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1499,9 +1499,9 @@ private function readSprm($sprm)
{
$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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public static function getPdfRendererPath()
*/
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;
Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Shared/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ protected static function parseStyle($attribute, $styles)

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':
Expand Down
4 changes: 2 additions & 2 deletions src/PhpWord/Shared/XMLWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTempora
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
Expand Down Expand Up @@ -178,6 +178,6 @@ public function writeAttribute($name, $value)
$value = json_encode($value);
}

return parent::writeAttribute($name, $value);
return parent::writeAttribute($name, $value ?? '');
}
}
2 changes: 1 addition & 1 deletion src/PhpWord/Writer/RTF/Element/Title.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected function getStyles()
/** @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;
Expand Down
4 changes: 2 additions & 2 deletions src/PhpWord/Writer/RTF/Style/Paragraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public function write()
$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);
Expand Down
9 changes: 3 additions & 6 deletions tests/PhpWord/ComplexType/FootnotePropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,30 @@ public function testSetGetNormal()

/**
* 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);
}
Expand Down
6 changes: 2 additions & 4 deletions tests/PhpWord/ComplexType/ProofStateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,20 @@ public function testGetSet()

/**
* 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');
}
Expand Down
8 changes: 3 additions & 5 deletions tests/PhpWord/Element/CellTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,10 @@ public function testAddObjectXLS()

/**
* 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);
Expand Down Expand Up @@ -227,11 +226,10 @@ public function testAddPreserveTextNotUTF8()

/**
* Add preserve text exception
*
* @expectedException \BadMethodCallException
*/
public function testAddPreserveTextException()
{
$this->expectException(\BadMethodCallException::class);
$oCell = new Cell();
$oCell->setDocPart('TextRun', 1);
$oCell->addPreserveText('text');
Expand Down Expand Up @@ -268,6 +266,6 @@ public function testGetElements()
{
$oCell = new Cell();

$this->assertInternalType('array', $oCell->getElements());
$this->assertIsArray($oCell->getElements());
}
}
10 changes: 3 additions & 7 deletions tests/PhpWord/Element/CommentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function testGetElements()
{
$oComment = new Comment('Test User', new \DateTime(), 'my_initials');

$this->assertInternalType('array', $oComment->getElements());
$this->assertIsArray($oComment->getElements());
}

/**
Expand All @@ -81,21 +81,17 @@ public function testRelationId()
$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);
Expand Down
20 changes: 8 additions & 12 deletions tests/PhpWord/Element/FieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,48 +113,44 @@ public function testConstructWithOptionValue()

/**
* 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());
}
Expand Down
2 changes: 1 addition & 1 deletion tests/PhpWord/Element/FooterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function testGetElements()
{
$oFooter = new Footer(1);

$this->assertInternalType('array', $oFooter->getElements());
$this->assertIsArray($oFooter->getElements());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/PhpWord/Element/FootnoteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@ public function testReferenceId()
public function testGetElements()
{
$oFootnote = new Footnote();
$this->assertInternalType('array', $oFootnote->getElements());
$this->assertIsArray($oFootnote->getElements());
}
}
5 changes: 2 additions & 3 deletions tests/PhpWord/Element/HeaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function testGetElements()
{
$oHeader = new Header(1);

$this->assertInternalType('array', $oHeader->getElements());
$this->assertIsArray($oHeader->getElements());
}

/**
Expand Down Expand Up @@ -229,11 +229,10 @@ public function testEvenPage()

/**
* Add footnote exception
*
* @expectedException \BadMethodCallException
*/
public function testAddFootnoteException()
{
$this->expectException(\BadMethodCallException::class);
$header = new Header(1);
$header->addFootnote();
}
Expand Down
Loading

0 comments on commit 25c56a3

Please sign in to comment.