Work on rewriting unit tests for the new folder structure (calling bootstrap) and json input files

This commit is contained in:
MarkBaker 2015-05-29 21:35:35 +01:00
parent 93d16b886f
commit 0dafaea059
7 changed files with 90 additions and 76 deletions

View File

@ -144,7 +144,7 @@ class Calculation
* The debug log generated by the calculation engine * The debug log generated by the calculation engine
* *
* @access private * @access private
* @var PHPExcel_CalcEngine_Logger * @var CalcEngine\Logger
* *
*/ */
private $debugLog; private $debugLog;
@ -271,7 +271,7 @@ class Calculation
), ),
'ACCRINT' => array( 'ACCRINT' => array(
'category' => Calculation\Categories::CATEGORY_FINANCIAL, 'category' => Calculation\Categories::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::ACCRINT', 'functionCall' => '\\PHPExcel\\Calculation\\Financial::ACCRINT',
'argumentCount' => '4-7' 'argumentCount' => '4-7'
), ),
'ACCRINTM' => array( 'ACCRINTM' => array(
@ -3139,7 +3139,7 @@ class Calculation
); );
// Convert infix to postfix notation // Convert infix to postfix notation
private function _parseFormula($formula, PHPExcel_Cell $pCell = null) private function _parseFormula($formula, Cell $pCell = null)
{ {
if (($formula = $this->convertMatrixReferences(trim($formula))) === false) { if (($formula = $this->convertMatrixReferences(trim($formula))) === false) {
return false; return false;
@ -3160,7 +3160,7 @@ class Calculation
// Start with initialisation // Start with initialisation
$index = 0; $index = 0;
$stack = new PHPExcel_Calculation_Token_Stack; $stack = new Calculation\Token\Stack;
$output = array(); $output = array();
$expectingOperator = false; // We use this test in syntax-checking the expression to determine when a $expectingOperator = false; // We use this test in syntax-checking the expression to determine when a
// - is a negation or + is a positive operator rather than an operation // - is a negation or + is a positive operator rather than an operation

View File

@ -1,17 +1,15 @@
<?php <?php
namespace PHPExcel;
require_once 'testDataFileIterator.php'; require_once 'testDataFileIterator.php';
class CalculationTest extends PHPUnit_Framework_TestCase class CalculationTest extends \PHPUnit_Framework_TestCase
{ {
public function setUp() public function setUp()
{ {
if (!defined('PHPEXCEL_ROOT')) { Calculation\Functions::setCompatibilityMode(Calculation\Functions::COMPATIBILITY_EXCEL);
define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
}
require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
PHPExcel_Calculation_Functions::setCompatibilityMode(PHPExcel_Calculation_Functions::COMPATIBILITY_EXCEL);
} }
/** /**
@ -19,17 +17,17 @@ class CalculationTest extends PHPUnit_Framework_TestCase
*/ */
public function testBinaryComparisonOperation($formula, $expectedResultExcel, $expectedResultOpenOffice) public function testBinaryComparisonOperation($formula, $expectedResultExcel, $expectedResultOpenOffice)
{ {
PHPExcel_Calculation_Functions::setCompatibilityMode(PHPExcel_Calculation_Functions::COMPATIBILITY_EXCEL); Calculation\Functions::setCompatibilityMode(Calculation\Functions::COMPATIBILITY_EXCEL);
$resultExcel = \PHPExcel_Calculation::getInstance()->_calculateFormulaValue($formula); $resultExcel = Calculation::getInstance()->_calculateFormulaValue($formula);
$this->assertEquals($expectedResultExcel, $resultExcel, 'should be Excel compatible'); $this->assertEquals($expectedResultExcel, $resultExcel, 'should be Excel compatible');
PHPExcel_Calculation_Functions::setCompatibilityMode(PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE); Calculation\Functions::setCompatibilityMode(Calculation\Functions::COMPATIBILITY_OPENOFFICE);
$resultOpenOffice = \PHPExcel_Calculation::getInstance()->_calculateFormulaValue($formula); $resultOpenOffice = Calculation::getInstance()->_calculateFormulaValue($formula);
$this->assertEquals($expectedResultOpenOffice, $resultOpenOffice, 'should be OpenOffice compatible'); $this->assertEquals($expectedResultOpenOffice, $resultOpenOffice, 'should be OpenOffice compatible');
} }
public function providerBinaryComparisonOperation() public function providerBinaryComparisonOperation()
{ {
return new testDataFileIterator('rawTestData/CalculationBinaryComparisonOperation.data'); return new \testDataFileIterator('rawTestData/CalculationBinaryComparisonOperation.data');
} }
} }

View File

@ -1,17 +1,15 @@
<?php <?php
namespace PHPExcel;
require_once 'testDataFileIterator.php'; require_once 'testDataFileIterator.php';
class CellTest extends PHPUnit_Framework_TestCase class CellTest extends \PHPUnit_Framework_TestCase
{ {
public function setUp() public function setUp()
{ {
if (!defined('PHPEXCEL_ROOT')) {
define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
}
require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
} }
/** /**
@ -21,21 +19,22 @@ class CellTest extends PHPUnit_Framework_TestCase
{ {
$args = func_get_args(); $args = func_get_args();
$expectedResult = array_pop($args); $expectedResult = array_pop($args);
$result = call_user_func_array(array('PHPExcel_Cell','columnIndexFromString'), $args); $result = call_user_func_array(array('\\PHPExcel\\Cell','columnIndexFromString'), $args);
$this->assertEquals($expectedResult, $result); $this->assertEquals($expectedResult, $result);
} }
public function providerColumnString() public function providerColumnString()
{ {
return new testDataFileIterator('rawTestData/ColumnString.data'); return new \testDataFileIterator('rawTestData/ColumnString.data');
} }
public function testColumnIndexFromStringTooLong() public function testColumnIndexFromStringTooLong()
{ {
$cellAddress = 'ABCD'; $cellAddress = 'ABCD';
try { try {
$result = call_user_func(array('PHPExcel_Cell','columnIndexFromString'), $cellAddress); $result = call_user_func(array('\\PHPExcel\\Cell','columnIndexFromString'), $cellAddress);
} catch (PHPExcel_Exception $e) { } catch (\Exception $e) {
$this->assertInstanceOf('\\PHPExcel\\Exception', $e);
$this->assertEquals($e->getMessage(), 'Column string index can not be longer than 3 characters'); $this->assertEquals($e->getMessage(), 'Column string index can not be longer than 3 characters');
return; return;
} }
@ -46,8 +45,9 @@ class CellTest extends PHPUnit_Framework_TestCase
{ {
$cellAddress = ''; $cellAddress = '';
try { try {
$result = call_user_func(array('PHPExcel_Cell','columnIndexFromString'), $cellAddress); $result = call_user_func(array('\\PHPExcel\\Cell','columnIndexFromString'), $cellAddress);
} catch (PHPExcel_Exception $e) { } catch (\Exception $e) {
$this->assertInstanceOf('\\PHPExcel\\Exception', $e);
$this->assertEquals($e->getMessage(), 'Column string index can not be empty'); $this->assertEquals($e->getMessage(), 'Column string index can not be empty');
return; return;
} }
@ -61,13 +61,13 @@ class CellTest extends PHPUnit_Framework_TestCase
{ {
$args = func_get_args(); $args = func_get_args();
$expectedResult = array_pop($args); $expectedResult = array_pop($args);
$result = call_user_func_array(array('PHPExcel_Cell','stringFromColumnIndex'), $args); $result = call_user_func_array(array('\\PHPExcel\\Cell','stringFromColumnIndex'), $args);
$this->assertEquals($expectedResult, $result); $this->assertEquals($expectedResult, $result);
} }
public function providerColumnIndex() public function providerColumnIndex()
{ {
return new testDataFileIterator('rawTestData/ColumnIndex.data'); return new \testDataFileIterator('rawTestData/ColumnIndex.data');
} }
/** /**
@ -77,21 +77,22 @@ class CellTest extends PHPUnit_Framework_TestCase
{ {
$args = func_get_args(); $args = func_get_args();
$expectedResult = array_pop($args); $expectedResult = array_pop($args);
$result = call_user_func_array(array('PHPExcel_Cell','coordinateFromString'), $args); $result = call_user_func_array(array('\\PHPExcel\\Cell','coordinateFromString'), $args);
$this->assertEquals($expectedResult, $result); $this->assertEquals($expectedResult, $result);
} }
public function providerCoordinates() public function providerCoordinates()
{ {
return new testDataFileIterator('rawTestData/CellCoordinates.data'); return new \testDataFileIterator('rawTestData/CellCoordinates.data');
} }
public function testCoordinateFromStringWithRangeAddress() public function testCoordinateFromStringWithRangeAddress()
{ {
$cellAddress = 'A1:AI2012'; $cellAddress = 'A1:AI2012';
try { try {
$result = call_user_func(array('PHPExcel_Cell','coordinateFromString'), $cellAddress); $result = call_user_func(array('\\PHPExcel\\Cell','coordinateFromString'), $cellAddress);
} catch (PHPExcel_Exception $e) { } catch (\Exception $e) {
$this->assertInstanceOf('\\PHPExcel\\Exception', $e);
$this->assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells'); $this->assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells');
return; return;
} }
@ -102,8 +103,9 @@ class CellTest extends PHPUnit_Framework_TestCase
{ {
$cellAddress = ''; $cellAddress = '';
try { try {
$result = call_user_func(array('PHPExcel_Cell','coordinateFromString'), $cellAddress); $result = call_user_func(array('\\PHPExcel\\Cell','coordinateFromString'), $cellAddress);
} catch (PHPExcel_Exception $e) { } catch (\Exception $e) {
$this->assertInstanceOf('\\PHPExcel\\Exception', $e);
$this->assertEquals($e->getMessage(), 'Cell coordinate can not be zero-length string'); $this->assertEquals($e->getMessage(), 'Cell coordinate can not be zero-length string');
return; return;
} }
@ -114,8 +116,9 @@ class CellTest extends PHPUnit_Framework_TestCase
{ {
$cellAddress = 'AI'; $cellAddress = 'AI';
try { try {
$result = call_user_func(array('PHPExcel_Cell','coordinateFromString'), $cellAddress); $result = call_user_func(array('\\PHPExcel\\Cell','coordinateFromString'), $cellAddress);
} catch (PHPExcel_Exception $e) { } catch (\Exception $e) {
$this->assertInstanceOf('\\PHPExcel\\Exception', $e);
$this->assertEquals($e->getMessage(), 'Invalid cell coordinate '.$cellAddress); $this->assertEquals($e->getMessage(), 'Invalid cell coordinate '.$cellAddress);
return; return;
} }
@ -129,21 +132,22 @@ class CellTest extends PHPUnit_Framework_TestCase
{ {
$args = func_get_args(); $args = func_get_args();
$expectedResult = array_pop($args); $expectedResult = array_pop($args);
$result = call_user_func_array(array('PHPExcel_Cell','absoluteCoordinate'), $args); $result = call_user_func_array(array('\\PHPExcel\\Cell','absoluteCoordinate'), $args);
$this->assertEquals($expectedResult, $result); $this->assertEquals($expectedResult, $result);
} }
public function providerAbsoluteCoordinates() public function providerAbsoluteCoordinates()
{ {
return new testDataFileIterator('rawTestData/CellAbsoluteCoordinate.data'); return new \testDataFileIterator('rawTestData/CellAbsoluteCoordinate.data');
} }
public function testAbsoluteCoordinateFromStringWithRangeAddress() public function testAbsoluteCoordinateFromStringWithRangeAddress()
{ {
$cellAddress = 'A1:AI2012'; $cellAddress = 'A1:AI2012';
try { try {
$result = call_user_func(array('PHPExcel_Cell','absoluteCoordinate'), $cellAddress); $result = call_user_func(array('\\PHPExcel\\Cell','absoluteCoordinate'), $cellAddress);
} catch (PHPExcel_Exception $e) { } catch (\Exception $e) {
$this->assertInstanceOf('\\PHPExcel\\Exception', $e);
$this->assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells'); $this->assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells');
return; return;
} }
@ -157,21 +161,22 @@ class CellTest extends PHPUnit_Framework_TestCase
{ {
$args = func_get_args(); $args = func_get_args();
$expectedResult = array_pop($args); $expectedResult = array_pop($args);
$result = call_user_func_array(array('PHPExcel_Cell','absoluteReference'), $args); $result = call_user_func_array(array('\\PHPExcel\\Cell','absoluteReference'), $args);
$this->assertEquals($expectedResult, $result); $this->assertEquals($expectedResult, $result);
} }
public function providerAbsoluteReferences() public function providerAbsoluteReferences()
{ {
return new testDataFileIterator('rawTestData/CellAbsoluteReference.data'); return new \testDataFileIterator('rawTestData/CellAbsoluteReference.data');
} }
public function testAbsoluteReferenceFromStringWithRangeAddress() public function testAbsoluteReferenceFromStringWithRangeAddress()
{ {
$cellAddress = 'A1:AI2012'; $cellAddress = 'A1:AI2012';
try { try {
$result = call_user_func(array('PHPExcel_Cell','absoluteReference'), $cellAddress); $result = call_user_func(array('\\PHPExcel\\Cell','absoluteReference'), $cellAddress);
} catch (PHPExcel_Exception $e) { } catch (\Exception $e) {
$this->assertInstanceOf('\\PHPExcel\\Exception', $e);
$this->assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells'); $this->assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells');
return; return;
} }
@ -185,7 +190,7 @@ class CellTest extends PHPUnit_Framework_TestCase
{ {
$args = func_get_args(); $args = func_get_args();
$expectedResult = array_pop($args); $expectedResult = array_pop($args);
$result = call_user_func_array(array('PHPExcel_Cell','splitRange'), $args); $result = call_user_func_array(array('\\PHPExcel\\Cell','splitRange'), $args);
foreach ($result as $key => $split) { foreach ($result as $key => $split) {
if (!is_array($expectedResult[$key])) { if (!is_array($expectedResult[$key])) {
$this->assertEquals($expectedResult[$key], $split[0]); $this->assertEquals($expectedResult[$key], $split[0]);
@ -197,7 +202,7 @@ class CellTest extends PHPUnit_Framework_TestCase
public function providerSplitRange() public function providerSplitRange()
{ {
return new testDataFileIterator('rawTestData/CellSplitRange.data'); return new \testDataFileIterator('rawTestData/CellSplitRange.data');
} }
/** /**
@ -207,21 +212,22 @@ class CellTest extends PHPUnit_Framework_TestCase
{ {
$args = func_get_args(); $args = func_get_args();
$expectedResult = array_pop($args); $expectedResult = array_pop($args);
$result = call_user_func_array(array('PHPExcel_Cell','buildRange'), $args); $result = call_user_func_array(array('\\PHPExcel\\Cell','buildRange'), $args);
$this->assertEquals($expectedResult, $result); $this->assertEquals($expectedResult, $result);
} }
public function providerBuildRange() public function providerBuildRange()
{ {
return new testDataFileIterator('rawTestData/CellBuildRange.data'); return new \testDataFileIterator('rawTestData/CellBuildRange.data');
} }
public function testBuildRangeInvalid() public function testBuildRangeInvalid()
{ {
$cellRange = ''; $cellRange = '';
try { try {
$result = call_user_func(array('PHPExcel_Cell','buildRange'), $cellRange); $result = call_user_func(array('\\PHPExcel\\Cell','buildRange'), $cellRange);
} catch (PHPExcel_Exception $e) { } catch (\Exception $e) {
$this->assertInstanceOf('\\PHPExcel\\Exception', $e);
$this->assertEquals($e->getMessage(), 'Range does not contain any information'); $this->assertEquals($e->getMessage(), 'Range does not contain any information');
return; return;
} }
@ -235,13 +241,13 @@ class CellTest extends PHPUnit_Framework_TestCase
{ {
$args = func_get_args(); $args = func_get_args();
$expectedResult = array_pop($args); $expectedResult = array_pop($args);
$result = call_user_func_array(array('PHPExcel_Cell','rangeBoundaries'), $args); $result = call_user_func_array(array('\\PHPExcel\\Cell','rangeBoundaries'), $args);
$this->assertEquals($expectedResult, $result); $this->assertEquals($expectedResult, $result);
} }
public function providerRangeBoundaries() public function providerRangeBoundaries()
{ {
return new testDataFileIterator('rawTestData/CellRangeBoundaries.data'); return new \testDataFileIterator('rawTestData/CellRangeBoundaries.data');
} }
/** /**
@ -251,13 +257,13 @@ class CellTest extends PHPUnit_Framework_TestCase
{ {
$args = func_get_args(); $args = func_get_args();
$expectedResult = array_pop($args); $expectedResult = array_pop($args);
$result = call_user_func_array(array('PHPExcel_Cell','rangeDimension'), $args); $result = call_user_func_array(array('\\PHPExcel\\Cell','rangeDimension'), $args);
$this->assertEquals($expectedResult, $result); $this->assertEquals($expectedResult, $result);
} }
public function providerRangeDimension() public function providerRangeDimension()
{ {
return new testDataFileIterator('rawTestData/CellRangeDimension.data'); return new \testDataFileIterator('rawTestData/CellRangeDimension.data');
} }
/** /**
@ -267,13 +273,13 @@ class CellTest extends PHPUnit_Framework_TestCase
{ {
$args = func_get_args(); $args = func_get_args();
$expectedResult = array_pop($args); $expectedResult = array_pop($args);
$result = call_user_func_array(array('PHPExcel_Cell','getRangeBoundaries'), $args); $result = call_user_func_array(array('\\PHPExcel\\Cell','getRangeBoundaries'), $args);
$this->assertEquals($expectedResult, $result); $this->assertEquals($expectedResult, $result);
} }
public function providerGetRangeBoundaries() public function providerGetRangeBoundaries()
{ {
return new testDataFileIterator('rawTestData/CellGetRangeBoundaries.data'); return new \testDataFileIterator('rawTestData/CellGetRangeBoundaries.data');
} }
/** /**
@ -283,12 +289,12 @@ class CellTest extends PHPUnit_Framework_TestCase
{ {
$args = func_get_args(); $args = func_get_args();
$expectedResult = array_pop($args); $expectedResult = array_pop($args);
$result = call_user_func_array(array('PHPExcel_Cell','extractAllCellReferencesInRange'), $args); $result = call_user_func_array(array('\\PHPExcel\\Cell','extractAllCellReferencesInRange'), $args);
$this->assertEquals($expectedResult, $result); $this->assertEquals($expectedResult, $result);
} }
public function providerExtractAllCellReferencesInRange() public function providerExtractAllCellReferencesInRange()
{ {
return new testDataFileIterator('rawTestData/CellExtractAllCellReferencesInRange.data'); return new \testDataFileIterator('rawTestData/CellExtractAllCellReferencesInRange.data');
} }
} }

View File

@ -1,20 +1,19 @@
<?php <?php
class ReferenceHelperTest extends PHPUnit_Framework_TestCase namespace PHPExcel;
class ReferenceHelperTest extends \PHPUnit_Framework_TestCase
{ {
public function setUp() public function setUp()
{ {
if (!defined('PHPEXCEL_ROOT')) {
define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
}
require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
} }
public function testColumnSort() public function testColumnSort()
{ {
$columnBase = $columnExpectedResult = array( $columnBase = $columnExpectedResult = [
'A','B','Z', 'A','B','Z',
'AA','AB','AZ', 'AA','AB','AZ',
'BA','BB','BZ', 'BA','BB','BZ',
@ -25,9 +24,9 @@ class ReferenceHelperTest extends PHPUnit_Framework_TestCase
'BAA','BAB','BAZ', 'BAA','BAB','BAZ',
'BBA','BBB','BBZ', 'BBA','BBB','BBZ',
'BZA','BZB','BZZ' 'BZA','BZB','BZZ'
); ];
shuffle($columnBase); shuffle($columnBase);
usort($columnBase, array('PHPExcel_ReferenceHelper','columnSort')); usort($columnBase, array('\\PHPExcel\\ReferenceHelper','columnSort'));
foreach ($columnBase as $key => $value) { foreach ($columnBase as $key => $value) {
$this->assertEquals($columnExpectedResult[$key], $value); $this->assertEquals($columnExpectedResult[$key], $value);
} }
@ -35,7 +34,7 @@ class ReferenceHelperTest extends PHPUnit_Framework_TestCase
public function testColumnReverseSort() public function testColumnReverseSort()
{ {
$columnBase = $columnExpectedResult = array( $columnBase = $columnExpectedResult = [
'A','B','Z', 'A','B','Z',
'AA','AB','AZ', 'AA','AB','AZ',
'BA','BB','BZ', 'BA','BB','BZ',
@ -46,10 +45,10 @@ class ReferenceHelperTest extends PHPUnit_Framework_TestCase
'BAA','BAB','BAZ', 'BAA','BAB','BAZ',
'BBA','BBB','BBZ', 'BBA','BBB','BBZ',
'BZA','BZB','BZZ' 'BZA','BZB','BZZ'
); ];
shuffle($columnBase); shuffle($columnBase);
$columnExpectedResult = array_reverse($columnExpectedResult); $columnExpectedResult = array_reverse($columnExpectedResult);
usort($columnBase, array('PHPExcel_ReferenceHelper','columnReverseSort')); usort($columnBase, array('\\PHPExcel\\ReferenceHelper','columnReverseSort'));
foreach ($columnBase as $key => $value) { foreach ($columnBase as $key => $value) {
$this->assertEquals($columnExpectedResult[$key], $value); $this->assertEquals($columnExpectedResult[$key], $value);
} }

View File

@ -35,6 +35,11 @@ set_include_path(implode(PATH_SEPARATOR, array(
))); )));
if (!defined('PHPEXCEL_ROOT')) {
define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
}
require_once(PHPEXCEL_ROOT . 'Bootstrap.php');
/** /**
* @todo Sort out xdebug in vagrant so that this works in all sandboxes * @todo Sort out xdebug in vagrant so that this works in all sandboxes
* For now, it is safer to test for it rather then remove it. * For now, it is safer to test for it rather then remove it.

View File

@ -1,9 +1,12 @@
0, "A" 0, "A"
25, "Z" 25, "Z"
26, "AA" 26, "AA"
27, "AB" 27, "AB"
51, "AZ" 51, "AZ"
52, "BA" 52, "BA"
77, "BZ"
78, "CA"
255, "IV"
701, "ZZ" 701, "ZZ"
702, "AAA" 702, "AAA"
1378, "BAA" 1378, "BAA"

View File

@ -4,6 +4,9 @@
"AB", 28 "AB", 28
"AZ", 52 "AZ", 52
"BA", 53 "BA", 53
"BZ", 78
"CA", 79
"IV", 256
"ZZ", 702 "ZZ", 702
"AAA", 703 "AAA", 703
"BAA", 1379 "BAA", 1379