Additional cell datatype unit tests (#1301)

This commit is contained in:
Mark Baker 2020-01-03 23:29:53 +01:00 committed by GitHub
parent 0417c8cc2b
commit e19228ecb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 66 additions and 5 deletions

View File

@ -217,6 +217,9 @@ class Cell
break;
case DataType::TYPE_NUMERIC:
if (is_string($pValue) && !is_numeric($pValue)) {
throw new Exception('Invalid numeric value for datatype Numeric');
}
$this->value = 0 + $pValue;
break;

View File

@ -60,7 +60,7 @@ class QRDecomposition
{
if ($A instanceof Matrix) {
// Initialize.
$this->QR = $A->getArrayCopy();
$this->QR = $A->getArray();
$this->m = $A->getRowDimension();
$this->n = $A->getColumnDimension();
// Main loop.

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Cell;
use PhpOffice\PhpSpreadsheet\Exception;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase;
@ -27,4 +28,26 @@ class CellTest extends TestCase
{
return require 'data/Cell/SetValueExplicit.php';
}
/**
* @dataProvider providerSetValueExplicitException
*
* @param mixed $expected
* @param mixed $value
* @param string $dataType
*/
public function testSetValueExplicitException($value, string $dataType)
{
$this->expectException(Exception::class);
$spreadsheet = new Spreadsheet();
$cell = $spreadsheet->getActiveSheet()->getCell('A1');
$cell->setValueExplicit($value, $dataType);
}
public function providerSetValueExplicitException()
{
return require 'data/Cell/SetValueExplicitException.php';
}
}

View File

@ -8,19 +8,44 @@ return [
'01234567890123456789',
DataType::TYPE_NUMERIC,
],
[
1234567890123456789,
1234567890123456789,
DataType::TYPE_NUMERIC,
],
[
123.456,
'123.456',
DataType::TYPE_NUMERIC,
],
[
1234567890123456789,
1234567890123456789,
123.456,
123.456,
DataType::TYPE_NUMERIC,
],
[
123.456,
123.456,
0,
null,
DataType::TYPE_NUMERIC,
],
[
0,
false,
DataType::TYPE_NUMERIC,
],
[
1,
true,
DataType::TYPE_NUMERIC,
],
[
'#DIV/0!',
'#DIV/0!',
DataType::TYPE_ERROR,
],
[
'#NULL!',
'NOT A VALID ERROR TYPE VALUE',
DataType::TYPE_ERROR,
],
];

View File

@ -0,0 +1,10 @@
<?php
use PhpOffice\PhpSpreadsheet\Cell\DataType;
return [
[
'XYZ',
DataType::TYPE_NUMERIC,
],
];