Addtional unit tests for vlue binders

This commit is contained in:
MarkBaker 2021-06-03 14:10:28 +02:00 committed by Mark Baker
parent 89eac0feed
commit 3297f503c2
3 changed files with 24 additions and 0 deletions

View File

@ -26,6 +26,7 @@ class DefaultValueBinder implements IValueBinder
if ($value instanceof DateTimeInterface) { if ($value instanceof DateTimeInterface) {
$value = $value->format('Y-m-d H:i:s'); $value = $value->format('Y-m-d H:i:s');
} elseif (!($value instanceof RichText)) { } elseif (!($value instanceof RichText)) {
// Attempt to cast any unexpected objects to string
$value = (string) $value; $value = (string) $value;
} }
} }

View File

@ -9,6 +9,7 @@ use PhpOffice\PhpSpreadsheet\Collection\Cells;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat; use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class AdvancedValueBinderTest extends TestCase class AdvancedValueBinderTest extends TestCase
@ -42,6 +43,23 @@ class AdvancedValueBinderTest extends TestCase
StringHelper::setThousandsSeparator($this->thousandsSeparator); StringHelper::setThousandsSeparator($this->thousandsSeparator);
} }
public function testNullValue()
{
/** @var Cell&MockObject $cellStub */
$cellStub = $this->getMockBuilder(Cell::class)
->disableOriginalConstructor()
->getMock();
// Configure the stub.
$cellStub->expects(self::once())
->method('setValueExplicit')
->with(null, DataType::TYPE_NULL)
->willReturn(true);
$binder = new AdvancedValueBinder();
$binder->bindValue($cellStub, null);
}
/** /**
* @dataProvider currencyProvider * @dataProvider currencyProvider
* *
@ -105,6 +123,7 @@ class AdvancedValueBinderTest extends TestCase
['€2.020,20', 2020.2, $currencyEURO, '.', ',', '€'], ['€2.020,20', 2020.2, $currencyEURO, '.', ',', '€'],
['€ 2.020,20', 2020.2, $currencyEURO, '.', ',', '€'], ['€ 2.020,20', 2020.2, $currencyEURO, '.', ',', '€'],
['€2,020.22', 2020.22, $currencyEURO, ',', '.', '€'], ['€2,020.22', 2020.22, $currencyEURO, ',', '.', '€'],
['$10.11', 10.11, $currencyUSD, ',', '.', '€'],
]; ];
} }

View File

@ -77,4 +77,8 @@ return [
's', 's',
'123456\n', '123456\n',
], ],
'Numeric that exceeds PHP MAX_INT Size' => [
's',
'1234567890123459012345689012345690',
]
]; ];