Skip to content

Commit 3be06a5

Browse files
midlanPowerKiKi
authored andcommitted
Support overriding DefaultValueBinder::dataTypeForValue()
This allow to avoid overriding `DefaultValueBinder::bindValue()` Fixes #735
1 parent fdc224a commit 3be06a5

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
1313
- SUMIFS containing multiple conditions - [#704](https://github.com/PHPOffice/PhpSpreadsheet/issues/704)
1414
- Csv reader avoid notice when the file is empty - [#743](https://github.com/PHPOffice/PhpSpreadsheet/pull/743)
1515
- Fix print area parser for XLSX reader - [#734](https://github.com/PHPOffice/PhpSpreadsheet/pull/734)
16+
- Support overriding `DefaultValueBinder::dataTypeForValue()` without overriding `DefaultValueBinder::bindValue()` - [#735](https://github.com/PHPOffice/PhpSpreadsheet/pull/735)
1617

1718
## [1.5.0] - 2018-10-21
1819

src/PhpSpreadsheet/Cell/DefaultValueBinder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function bindValue(Cell $cell, $value)
3131
}
3232

3333
// Set value explicit
34-
$cell->setValueExplicit($value, self::dataTypeForValue($value));
34+
$cell->setValueExplicit($value, static::dataTypeForValue($value));
3535

3636
// Done!
3737
return true;

tests/PhpSpreadsheetTests/Cell/DefaultValueBinderTest.php

+18-6
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@
1212

1313
class DefaultValueBinderTest extends TestCase
1414
{
15-
private $cellStub;
16-
1715
private function createCellStub()
1816
{
1917
// Create a stub for the Cell class.
20-
$this->cellStub = $this->getMockBuilder(Cell::class)
18+
/** @var Cell $cellStub */
19+
$cellStub = $this->getMockBuilder(Cell::class)
2120
->disableOriginalConstructor()
2221
->getMock();
22+
2323
// Configure the stub.
24-
$this->cellStub->expects($this->any())
24+
$cellStub->expects($this->any())
2525
->method('setValueExplicit')
2626
->will($this->returnValue(true));
27+
28+
return $cellStub;
2729
}
2830

2931
/**
@@ -33,9 +35,9 @@ private function createCellStub()
3335
*/
3436
public function testBindValue($value)
3537
{
36-
$this->createCellStub();
38+
$cellStub = $this->createCellStub();
3739
$binder = new DefaultValueBinder();
38-
$result = $binder->bindValue($this->cellStub, $value);
40+
$result = $binder->bindValue($cellStub, $value);
3941
self::assertTrue($result);
4042
}
4143

@@ -83,4 +85,14 @@ public function testDataTypeForRichTextObject()
8385
$result = DefaultValueBinder::dataTypeForValue($objRichText);
8486
self::assertEquals($expectedResult, $result);
8587
}
88+
89+
public function testCanOverrideStaticMethodWithoutOverridingBindValue()
90+
{
91+
$cellStub = $this->createCellStub();
92+
$binder = new ValueBinderWithOverriddenDataTypeForValue();
93+
94+
self::assertFalse($binder::$called);
95+
$binder->bindValue($cellStub, 123);
96+
self::assertTrue($binder::$called);
97+
}
8698
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace PhpOffice\PhpSpreadsheetTests\Cell;
4+
5+
use PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder;
6+
7+
class ValueBinderWithOverriddenDataTypeForValue extends DefaultValueBinder
8+
{
9+
public static $called = false;
10+
11+
public static function dataTypeForValue($pValue)
12+
{
13+
self::$called = true;
14+
15+
return parent::dataTypeForValue($pValue);
16+
}
17+
}

0 commit comments

Comments
 (0)