diff --git a/src/PhpSpreadsheet/Calculation.php b/src/PhpSpreadsheet/Calculation.php index d6ab6519..51bb0252 100644 --- a/src/PhpSpreadsheet/Calculation.php +++ b/src/PhpSpreadsheet/Calculation.php @@ -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 diff --git a/unitTests/Classes/src/CalculationTest.php b/unitTests/Classes/src/CalculationTest.php index bc221ce2..f44cc038 100644 --- a/unitTests/Classes/src/CalculationTest.php +++ b/unitTests/Classes/src/CalculationTest.php @@ -1,17 +1,15 @@ _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'); } } diff --git a/unitTests/Classes/src/CellTest.php b/unitTests/Classes/src/CellTest.php index 9680294a..a11670d2 100644 --- a/unitTests/Classes/src/CellTest.php +++ b/unitTests/Classes/src/CellTest.php @@ -1,17 +1,15 @@ 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'); } } diff --git a/unitTests/Classes/src/ReferenceHelperTest.php b/unitTests/Classes/src/ReferenceHelperTest.php index cf40f73a..ed16711f 100644 --- a/unitTests/Classes/src/ReferenceHelperTest.php +++ b/unitTests/Classes/src/ReferenceHelperTest.php @@ -1,20 +1,19 @@ $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); } diff --git a/unitTests/bootstrap.php b/unitTests/bootstrap.php index c575eb63..885f592a 100644 --- a/unitTests/bootstrap.php +++ b/unitTests/bootstrap.php @@ -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. diff --git a/unitTests/rawTestData/ColumnIndex.data b/unitTests/rawTestData/ColumnIndex.data index 9a1679b6..44e49d5a 100644 --- a/unitTests/rawTestData/ColumnIndex.data +++ b/unitTests/rawTestData/ColumnIndex.data @@ -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" diff --git a/unitTests/rawTestData/ColumnString.data b/unitTests/rawTestData/ColumnString.data index 5573759e..792deaa4 100644 --- a/unitTests/rawTestData/ColumnString.data +++ b/unitTests/rawTestData/ColumnString.data @@ -4,6 +4,9 @@ "AB", 28 "AZ", 52 "BA", 53 +"BZ", 78 +"CA", 79 +"IV", 256 "ZZ", 702 "AAA", 703 "BAA", 1379