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

DefaultValueBinderTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 73
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 4

6 Methods

Rating   Name   Duplication   Size   Complexity  
A createCellStub() 0 11 1
A testBindValue() 0 7 1
A binderProvider() 0 17 1
A testDataTypeForValue() 0 5 1
A providerDataTypeForValue() 0 4 1
A testDataTypeForRichTextObject() 0 9 1
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