1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Cell; |
4
|
|
|
|
5
|
|
|
use DateTime; |
6
|
|
|
use DateTimeImmutable; |
7
|
|
|
use PhpOffice\PhpSpreadsheet\Cell\Cell; |
8
|
|
|
use PhpOffice\PhpSpreadsheet\Cell\DataType; |
9
|
|
|
use PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder; |
10
|
|
|
use PhpOffice\PhpSpreadsheet\RichText\RichText; |
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
|
13
|
|
|
class DefaultValueBinderTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
private function createCellStub() |
16
|
|
|
{ |
17
|
|
|
// Create a stub for the Cell class. |
18
|
|
|
/** @var Cell $cellStub */ |
19
|
|
|
$cellStub = $this->getMockBuilder(Cell::class) |
20
|
|
|
->disableOriginalConstructor() |
21
|
|
|
->getMock(); |
22
|
|
|
|
23
|
|
|
// Configure the stub. |
24
|
|
|
$cellStub->expects($this->any()) |
|
|
|
|
25
|
|
|
->method('setValueExplicit') |
26
|
|
|
->will($this->returnValue(true)); |
27
|
|
|
|
28
|
|
|
return $cellStub; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @dataProvider binderProvider |
33
|
|
|
* |
34
|
|
|
* @param mixed $value |
35
|
|
|
*/ |
36
|
|
|
public function testBindValue($value) |
37
|
|
|
{ |
38
|
|
|
$cellStub = $this->createCellStub(); |
39
|
|
|
$binder = new DefaultValueBinder(); |
40
|
|
|
$result = $binder->bindValue($cellStub, $value); |
41
|
|
|
self::assertTrue($result); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function binderProvider() |
45
|
|
|
{ |
46
|
|
|
return [ |
47
|
|
|
[null], |
48
|
|
|
[''], |
49
|
|
|
['ABC'], |
50
|
|
|
['=SUM(A1:B2)'], |
51
|
|
|
[true], |
52
|
|
|
[false], |
53
|
|
|
[123], |
54
|
|
|
[-123.456], |
55
|
|
|
['123'], |
56
|
|
|
['-123.456'], |
57
|
|
|
['#REF!'], |
58
|
|
|
[new DateTime()], |
59
|
|
|
[new DateTimeImmutable()], |
60
|
|
|
]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @dataProvider providerDataTypeForValue |
65
|
|
|
* |
66
|
|
|
* @param mixed $expectedResult |
67
|
|
|
*/ |
68
|
|
|
public function testDataTypeForValue($expectedResult, ...$args) |
69
|
|
|
{ |
70
|
|
|
$result = DefaultValueBinder::dataTypeForValue(...$args); |
|
|
|
|
71
|
|
|
self::assertEquals($expectedResult, $result); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function providerDataTypeForValue() |
75
|
|
|
{ |
76
|
|
|
return require 'data/Cell/DefaultValueBinder.php'; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function testDataTypeForRichTextObject() |
80
|
|
|
{ |
81
|
|
|
$objRichText = new RichText(); |
82
|
|
|
$objRichText->createText('Hello World'); |
83
|
|
|
|
84
|
|
|
$expectedResult = DataType::TYPE_INLINE; |
85
|
|
|
$result = DefaultValueBinder::dataTypeForValue($objRichText); |
86
|
|
|
self::assertEquals($expectedResult, $result); |
87
|
|
|
} |
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
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.