PhpSpreadsheet/tests/PhpSpreadsheetTests/Cell/DefaultValueBinderTest.php

88 lines
2.2 KiB
PHP
Raw Normal View History

2015-03-27 21:28:26 +00:00
<?php
namespace PhpSpreadsheetTests\Cell;
2015-03-27 21:28:26 +00:00
use PhpSpreadsheet\Cell;
use PhpSpreadsheet\Cell\DataType;
use PhpSpreadsheet\Cell\DefaultValueBinder;
use PhpSpreadsheet\RichText;
2016-03-22 14:35:50 +00:00
class DefaultValueBinderTest extends \PHPUnit_Framework_TestCase
2015-03-27 21:28:26 +00:00
{
protected $cellStub;
2015-03-27 21:28:26 +00:00
public function setUp()
{
if (!defined('PHPSPREADSHEET_ROOT')) {
define('PHPSPREADSHEET_ROOT', APPLICATION_PATH . '/');
2015-03-27 21:28:26 +00:00
}
require_once PHPSPREADSHEET_ROOT . '/Bootstrap.php';
2015-05-17 13:00:02 +00:00
}
2015-03-27 21:28:26 +00:00
protected function createCellStub()
{
// Create a stub for the Cell class.
$this->cellStub = $this->getMockBuilder(Cell::class)
->disableOriginalConstructor()
->getMock();
// Configure the stub.
$this->cellStub->expects($this->any())
->method('setValueExplicit')
->will($this->returnValue(true));
}
/**
* @dataProvider binderProvider
*/
public function testBindValue($value)
2015-05-17 13:00:02 +00:00
{
$this->createCellStub();
$binder = new DefaultValueBinder();
2015-05-17 13:00:02 +00:00
$result = $binder->bindValue($this->cellStub, $value);
$this->assertTrue($result);
}
public function binderProvider()
{
return [
[null],
[''],
['ABC'],
['=SUM(A1:B2)'],
[true],
[false],
[123],
[-123.456],
['123'],
['-123.456'],
['#REF!'],
[new \DateTime()],
];
}
2015-03-27 21:28:26 +00:00
/**
* @dataProvider providerDataTypeForValue
*/
2015-05-17 13:00:02 +00:00
public function testDataTypeForValue()
{
list($args, $expectedResult) = func_get_args();
$result = call_user_func_array([DefaultValueBinder::class, 'dataTypeForValue'], $args);
2015-05-17 13:00:02 +00:00
$this->assertEquals($expectedResult, $result);
}
2015-03-27 21:28:26 +00:00
public function providerDataTypeForValue()
{
return require 'data/Cell/DefaultValueBinder.php';
2015-05-17 13:00:02 +00:00
}
2015-03-27 21:28:26 +00:00
2015-05-17 13:00:02 +00:00
public function testDataTypeForRichTextObject()
{
$objRichText = new RichText();
$objRichText->createText('Hello World');
$expectedResult = DataType::TYPE_INLINE;
$result = DefaultValueBinder::dataTypeForValue($objRichText);
2015-05-17 13:00:02 +00:00
$this->assertEquals($expectedResult, $result);
}
2015-03-27 21:28:26 +00:00
}