fix dependencies to have 7.1 compatible build (#1228)

* add assertions in test methods without assertions
* loosen dependencies so 7.0 & 7.1 builds can succeed
* fix some scrutinizer errors
* update release date
This commit is contained in:
troosan 2017-12-29 02:30:53 +01:00 committed by GitHub
parent fce1bf28c8
commit b614497ae6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 105 additions and 108 deletions

View File

@ -15,7 +15,7 @@ tools:
ruleset: phpmd.xml.dist ruleset: phpmd.xml.dist
external_code_coverage: external_code_coverage:
enabled: true enabled: true
timeout: 900 timeout: 1200
php_cpd: true php_cpd: true
# php_sim: # Temporarily disabled to allow focus on things other than duplicates # php_sim: # Temporarily disabled to allow focus on things other than duplicates
# min_mass: 40 # min_mass: 40

View File

@ -9,14 +9,14 @@ php:
- 5.6 - 5.6
- 7.0 - 7.0
- 7.1 - 7.1
- 7.2
matrix: matrix:
include: include:
- php: 5.6 - php: 5.6
env: COVERAGE=1 env: COVERAGE=1
allow_failures: allow_failures:
- php: 7.0 - php: 7.2
- php: 7.1
cache: cache:
directories: directories:

View File

@ -3,10 +3,10 @@ Change Log
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/). This project adheres to [Semantic Versioning](http://semver.org/).
v0.14.0 (28 Dec 2017) v0.14.0 (29 Dec 2017)
---------------------- ----------------------
This release fixes several bugs and adds some new features. This release fixes several bugs and adds some new features.
This is the last version to support PHP 5.3 This version brings compatibility with PHP 7.0 & 7.1
### Added ### Added
- Possibility to control the footnote numbering - @troosan #1068 - Possibility to control the footnote numbering - @troosan #1068

View File

@ -46,23 +46,22 @@
] ]
}, },
"require": { "require": {
"php": ">=5.3.3", "php": "^5.3.3 || ^7.0",
"ext-xml": "*", "ext-xml": "*",
"zendframework/zend-escaper": "^2.2", "zendframework/zend-escaper": "^2.2",
"zendframework/zend-stdlib": "^2.2 || ^3.0", "zendframework/zend-stdlib": "^2.2 || ^3.0",
"phpoffice/common": "^0.2" "phpoffice/common": "^0.2"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^4.8.36", "phpunit/phpunit": "^4.8.36 || ^5.0",
"phpdocumentor/phpdocumentor":"2.*", "phpdocumentor/phpdocumentor":"2.*",
"twig/twig":"1.27",
"squizlabs/php_codesniffer": "^2.7", "squizlabs/php_codesniffer": "^2.7",
"friendsofphp/php-cs-fixer": "^2.0", "friendsofphp/php-cs-fixer": "^2.0",
"phpmd/phpmd": "2.*", "phpmd/phpmd": "2.*",
"phploc/phploc": "2.*", "phploc/phploc": "2.* || 3.* || 4.*",
"dompdf/dompdf":"0.8.*", "dompdf/dompdf":"0.8.*",
"tecnickcom/tcpdf": "6.*", "tecnickcom/tcpdf": "6.*",
"mpdf/mpdf": "5.*" "mpdf/mpdf": "5.* || 6.* || 7.*"
}, },
"suggest": { "suggest": {
"ext-zip": "Allows writing OOXML and ODF", "ext-zip": "Allows writing OOXML and ODF",

View File

@ -1,28 +1,35 @@
Issue tracker is **ONLY** used for reporting bugs. NO NEW FEATURE ACCEPTED! Use [stackoverflow](https://stackoverflow.com/questions/tagged/phpword) for supporting issues. This is:
- [ ] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpword)
# Expected Behavior # Expected Behavior
Please describe the behavior you are expecting. Please describe the behavior you are expecting.
# Current Behavior ### Current Behavior
What is the current behavior? What is the current behavior?
# Failure Information ### Failure Information
Please help provide information about the failure. Please help provide information about the failure.
## How to Reproduce ### How to Reproduce
Please provide a code sample that reproduces the issue. Please provide a code sample that reproduces the issue.
```php ```php
<?php
require __DIR__ . '/vendor/autoload.php';
$phpWord = new \PhpOffice\PhpWord\PhpWord(); $phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$section->... $section->...
``` ```
## Context ### Context
* PHP version: * PHP version:
* PHPWord version: 0.14 * PHPWord version: 0.14

View File

@ -1,12 +1,11 @@
# Description ### Description
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context.
Fixes # (issue) Fixes # (issue)
# Checklist: ### Checklist:
- [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have run `composer check` and no errors were reported
- [ ] I have run phpunit, phpcs, php-cs-fixer, phpmd
- [ ] The new code is covered by unit tests - [ ] The new code is covered by unit tests
- [ ] I have update the documentation to describe the changes - [ ] I have update the documentation to describe the changes

View File

@ -1,20 +0,0 @@
#!/bin/bash
echo "Running composer update"
composer update
## PHP_CodeSniffer
echo "Running CodeSniffer"
./vendor/bin/phpcs src/ tests/ --standard=PSR2 -n --ignore=src/PhpWord/Shared/PCLZip
## PHP-CS-Fixer
echo "Running CS Fixer"
./vendor/bin/php-cs-fixer fix --diff --verbose --dry-run
## PHP Mess Detector
echo "Running Mess Detector"
./vendor/bin/phpmd src/,tests/ text ./phpmd.xml.dist --exclude pclzip.lib.php
## PHPUnit
echo "Running PHPUnit"
./vendor/bin/phpunit -c ./

View File

@ -228,7 +228,7 @@ abstract class AbstractElement
/** /**
* Get element unique ID * Get element unique ID
* *
* @return int * @return string
*/ */
public function getElementId() public function getElementId()
{ {
@ -425,18 +425,18 @@ abstract class AbstractElement
/** /**
* Set enum value * Set enum value
* *
* @param mixed $value * @param string|null $value
* @param array $enum * @param string[] $enum
* @param mixed $default * @param string|null $default
* *
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @return mixed * @return string|null
* *
* @todo Merge with the same method in AbstractStyle * @todo Merge with the same method in AbstractStyle
*/ */
protected function setEnumVal($value = null, $enum = array(), $default = null) protected function setEnumVal($value = null, $enum = array(), $default = null)
{ {
if ($value != null && trim($value) != '' && !empty($enum) && !in_array($value, $enum)) { if ($value !== null && trim($value) != '' && !empty($enum) && !in_array($value, $enum)) {
throw new \InvalidArgumentException("Invalid style value: {$value}"); throw new \InvalidArgumentException("Invalid style value: {$value}");
} elseif ($value === null || trim($value) == '') { } elseif ($value === null || trim($value) == '') {
$value = $default; $value = $default;

View File

@ -211,7 +211,7 @@ class Field extends AbstractElement
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @return null|string|TextRun * @return null|string|TextRun
*/ */
public function setText($text) public function setText($text = null)
{ {
if (isset($text)) { if (isset($text)) {
if (is_string($text) || $text instanceof TextRun) { if (is_string($text) || $text instanceof TextRun) {

View File

@ -52,8 +52,6 @@ class TrackChange extends AbstractContainer
{ {
$this->author = $author; $this->author = $author;
$this->date = $date; $this->date = $date;
return $this;
} }
/** /**

View File

@ -182,7 +182,7 @@ class Protection
/** /**
* Set salt. Salt HAS to be 16 characters, or an exception will be thrown. * Set salt. Salt HAS to be 16 characters, or an exception will be thrown.
* *
* @param $salt * @param string $salt
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @return self * @return self
*/ */

View File

@ -152,7 +152,7 @@ class Settings extends AbstractPart
$revisionView = new TrackChangesView(); $revisionView = new TrackChangesView();
$revisionView->setMarkup(filter_var($xmlReader->getAttribute('w:markup', $node), FILTER_VALIDATE_BOOLEAN)); $revisionView->setMarkup(filter_var($xmlReader->getAttribute('w:markup', $node), FILTER_VALIDATE_BOOLEAN));
$revisionView->setComments($xmlReader->getAttribute('w:comments', $node)); $revisionView->setComments($xmlReader->getAttribute('w:comments', $node));
$revisionView->setInsDel($xmlReader->getAttribute('w:insDel', $node)); $revisionView->setInsDel(filter_var($xmlReader->getAttribute('w:insDel', $node), FILTER_VALIDATE_BOOLEAN));
$revisionView->setFormatting(filter_var($xmlReader->getAttribute('w:formatting', $node), FILTER_VALIDATE_BOOLEAN)); $revisionView->setFormatting(filter_var($xmlReader->getAttribute('w:formatting', $node), FILTER_VALIDATE_BOOLEAN));
$revisionView->setInkAnnotations(filter_var($xmlReader->getAttribute('w:inkAnnotations', $node), FILTER_VALIDATE_BOOLEAN)); $revisionView->setInkAnnotations(filter_var($xmlReader->getAttribute('w:inkAnnotations', $node), FILTER_VALIDATE_BOOLEAN));
$phpWord->getSettings()->setRevisionView($revisionView); $phpWord->getSettings()->setRevisionView($revisionView);

View File

@ -33,7 +33,7 @@ class Converter
/** /**
* Convert centimeter to twip * Convert centimeter to twip
* *
* @param int $centimeter * @param float $centimeter
* @return float * @return float
*/ */
public static function cmToTwip($centimeter = 1) public static function cmToTwip($centimeter = 1)
@ -44,7 +44,7 @@ class Converter
/** /**
* Convert centimeter to inch * Convert centimeter to inch
* *
* @param int $centimeter * @param float $centimeter
* @return float * @return float
*/ */
public static function cmToInch($centimeter = 1) public static function cmToInch($centimeter = 1)
@ -55,7 +55,7 @@ class Converter
/** /**
* Convert centimeter to pixel * Convert centimeter to pixel
* *
* @param int $centimeter * @param float $centimeter
* @return float * @return float
*/ */
public static function cmToPixel($centimeter = 1) public static function cmToPixel($centimeter = 1)
@ -66,7 +66,7 @@ class Converter
/** /**
* Convert centimeter to point * Convert centimeter to point
* *
* @param int $centimeter * @param float $centimeter
* @return float * @return float
*/ */
public static function cmToPoint($centimeter = 1) public static function cmToPoint($centimeter = 1)
@ -77,8 +77,8 @@ class Converter
/** /**
* Convert centimeter to EMU * Convert centimeter to EMU
* *
* @param int $centimeter * @param float $centimeter
* @return int * @return float
*/ */
public static function cmToEmu($centimeter = 1) public static function cmToEmu($centimeter = 1)
{ {
@ -88,8 +88,8 @@ class Converter
/** /**
* Convert inch to twip * Convert inch to twip
* *
* @param int $inch * @param float $inch
* @return int * @return float
*/ */
public static function inchToTwip($inch = 1) public static function inchToTwip($inch = 1)
{ {
@ -99,7 +99,7 @@ class Converter
/** /**
* Convert inch to centimeter * Convert inch to centimeter
* *
* @param int $inch * @param float $inch
* @return float * @return float
*/ */
public static function inchToCm($inch = 1) public static function inchToCm($inch = 1)
@ -110,8 +110,8 @@ class Converter
/** /**
* Convert inch to pixel * Convert inch to pixel
* *
* @param int $inch * @param float $inch
* @return int * @return float
*/ */
public static function inchToPixel($inch = 1) public static function inchToPixel($inch = 1)
{ {
@ -121,8 +121,8 @@ class Converter
/** /**
* Convert inch to point * Convert inch to point
* *
* @param int $inch * @param float $inch
* @return int * @return float
*/ */
public static function inchToPoint($inch = 1) public static function inchToPoint($inch = 1)
{ {
@ -132,8 +132,8 @@ class Converter
/** /**
* Convert inch to EMU * Convert inch to EMU
* *
* @param int $inch * @param float $inch
* @return int * @return float
*/ */
public static function inchToEmu($inch = 1) public static function inchToEmu($inch = 1)
{ {
@ -144,7 +144,7 @@ class Converter
* Convert pixel to twip * Convert pixel to twip
* *
* @param int $pixel * @param int $pixel
* @return int * @return float
*/ */
public static function pixelToTwip($pixel = 1) public static function pixelToTwip($pixel = 1)
{ {
@ -188,7 +188,7 @@ class Converter
* Convert point to twip unit * Convert point to twip unit
* *
* @param int $point * @param int $point
* @return int * @return float
*/ */
public static function pointToTwip($point = 1) public static function pointToTwip($point = 1)
{ {
@ -210,7 +210,7 @@ class Converter
* Convert point to EMU * Convert point to EMU
* *
* @param int $point * @param int $point
* @return int * @return float
*/ */
public static function pointToEmu($point = 1) public static function pointToEmu($point = 1)
{ {
@ -221,7 +221,7 @@ class Converter
* Convert EMU to pixel * Convert EMU to pixel
* *
* @param int $emu * @param int $emu
* @return int * @return float
*/ */
public static function emuToPixel($emu = 1) public static function emuToPixel($emu = 1)
{ {

View File

@ -518,6 +518,7 @@ class Html
private static function parseImage($node, $element) private static function parseImage($node, $element)
{ {
$style = array(); $style = array();
$src = null;
foreach ($node->attributes as $attribute) { foreach ($node->attributes as $attribute) {
switch ($attribute->name) { switch ($attribute->name) {
case 'src': case 'src':

View File

@ -165,7 +165,7 @@ class PasswordEncoder
/** /**
* Returns the algorithm ID * Returns the algorithm ID
* *
* @param sting $algorithmName * @param string $algorithmName
* @return int * @return int
*/ */
public static function getAlgorithmId($algorithmName) public static function getAlgorithmId($algorithmName)

View File

@ -161,7 +161,7 @@ class ZipArchive
{ {
if (!$this->usePclzip) { if (!$this->usePclzip) {
if ($this->zip->close() === false) { if ($this->zip->close() === false) {
throw new Exception("Could not close zip file {$this->filename}."); throw new Exception("Could not close zip file {$this->filename}: ");
} }
} }

View File

@ -118,14 +118,14 @@ class Paper extends AbstractStyle
/** /**
* Width * Width
* *
* @var int (twip) * @var float (twip)
*/ */
private $width; private $width;
/** /**
* Height * Height
* *
* @var int (twip) * @var float (twip)
*/ */
private $height; private $height;
@ -175,7 +175,7 @@ class Paper extends AbstractStyle
/** /**
* Get width * Get width
* *
* @return int * @return float
*/ */
public function getWidth() public function getWidth()
{ {
@ -185,7 +185,7 @@ class Paper extends AbstractStyle
/** /**
* Get height * Get height
* *
* @return int * @return float
*/ */
public function getHeight() public function getHeight()
{ {

View File

@ -17,6 +17,8 @@
namespace PhpOffice\PhpWord\Writer\PDF; namespace PhpOffice\PhpWord\Writer\PDF;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Writer\WriterInterface; use PhpOffice\PhpWord\Writer\WriterInterface;
/** /**
@ -27,12 +29,14 @@ use PhpOffice\PhpWord\Writer\WriterInterface;
*/ */
class MPDF extends AbstractRenderer implements WriterInterface class MPDF extends AbstractRenderer implements WriterInterface
{ {
/** public function __construct(PhpWord $phpWord)
* Name of renderer include file {
* if (file_exists(Settings::getPdfRendererPath() . '/mpdf.php')) {
* @var string // MPDF version 5.* needs this file to be included, later versions not
*/ $this->includeFile = 'mpdf.php';
protected $includeFile = 'mpdf.php'; }
parent::__construct($phpWord);
}
/** /**
* Save PhpWord to file. * Save PhpWord to file.
@ -48,7 +52,13 @@ class MPDF extends AbstractRenderer implements WriterInterface
$orientation = strtoupper('portrait'); $orientation = strtoupper('portrait');
// Create PDF // Create PDF
if ($this->includeFile != null) {
// MPDF version 5.*
$pdf = new \mpdf(); $pdf = new \mpdf();
} else {
// MPDF version > 6.*
$pdf = new \Mpdf\Mpdf();
}
$pdf->_setPageSize($paperSize, $orientation); $pdf->_setPageSize($paperSize, $orientation);
$pdf->addPage($orientation); $pdf->addPage($orientation);

View File

@ -29,7 +29,7 @@ class Comments extends AbstractPart
/** /**
* Comments collection to be written * Comments collection to be written
* *
* @var \PhpOffice\PhpWord\Collection\Comments * @var \PhpOffice\PhpWord\Element\Comment[]
*/ */
protected $elements; protected $elements;
@ -92,7 +92,7 @@ class Comments extends AbstractPart
/** /**
* Set element * Set element
* *
* @param \PhpOffice\PhpWord\Collection\Comments $elements * @param \PhpOffice\PhpWord\Element\Comment[] $elements
* @return self * @return self
*/ */
public function setElements($elements) public function setElements($elements)

View File

@ -27,34 +27,34 @@ use PhpOffice\PhpWord\Settings;
*/ */
class ZipArchiveTest extends \PHPUnit\Framework\TestCase class ZipArchiveTest extends \PHPUnit\Framework\TestCase
{ {
/** // /**
* Test close method exception: Working in local, not working in Travis // * Test close method exception: Working in local, not working in Travis
* // *
* expectedException \PhpOffice\PhpWord\Exception\Exception // * expectedException \PhpOffice\PhpWord\Exception\Exception
* expectedExceptionMessage Could not close zip file // * expectedExceptionMessage Could not close zip file
* covers ::close // * covers ::close
*/ // */
public function testCloseException() // public function testCloseException()
{ // {
// $zipFile = __DIR__ . "/../_files/documents/ziptest.zip"; // $zipFile = __DIR__ . "/../_files/documents/ziptest.zip";
// $object = new ZipArchive(); // $object = new ZipArchive();
// $object->open($zipFile, ZipArchive::CREATE); // $object->open($zipFile, ZipArchive::CREATE);
// $object->addFromString('content/string.txt', 'Test'); // $object->addFromString('content/string.txt', 'Test');
// // Lock the file // // Lock the file
// $resource = fopen($zipFile, "w"); // $resource = fopen($zipFile, "w");
// flock($resource, LOCK_EX); // flock($resource, LOCK_EX);
// // Closing the file should throws an exception // // Closing the file should throws an exception
// $object->close(); // $object->close();
// // Unlock the file // // Unlock the file
// flock($resource, LOCK_UN); // flock($resource, LOCK_UN);
// fclose($resource); // fclose($resource);
// @unlink($zipFile); // @unlink($zipFile);
} // }
/** /**
* Test all methods * Test all methods

View File

@ -110,6 +110,7 @@ class ODTextTest extends \PHPUnit\Framework\TestCase
$section->addText('Test'); $section->addText('Test');
$writer = new ODText($phpWord); $writer = new ODText($phpWord);
$writer->save('php://output'); $writer->save('php://output');
$this->assertNotNull($this->getActualOutput());
} }
/** /**

View File

@ -111,5 +111,6 @@ class RTFTest extends \PHPUnit\Framework\TestCase
$section->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); $section->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
$writer = new RTF($phpWord); $writer = new RTF($phpWord);
$writer->save('php://output'); $writer->save('php://output');
$this->assertNotNull($this->getActualOutput());
} }
} }

View File

@ -58,7 +58,8 @@ class DocumentTest extends \PHPUnit\Framework\TestCase
$docInfo->setCustomProperty('key6', new \DateTime()); $docInfo->setCustomProperty('key6', new \DateTime());
$docInfo->setCustomProperty('key7', time(), DocInfo::PROPERTY_TYPE_DATE); $docInfo->setCustomProperty('key7', time(), DocInfo::PROPERTY_TYPE_DATE);
TestHelperDOCX::getDocument($phpWord); $doc = TestHelperDOCX::getDocument($phpWord);
$this->assertNotNull($doc);
// $this->assertTrue($doc->elementExists('/Properties/property[name="key1"]/vt:lpwstr')); // $this->assertTrue($doc->elementExists('/Properties/property[name="key1"]/vt:lpwstr'));
// $this->assertTrue($doc->elementExists('/Properties/property[name="key2"]/vt:bool')); // $this->assertTrue($doc->elementExists('/Properties/property[name="key2"]/vt:bool'));