Completed
Push — develop ( 682b1b...fe73b2 )
by Adrien
20:00
created

DefaultValueBinderTest::setUp()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 7
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests\Cell;
4
5
use PhpOffice\PhpSpreadsheet\Cell;
6
use PhpOffice\PhpSpreadsheet\Cell\DataType;
7
use PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder;
8
use PhpOffice\PhpSpreadsheet\RichText;
9
10
class DefaultValueBinderTest extends \PHPUnit_Framework_TestCase
11
{
12
    protected $cellStub;
13
14
    protected function createCellStub()
15
    {
16
        // Create a stub for the Cell class.
17
        $this->cellStub = $this->getMockBuilder(Cell::class)
18
            ->disableOriginalConstructor()
19
            ->getMock();
20
        // Configure the stub.
21
        $this->cellStub->expects($this->any())
22
            ->method('setValueExplicit')
23
            ->will($this->returnValue(true));
24
    }
25
26
    /**
27
     * @dataProvider binderProvider
28
     *
29
     * @param mixed $value
30
     */
31
    public function testBindValue($value)
32
    {
33
        $this->createCellStub();
34
        $binder = new DefaultValueBinder();
35
        $result = $binder->bindValue($this->cellStub, $value);
36
        $this->assertTrue($result);
37
    }
38
39
    public function binderProvider()
40
    {
41
        return [
42
            [null],
43
            [''],
44
            ['ABC'],
45
            ['=SUM(A1:B2)'],
46
            [true],
47
            [false],
48
            [123],
49
            [-123.456],
50
            ['123'],
51
            ['-123.456'],
52
            ['#REF!'],
53
            [new \DateTime()],
54
        ];
55
    }
56
57
    /**
58
     * @dataProvider providerDataTypeForValue
59
     *
60
     * @param mixed $expectedResult
61
     */
62
    public function testDataTypeForValue($expectedResult, ...$args)
63
    {
64
        $result = DefaultValueBinder::dataTypeForValue(...$args);
65
        $this->assertEquals($expectedResult, $result);
66
    }
67
68
    public function providerDataTypeForValue()
69
    {
70
        return require 'data/Cell/DefaultValueBinder.php';
71
    }
72
73
    public function testDataTypeForRichTextObject()
74
    {
75
        $objRichText = new RichText();
76
        $objRichText->createText('Hello World');
77
78
        $expectedResult = DataType::TYPE_INLINE;
79
        $result = DefaultValueBinder::dataTypeForValue($objRichText);
80
        $this->assertEquals($expectedResult, $result);
81
    }
82
}
83