QA: Additional unit testing and template scrutinizer config file

This commit is contained in:
Ivan Lanin 2014-05-05 18:57:54 +07:00
parent 2add5541ce
commit 5a2f4020fb
15 changed files with 435 additions and 74 deletions

13
.scrutinizer.yml Normal file
View File

@ -0,0 +1,13 @@
filter:
excluded_paths: [ 'vendor/*', 'tests/*', 'samples/*', 'src/PhpWord/Shared/PCLZip/*' ]
before_commands:
- "composer install --prefer-source --dev"
tools:
php_code_coverage:
enabled: true
test_command: phpunit -c phpunit.xml.dist
php_sim: true
php_pdepend: true
php_analyzer: true

View File

@ -25,20 +25,34 @@ namespace PhpOffice\PhpWord\Style;
*/
class Shading extends AbstractStyle
{
/**
* Pattern constants (partly)
*
* @const string
* @link http://www.schemacentral.com/sc/ooxml/t-w_ST_Shd.html
*/
const PATTERN_CLEAR = 'clear'; // No pattern
const PATTERN_SOLID = 'solid'; // 100% fill pattern
const PATTERN_HSTRIPE = 'horzStripe'; // Horizontal stripe pattern
const PATTERN_VSTRIPE = 'vertStripe'; // Vertical stripe pattern
const PATTERN_DSTRIPE = 'diagStripe'; // Diagonal stripe pattern
const PATTERN_HCROSS = 'horzCross'; // Horizontal cross pattern
const PATTERN_DCROSS = 'diagCross'; // Diagonal cross pattern
/**
* Shading pattern
*
* @var string
* @link http://www.schemacentral.com/sc/ooxml/t-w_ST_Shd.html
*/
private $pattern = 'clear';
private $pattern = self::PATTERN_CLEAR;
/**
* Shading pattern color
*
* @var string
*/
private $color = 'auto';
private $color;
/**
* Shading background color
@ -75,7 +89,10 @@ class Shading extends AbstractStyle
*/
public function setPattern($value = null)
{
$this->pattern = $value;
$enum = array(self::PATTERN_CLEAR, self::PATTERN_SOLID, self::PATTERN_HSTRIPE,
self::PATTERN_VSTRIPE, self::PATTERN_DSTRIPE, self::PATTERN_HCROSS, self::PATTERN_DCROSS);
$this->pattern = $this->setEnumVal($value, $enum, $this->pattern);
return $this;
}

View File

@ -22,6 +22,12 @@ namespace PhpOffice\PhpWord\Style;
*/
class TOC extends Tab
{
/**
* Tab leader types for backward compatibility
*
* @const string
* @deprecated 0.11.0
*/
const TABLEADER_DOT = self::TAB_LEADER_DOT;
const TABLEADER_UNDERSCORE = self::TAB_LEADER_UNDERSCORE;
const TABLEADER_LINE = self::TAB_LEADER_HYPHEN;
@ -32,8 +38,7 @@ class TOC extends Tab
*
* @var int
*/
private $indent;
private $indent = 200;
/**
* Create a new TOC Style
@ -41,7 +46,6 @@ class TOC extends Tab
public function __construct()
{
parent::__construct(self::TAB_STOP_RIGHT, 9062, self::TABLEADER_DOT);
$this->indent = 200;
}
/**

View File

@ -143,6 +143,8 @@ class Table extends Border
{
if (!is_null($this->shading)) {
return $this->shading->getFill();
} else {
return null;
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* PHPWord
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2014 PHPWord
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Tests\Element;
use PhpOffice\PhpWord\Collection\Footnotes;
use PhpOffice\PhpWord\Element\Footnote;
/**
* Test class for PhpOffice\PhpWord\Element\Collection subnamespace
*
* Using concrete class Footnotes instead of AbstractCollection
*/
class CollectionTest extends \PHPUnit_Framework_TestCase
{
/**
* Test collection
*/
public function testCollection()
{
$object = new Footnotes();
$object->addItem(new Footnote()); // addItem #1
$this->assertEquals(2, $object->addItem(new Footnote())); // addItem #2. Should returns new item index
$this->assertEquals(2, $object->countItems()); // There are two items now
$this->assertEquals(2, count($object->getItems())); // getItems returns array
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Footnote', $object->getItem(1)); // getItem returns object
$this->assertNull($object->getItem(3)); // getItem returns null when invalid index is referenced
$object->setItem(2, null); // Set item #2 to null
$this->assertNull($object->getItem(2)); // Check if it's null
}
}

View File

@ -61,6 +61,17 @@ class TOCTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('Font Style', $object->getStyleFont());
}
/**
* Test when no PHPWord object is assigned:
*/
public function testNoPhpWord()
{
$object = new TOC();
$this->assertEmpty($object->getTitles());
$this->assertNull($object->getPhpWord());
}
/**
* Set/get minDepth and maxDepth
*/

View File

@ -0,0 +1,53 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2014 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Tests\Style;
use PhpOffice\PhpWord\Style\Indentation;
/**
* Test class for PhpOffice\PhpWord\Style\Indentation
*
* @coversDefaultClass \PhpOffice\PhpWord\Style\Indentation
*/
class IndentationTest extends \PHPUnit_Framework_TestCase
{
/**
* Test get/set
*/
public function testGetSetProperties()
{
$object = new Indentation();
$properties = array(
'left' => array(0, 10),
'right' => array(0, 10),
'firstLine' => array(null, 20),
'hanging' => array(null, 20),
);
foreach ($properties as $property => $value) {
list($default, $expected) = $value;
$get = "get{$property}";
$set = "set{$property}";
$this->assertEquals($default, $object->$get()); // Default value
$object->$set($expected);
$this->assertEquals($expected, $object->$get()); // New value
}
}
}

View File

@ -0,0 +1,53 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2014 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Tests\Style;
use PhpOffice\PhpWord\Style\LineNumbering;
/**
* Test class for PhpOffice\PhpWord\Style\LineNumbering
*
* @coversDefaultClass \PhpOffice\PhpWord\Style\LineNumbering
*/
class LineNumberingTest extends \PHPUnit_Framework_TestCase
{
/**
* Test get/set
*/
public function testGetSetProperties()
{
$object = new LineNumbering();
$properties = array(
'start' => array(1, 2),
'increment' => array(1, 10),
'distance' => array(null, 10),
'restart' => array(null, 'continuous'),
);
foreach ($properties as $property => $value) {
list($default, $expected) = $value;
$get = "get{$property}";
$set = "set{$property}";
$this->assertEquals($default, $object->$get()); // Default value
$object->$set($expected);
$this->assertEquals($expected, $object->$get()); // New value
}
}
}

View File

@ -0,0 +1,61 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2014 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Tests\Style;
use PhpOffice\PhpWord\Style\Numbering;
/**
* Test class for PhpOffice\PhpWord\Style\Numbering
*
* @coversDefaultClass \PhpOffice\PhpWord\Style\Numbering
*/
class NumberingTest extends \PHPUnit_Framework_TestCase
{
/**
* Test get/set
*/
public function testGetSetProperties()
{
$this->object = new Numbering();
$this->properties = array(
'numId' => array(null, 1),
'type' => array(null, 'singleLevel'),
);
foreach ($this->properties as $property => $value) {
list($default, $expected) = $value;
$get = "get{$property}";
$set = "set{$property}";
$this->assertEquals($default, $this->object->$get()); // Default value
$this->object->$set($expected);
$this->assertEquals($expected, $this->object->$get()); // New value
}
}
/**
* Test get level
*/
public function testGetLevels()
{
$this->object = new Numbering();
$this->assertEmpty($this->object->getLevels());
}
}

View File

@ -0,0 +1,52 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2014 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Tests\Style;
use PhpOffice\PhpWord\Style\Shading;
/**
* Test class for PhpOffice\PhpWord\Style\Shading
*
* @coversDefaultClass \PhpOffice\PhpWord\Style\Shading
*/
class ShadingTest extends \PHPUnit_Framework_TestCase
{
/**
* Test get/set
*/
public function testGetSetProperties()
{
$object = new Shading();
$properties = array(
'pattern' => array('clear', 'solid'),
'color' => array(null, 'FF0000'),
'fill' => array(null, 'FF0000'),
);
foreach ($properties as $property => $value) {
list($default, $expected) = $value;
$get = "get{$property}";
$set = "set{$property}";
$this->assertEquals($default, $object->$get()); // Default value
$object->$set($expected);
$this->assertEquals($expected, $object->$get()); // New value
}
}
}

View File

@ -0,0 +1,53 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2014 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Tests\Style;
use PhpOffice\PhpWord\Style\Spacing;
/**
* Test class for PhpOffice\PhpWord\Style\Spacing
*
* @coversDefaultClass \PhpOffice\PhpWord\Style\Spacing
*/
class SpacingTest extends \PHPUnit_Framework_TestCase
{
/**
* Test get/set
*/
public function testGetSetProperties()
{
$object = new Spacing();
$properties = array(
'before' => array(null, 10),
'after' => array(null, 10),
'line' => array(null, 10),
'rule' => array('auto', 'exact'),
);
foreach ($properties as $property => $value) {
list($default, $expected) = $value;
$get = "get{$property}";
$set = "set{$property}";
$this->assertEquals($default, $object->$get()); // Default value
$object->$set($expected);
$this->assertEquals($expected, $object->$get()); // New value
}
}
}

View File

@ -23,28 +23,30 @@ use PhpOffice\PhpWord\Style\TOC;
* Test class for PhpOffice\PhpWord\Style\TOC
*
* @coversDefaultClass \PhpOffice\PhpWord\Style\TOC
* @runTestsInSeparateProcesses
*/
class TOCTest extends \PHPUnit_Framework_TestCase
{
/**
* Test properties with normal value
* Test get/set
*/
public function testProperties()
public function testGetSet()
{
$object = new TOC();
$properties = array(
'position' => 9062,
'leader' => \PhpOffice\PhpWord\Style\Tab::TAB_LEADER_DOT,
'indent' => 200,
'tabLeader' => array(TOC::TAB_LEADER_DOT, TOC::TAB_LEADER_UNDERSCORE),
'tabPos' => array(9062, 10),
'indent' => array(200, 10),
);
foreach ($properties as $key => $value) {
// set/get
$set = "set{$key}";
$get = "get{$key}";
$object->$set($value);
$this->assertEquals($value, $object->$get());
foreach ($properties as $property => $value) {
list($default, $expected) = $value;
$get = "get{$property}";
$set = "set{$property}";
$this->assertEquals($default, $object->$get()); // Default value
$object->$set($expected);
$this->assertEquals($expected, $object->$get()); // New value
}
}
}

View File

@ -0,0 +1,52 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2014 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Tests\Style;
use PhpOffice\PhpWord\Style\Tab;
/**
* Test class for PhpOffice\PhpWord\Style\Tab
*
* @coversDefaultClass \PhpOffice\PhpWord\Style\Tab
*/
class TabTest extends \PHPUnit_Framework_TestCase
{
/**
* Test get/set
*/
public function testGetSetProperties()
{
$object = new Tab();
$properties = array(
'type' => array(Tab::TAB_STOP_CLEAR, Tab::TAB_STOP_RIGHT),
'leader' => array(Tab::TAB_LEADER_NONE, Tab::TAB_LEADER_DOT),
'position' => array(0, 10),
);
foreach ($properties as $property => $value) {
list($default, $expected) = $value;
$get = "get{$property}";
$set = "set{$property}";
$this->assertEquals($default, $object->$get()); // Default value
$object->$set($expected);
$this->assertEquals($expected, $object->$get()); // New value
}
}
}

View File

@ -38,6 +38,9 @@ class TableTest extends \PHPUnit_Framework_TestCase
$styleTable = array('bgColor' => 'FF0000');
$styleFirstRow = array('borderBottomSize' => 3);
$object = new Table();
$this->assertNull($object->getBgColor());
$object = new Table($styleTable, $styleFirstRow);
$this->assertEquals('FF0000', $object->getBgColor());

View File

@ -1,55 +0,0 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2014 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Tests\Style;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Style\Tab;
use PhpOffice\PhpWord\Tests\TestHelperDOCX;
/**
* Test class for PhpOffice\PhpWord\Style\Tab
*
* @coversDefaultClass \PhpOffice\PhpWord\Style\Tab
* @runTestsInSeparateProcesses
*/
class TabsTest extends \PHPUnit_Framework_TestCase
{
/**
* Executed before each method of the class
*/
public function tearDown()
{
TestHelperDOCX::clear();
}
/**
* Test if the tabs has been created properly
*/
public function testTabsStyle()
{
$phpWord = new PhpWord();
$phpWord->addParagraphStyle('tabbed', array('tabs' => array(new Tab('left', 1440, 'dot'))));
$doc = TestHelperDOCX::getDocument($phpWord);
$file = 'word/styles.xml';
$path = '/w:styles/w:style[@w:styleId="tabbed"]/w:pPr/w:tabs/w:tab[1]';
$element = $doc->getElement($path, $file);
$this->assertEquals('left', $element->getAttribute('w:val'));
$this->assertEquals(1440, $element->getAttribute('w:pos'));
$this->assertEquals('dot', $element->getAttribute('w:leader'));
}
}