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
*
* @access private
* @var PHPExcel_CalcEngine_Logger
* @var CalcEngine\Logger
*
*/
private $debugLog;
@ -271,7 +271,7 @@ class Calculation
),
'ACCRINT' => array(
'category' => Calculation\Categories::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::ACCRINT',
'functionCall' => '\\PHPExcel\\Calculation\\Financial::ACCRINT',
'argumentCount' => '4-7'
),
'ACCRINTM' => array(
@ -3139,7 +3139,7 @@ class Calculation
);
// 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) {
return false;
@ -3160,7 +3160,7 @@ class Calculation
// Start with initialisation
$index = 0;
$stack = new PHPExcel_Calculation_Token_Stack;
$stack = new Calculation\Token\Stack;
$output = array();
$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

View File

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

View File

@ -1,17 +1,15 @@
<?php
namespace PHPExcel;
require_once 'testDataFileIterator.php';
class CellTest extends PHPUnit_Framework_TestCase
class CellTest extends \PHPUnit_Framework_TestCase
{
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();
$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);
}
public function providerColumnString()
{
return new testDataFileIterator('rawTestData/ColumnString.data');
return new \testDataFileIterator('rawTestData/ColumnString.data');
}
public function testColumnIndexFromStringTooLong()
{
$cellAddress = 'ABCD';
try {
$result = call_user_func(array('PHPExcel_Cell','columnIndexFromString'), $cellAddress);
} catch (PHPExcel_Exception $e) {
$result = call_user_func(array('\\PHPExcel\\Cell','columnIndexFromString'), $cellAddress);
} catch (\Exception $e) {
$this->assertInstanceOf('\\PHPExcel\\Exception', $e);
$this->assertEquals($e->getMessage(), 'Column string index can not be longer than 3 characters');
return;
}
@ -46,8 +45,9 @@ class CellTest extends PHPUnit_Framework_TestCase
{
$cellAddress = '';
try {
$result = call_user_func(array('PHPExcel_Cell','columnIndexFromString'), $cellAddress);
} catch (PHPExcel_Exception $e) {
$result = call_user_func(array('\\PHPExcel\\Cell','columnIndexFromString'), $cellAddress);
} catch (\Exception $e) {
$this->assertInstanceOf('\\PHPExcel\\Exception', $e);
$this->assertEquals($e->getMessage(), 'Column string index can not be empty');
return;
}
@ -61,13 +61,13 @@ class CellTest extends PHPUnit_Framework_TestCase
{
$args = func_get_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);
}
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();
$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);
}
public function providerCoordinates()
{
return new testDataFileIterator('rawTestData/CellCoordinates.data');
return new \testDataFileIterator('rawTestData/CellCoordinates.data');
}
public function testCoordinateFromStringWithRangeAddress()
{
$cellAddress = 'A1:AI2012';
try {
$result = call_user_func(array('PHPExcel_Cell','coordinateFromString'), $cellAddress);
} catch (PHPExcel_Exception $e) {
$result = call_user_func(array('\\PHPExcel\\Cell','coordinateFromString'), $cellAddress);
} catch (\Exception $e) {
$this->assertInstanceOf('\\PHPExcel\\Exception', $e);
$this->assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells');
return;
}
@ -102,8 +103,9 @@ class CellTest extends PHPUnit_Framework_TestCase
{
$cellAddress = '';
try {
$result = call_user_func(array('PHPExcel_Cell','coordinateFromString'), $cellAddress);
} catch (PHPExcel_Exception $e) {
$result = call_user_func(array('\\PHPExcel\\Cell','coordinateFromString'), $cellAddress);
} catch (\Exception $e) {
$this->assertInstanceOf('\\PHPExcel\\Exception', $e);
$this->assertEquals($e->getMessage(), 'Cell coordinate can not be zero-length string');
return;
}
@ -114,8 +116,9 @@ class CellTest extends PHPUnit_Framework_TestCase
{
$cellAddress = 'AI';
try {
$result = call_user_func(array('PHPExcel_Cell','coordinateFromString'), $cellAddress);
} catch (PHPExcel_Exception $e) {
$result = call_user_func(array('\\PHPExcel\\Cell','coordinateFromString'), $cellAddress);
} catch (\Exception $e) {
$this->assertInstanceOf('\\PHPExcel\\Exception', $e);
$this->assertEquals($e->getMessage(), 'Invalid cell coordinate '.$cellAddress);
return;
}
@ -129,21 +132,22 @@ class CellTest extends PHPUnit_Framework_TestCase
{
$args = func_get_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);
}
public function providerAbsoluteCoordinates()
{
return new testDataFileIterator('rawTestData/CellAbsoluteCoordinate.data');
return new \testDataFileIterator('rawTestData/CellAbsoluteCoordinate.data');
}
public function testAbsoluteCoordinateFromStringWithRangeAddress()
{
$cellAddress = 'A1:AI2012';
try {
$result = call_user_func(array('PHPExcel_Cell','absoluteCoordinate'), $cellAddress);
} catch (PHPExcel_Exception $e) {
$result = call_user_func(array('\\PHPExcel\\Cell','absoluteCoordinate'), $cellAddress);
} catch (\Exception $e) {
$this->assertInstanceOf('\\PHPExcel\\Exception', $e);
$this->assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells');
return;
}
@ -157,21 +161,22 @@ class CellTest extends PHPUnit_Framework_TestCase
{
$args = func_get_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);
}
public function providerAbsoluteReferences()
{
return new testDataFileIterator('rawTestData/CellAbsoluteReference.data');
return new \testDataFileIterator('rawTestData/CellAbsoluteReference.data');
}
public function testAbsoluteReferenceFromStringWithRangeAddress()
{
$cellAddress = 'A1:AI2012';
try {
$result = call_user_func(array('PHPExcel_Cell','absoluteReference'), $cellAddress);
} catch (PHPExcel_Exception $e) {
$result = call_user_func(array('\\PHPExcel\\Cell','absoluteReference'), $cellAddress);
} catch (\Exception $e) {
$this->assertInstanceOf('\\PHPExcel\\Exception', $e);
$this->assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells');
return;
}
@ -185,7 +190,7 @@ class CellTest extends PHPUnit_Framework_TestCase
{
$args = func_get_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) {
if (!is_array($expectedResult[$key])) {
$this->assertEquals($expectedResult[$key], $split[0]);
@ -197,7 +202,7 @@ class CellTest extends PHPUnit_Framework_TestCase
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();
$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);
}
public function providerBuildRange()
{
return new testDataFileIterator('rawTestData/CellBuildRange.data');
return new \testDataFileIterator('rawTestData/CellBuildRange.data');
}
public function testBuildRangeInvalid()
{
$cellRange = '';
try {
$result = call_user_func(array('PHPExcel_Cell','buildRange'), $cellRange);
} catch (PHPExcel_Exception $e) {
$result = call_user_func(array('\\PHPExcel\\Cell','buildRange'), $cellRange);
} catch (\Exception $e) {
$this->assertInstanceOf('\\PHPExcel\\Exception', $e);
$this->assertEquals($e->getMessage(), 'Range does not contain any information');
return;
}
@ -235,13 +241,13 @@ class CellTest extends PHPUnit_Framework_TestCase
{
$args = func_get_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);
}
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();
$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);
}
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();
$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);
}
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();
$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);
}
public function providerExtractAllCellReferencesInRange()
{
return new testDataFileIterator('rawTestData/CellExtractAllCellReferencesInRange.data');
return new \testDataFileIterator('rawTestData/CellExtractAllCellReferencesInRange.data');
}
}

View File

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

View File

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

View File

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