ColumnSchemaTest.php 846 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
<?php

namespace yiiunit\extensions\sphinx;

use yii\sphinx\ColumnSchema;

/**
 * @group sphinx
 */
class ColumnSchemaTest extends SphinxTestCase
{
	/**
	 * Data provider for [[testTypeCast]]
	 * @return array test data.
	 */
	public function dataProviderTypeCast()
	{
		return [
			[
				'integer',
				'integer',
				5,
				5
			],
			[
				'integer',
				'integer',
				'5',
				5
			],
			[
				'string',
				'string',
				5,
				'5'
			],
		];
	}

	/**
	 * @dataProvider dataProviderTypeCast
	 *
	 * @param $type
	 * @param $phpType
	 * @param $value
	 * @param $expectedResult
	 */
	public function testTypeCast($type, $phpType, $value, $expectedResult)
	{
		$columnSchema = new ColumnSchema();
		$columnSchema->type = $type;
		$columnSchema->phpType = $phpType;
		$this->assertEquals($expectedResult, $columnSchema->typecast($value));
	}
}