 aed27a0bed
			
		
	
	
		aed27a0bed
		
	
	
	
	
		
			
			Use the `PHPUnit\Framework\TestCase` notation instead of `PHPUnit_Framework_TestCase` while extending our TestCases. This will help us migrate to PHPUnit 6, that [no longer support snake case class names](https://github.com/sebastianbergmann/phpunit/blob/master/ChangeLog-6.0.md#changed-1).
		
			
				
	
	
		
			85 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			85 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace PhpOffice\PhpSpreadsheetTests\Cell;
 | |
| 
 | |
| use DateTime;
 | |
| use PhpOffice\PhpSpreadsheet\Cell\Cell;
 | |
| use PhpOffice\PhpSpreadsheet\Cell\DataType;
 | |
| use PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder;
 | |
| use PhpOffice\PhpSpreadsheet\RichText\RichText;
 | |
| use PHPUnit\Framework\TestCase;
 | |
| 
 | |
| class DefaultValueBinderTest extends TestCase
 | |
| {
 | |
|     protected $cellStub;
 | |
| 
 | |
|     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
 | |
|      *
 | |
|      * @param mixed $value
 | |
|      */
 | |
|     public function testBindValue($value)
 | |
|     {
 | |
|         $this->createCellStub();
 | |
|         $binder = new DefaultValueBinder();
 | |
|         $result = $binder->bindValue($this->cellStub, $value);
 | |
|         self::assertTrue($result);
 | |
|     }
 | |
| 
 | |
|     public function binderProvider()
 | |
|     {
 | |
|         return [
 | |
|             [null],
 | |
|             [''],
 | |
|             ['ABC'],
 | |
|             ['=SUM(A1:B2)'],
 | |
|             [true],
 | |
|             [false],
 | |
|             [123],
 | |
|             [-123.456],
 | |
|             ['123'],
 | |
|             ['-123.456'],
 | |
|             ['#REF!'],
 | |
|             [new DateTime()],
 | |
|         ];
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @dataProvider providerDataTypeForValue
 | |
|      *
 | |
|      * @param mixed $expectedResult
 | |
|      */
 | |
|     public function testDataTypeForValue($expectedResult, ...$args)
 | |
|     {
 | |
|         $result = DefaultValueBinder::dataTypeForValue(...$args);
 | |
|         self::assertEquals($expectedResult, $result);
 | |
|     }
 | |
| 
 | |
|     public function providerDataTypeForValue()
 | |
|     {
 | |
|         return require 'data/Cell/DefaultValueBinder.php';
 | |
|     }
 | |
| 
 | |
|     public function testDataTypeForRichTextObject()
 | |
|     {
 | |
|         $objRichText = new RichText();
 | |
|         $objRichText->createText('Hello World');
 | |
| 
 | |
|         $expectedResult = DataType::TYPE_INLINE;
 | |
|         $result = DefaultValueBinder::dataTypeForValue($objRichText);
 | |
|         self::assertEquals($expectedResult, $result);
 | |
|     }
 | |
| }
 |