diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c3ef129..6aee7723 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - SUMIFS containing multiple conditions - [#704](https://github.com/PHPOffice/PhpSpreadsheet/issues/704) - Csv reader avoid notice when the file is empty - [#743](https://github.com/PHPOffice/PhpSpreadsheet/pull/743) - Fix print area parser for XLSX reader - [#734](https://github.com/PHPOffice/PhpSpreadsheet/pull/734) +- Support overriding `DefaultValueBinder::dataTypeForValue()` without overriding `DefaultValueBinder::bindValue()` - [#735](https://github.com/PHPOffice/PhpSpreadsheet/pull/735) ## [1.5.0] - 2018-10-21 diff --git a/src/PhpSpreadsheet/Cell/DefaultValueBinder.php b/src/PhpSpreadsheet/Cell/DefaultValueBinder.php index 0e35ae2f..7cbb6cca 100644 --- a/src/PhpSpreadsheet/Cell/DefaultValueBinder.php +++ b/src/PhpSpreadsheet/Cell/DefaultValueBinder.php @@ -31,7 +31,7 @@ class DefaultValueBinder implements IValueBinder } // Set value explicit - $cell->setValueExplicit($value, self::dataTypeForValue($value)); + $cell->setValueExplicit($value, static::dataTypeForValue($value)); // Done! return true; diff --git a/tests/PhpSpreadsheetTests/Cell/DefaultValueBinderTest.php b/tests/PhpSpreadsheetTests/Cell/DefaultValueBinderTest.php index 356a7212..d116fb99 100644 --- a/tests/PhpSpreadsheetTests/Cell/DefaultValueBinderTest.php +++ b/tests/PhpSpreadsheetTests/Cell/DefaultValueBinderTest.php @@ -12,18 +12,20 @@ use PHPUnit\Framework\TestCase; class DefaultValueBinderTest extends TestCase { - private $cellStub; - private function createCellStub() { // Create a stub for the Cell class. - $this->cellStub = $this->getMockBuilder(Cell::class) + /** @var Cell $cellStub */ + $cellStub = $this->getMockBuilder(Cell::class) ->disableOriginalConstructor() ->getMock(); + // Configure the stub. - $this->cellStub->expects($this->any()) + $cellStub->expects($this->any()) ->method('setValueExplicit') ->will($this->returnValue(true)); + + return $cellStub; } /** @@ -33,9 +35,9 @@ class DefaultValueBinderTest extends TestCase */ public function testBindValue($value) { - $this->createCellStub(); + $cellStub = $this->createCellStub(); $binder = new DefaultValueBinder(); - $result = $binder->bindValue($this->cellStub, $value); + $result = $binder->bindValue($cellStub, $value); self::assertTrue($result); } @@ -83,4 +85,14 @@ class DefaultValueBinderTest extends TestCase $result = DefaultValueBinder::dataTypeForValue($objRichText); self::assertEquals($expectedResult, $result); } + + public function testCanOverrideStaticMethodWithoutOverridingBindValue() + { + $cellStub = $this->createCellStub(); + $binder = new ValueBinderWithOverriddenDataTypeForValue(); + + self::assertFalse($binder::$called); + $binder->bindValue($cellStub, 123); + self::assertTrue($binder::$called); + } } diff --git a/tests/PhpSpreadsheetTests/Cell/ValueBinderWithOverriddenDataTypeForValue.php b/tests/PhpSpreadsheetTests/Cell/ValueBinderWithOverriddenDataTypeForValue.php new file mode 100644 index 00000000..d1b025a9 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Cell/ValueBinderWithOverriddenDataTypeForValue.php @@ -0,0 +1,17 @@ +