mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-24 06:58:31 +00:00
ffdae8efac
* Update Some Doc Block Annotations See PR #2010. That PR was never completed, and has gone stale. However, it was correct in identifying a situation where the doc block was not entirely accurate. It did not go far enough - several closely-related methods have similar problems. This PR attempts to fix the original problem and its close relations. Aside from the doc block changes, there are very minor changes to executable code. It also changes some of the unit tests targeted at the methods in question to eliminate mocking in favor of 'real' tests. * Change Method to Static Otherwise Scrutinizer will complain, even though Phpstan doesn't. * Scrutinizer Various clean-up activities. * Scrutinizer @#&$(*#&$ Got complexity down from 53 to (I think) 50. Don't really know what the target is. * Code Changes Suggested By Review Some improvements suggested in review by @PowerKiKi. * Update Cells.php * Merge Conflict A change to a parameter name caused several problems when trying to fix it on Github. Fixing it locally should do the trick. * Merge Conflicts in Phpstan Baseline PR #2382 made a large number of changes to Phpstan Baseline, some of which conflicted with the Phpstan Baseline changes in this PR. This should resolve them all.
91 lines
2.4 KiB
PHP
91 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Cell;
|
|
|
|
use DateTime;
|
|
use DateTimeImmutable;
|
|
use PhpOffice\PhpSpreadsheet\Cell\DataType;
|
|
use PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder;
|
|
use PhpOffice\PhpSpreadsheet\RichText\RichText;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class DefaultValueBinderTest extends TestCase
|
|
{
|
|
/**
|
|
* @dataProvider binderProvider
|
|
*
|
|
* @param mixed $value
|
|
*/
|
|
public function testBindValue($value): void
|
|
{
|
|
$spreadsheet = new Spreadsheet();
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
$cell = $sheet->getCell('A1');
|
|
$binder = new DefaultValueBinder();
|
|
$result = $binder->bindValue($cell, $value);
|
|
self::assertTrue($result);
|
|
$spreadsheet->disconnectWorksheets();
|
|
}
|
|
|
|
public function binderProvider(): array
|
|
{
|
|
return [
|
|
[null],
|
|
[''],
|
|
['ABC'],
|
|
['=SUM(A1:B2)'],
|
|
[true],
|
|
[false],
|
|
[123],
|
|
[-123.456],
|
|
['123'],
|
|
['-123.456'],
|
|
['#REF!'],
|
|
[new DateTime()],
|
|
[new DateTimeImmutable()],
|
|
['123456\n'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerDataTypeForValue
|
|
*
|
|
* @param mixed $expectedResult
|
|
* @param mixed $value
|
|
*/
|
|
public function testDataTypeForValue($expectedResult, $value): void
|
|
{
|
|
$result = DefaultValueBinder::dataTypeForValue($value);
|
|
self::assertEquals($expectedResult, $result);
|
|
}
|
|
|
|
public function providerDataTypeForValue(): array
|
|
{
|
|
return require 'tests/data/Cell/DefaultValueBinder.php';
|
|
}
|
|
|
|
public function testDataTypeForRichTextObject(): void
|
|
{
|
|
$objRichText = new RichText();
|
|
$objRichText->createText('Hello World');
|
|
|
|
$expectedResult = DataType::TYPE_INLINE;
|
|
$result = DefaultValueBinder::dataTypeForValue($objRichText);
|
|
self::assertEquals($expectedResult, $result);
|
|
}
|
|
|
|
public function testCanOverrideStaticMethodWithoutOverridingBindValue(): void
|
|
{
|
|
$spreadsheet = new Spreadsheet();
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
$cell = $sheet->getCell('A1');
|
|
$binder = new ValueBinderWithOverriddenDataTypeForValue();
|
|
|
|
self::assertFalse($binder::$called);
|
|
$binder->bindValue($cell, 123);
|
|
self::assertTrue($binder::$called);
|
|
$spreadsheet->disconnectWorksheets();
|
|
}
|
|
}
|