Passed
Push — develop ( fdc224...3be06a )
by Adrien
39:01
created

DefaultValueBinderTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 39
dl 0
loc 84
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testBindValue() 0 6 1
A testCanOverrideStaticMethodWithoutOverridingBindValue() 0 8 1
A providerDataTypeForValue() 0 3 1
A testDataTypeForValue() 0 4 1
A createCellStub() 0 14 1
A testDataTypeForRichTextObject() 0 8 1
A binderProvider() 0 16 1
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())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on PhpOffice\PhpSpreadsheet\Cell\Cell. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
        $cellStub->/** @scrutinizer ignore-call */ 
25
                   expects($this->any())

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.

Loading history...
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);
1 ignored issue
show
Bug introduced by
$args is expanded, but the parameter $pValue of PhpOffice\PhpSpreadsheet...der::dataTypeForValue() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

70
        $result = DefaultValueBinder::dataTypeForValue(/** @scrutinizer ignore-type */ ...$args);
Loading history...
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