2009-11-27 00:56:08 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\DBAL\Schema;
|
|
|
|
|
|
|
|
require_once __DIR__ . '/../../TestInit.php';
|
|
|
|
|
|
|
|
use Doctrine\DBAL\Schema\Schema;
|
|
|
|
use Doctrine\DBAL\Schema\Table;
|
|
|
|
use Doctrine\DBAL\Schema\Column;
|
|
|
|
use Doctrine\DBAL\Types\Type;
|
|
|
|
|
|
|
|
class ColumnTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
public function testGet()
|
|
|
|
{
|
2009-12-06 12:47:54 +03:00
|
|
|
$column = $this->createColumn();
|
2009-11-27 00:56:08 +03:00
|
|
|
|
|
|
|
$this->assertEquals("foo", $column->getName());
|
2009-12-06 12:47:54 +03:00
|
|
|
$this->assertSame(Type::getType('string'), $column->getType());
|
2009-11-27 00:56:08 +03:00
|
|
|
|
|
|
|
$this->assertEquals(200, $column->getLength());
|
|
|
|
$this->assertEquals(5, $column->getPrecision());
|
|
|
|
$this->assertEquals(2, $column->getScale());
|
|
|
|
$this->assertTrue($column->getUnsigned());
|
|
|
|
$this->assertFalse($column->getNotNull());
|
|
|
|
$this->assertTrue($column->getFixed());
|
|
|
|
$this->assertEquals("baz", $column->getDefault());
|
|
|
|
|
|
|
|
$this->assertEquals(array('foo' => 'bar'), $column->getPlatformOptions());
|
2009-11-28 01:00:43 +03:00
|
|
|
$this->assertTrue($column->hasPlatformOption('foo'));
|
|
|
|
$this->assertEquals('bar', $column->getPlatformOption('foo'));
|
|
|
|
$this->assertFalse($column->hasPlatformOption('bar'));
|
2009-11-27 00:56:08 +03:00
|
|
|
}
|
2009-12-06 12:47:54 +03:00
|
|
|
|
|
|
|
public function testToArray()
|
|
|
|
{
|
|
|
|
$expected = array(
|
|
|
|
'name' => 'foo',
|
|
|
|
'type' => Type::getType('string'),
|
|
|
|
'default' => 'baz',
|
|
|
|
'notnull' => false,
|
|
|
|
'length' => 200,
|
|
|
|
'precision' => 5,
|
|
|
|
'scale' => 2,
|
|
|
|
'fixed' => true,
|
|
|
|
'unsigned' => true,
|
2010-01-21 01:35:18 +03:00
|
|
|
'columnDefinition' => null,
|
2009-12-06 12:47:54 +03:00
|
|
|
'foo' => 'bar',
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $this->createColumn()->toArray());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Column
|
|
|
|
*/
|
|
|
|
public function createColumn()
|
|
|
|
{
|
|
|
|
$options = array(
|
|
|
|
'length' => 200,
|
|
|
|
'precision' => 5,
|
|
|
|
'scale' => 2,
|
|
|
|
'unsigned' => true,
|
|
|
|
'notnull' => false,
|
|
|
|
'fixed' => true,
|
|
|
|
'default' => 'baz',
|
|
|
|
'platformOptions' => array('foo' => 'bar'),
|
|
|
|
);
|
|
|
|
|
|
|
|
$string = Type::getType('string');
|
|
|
|
return new Column("foo", $string, $options);
|
|
|
|
}
|
2009-11-27 00:56:08 +03:00
|
|
|
}
|