3 namespace Doctrine\Tests\DBAL\Schema;
5 require_once __DIR__ . '/../../TestInit.php';
7 use Doctrine\DBAL\Schema\Schema;
8 use Doctrine\DBAL\Schema\Table;
9 use Doctrine\DBAL\Schema\Column;
10 use Doctrine\DBAL\Types\Type;
12 class ColumnTest extends \PHPUnit_Framework_TestCase
14 public function testGet()
16 $column = $this->createColumn();
18 $this->assertEquals("foo", $column->getName());
19 $this->assertSame(Type::getType('string'), $column->getType());
21 $this->assertEquals(200, $column->getLength());
22 $this->assertEquals(5, $column->getPrecision());
23 $this->assertEquals(2, $column->getScale());
24 $this->assertTrue($column->getUnsigned());
25 $this->assertFalse($column->getNotNull());
26 $this->assertTrue($column->getFixed());
27 $this->assertEquals("baz", $column->getDefault());
29 $this->assertEquals(array('foo' => 'bar'), $column->getPlatformOptions());
30 $this->assertTrue($column->hasPlatformOption('foo'));
31 $this->assertEquals('bar', $column->getPlatformOption('foo'));
32 $this->assertFalse($column->hasPlatformOption('bar'));
34 $this->assertEquals(array('bar' => 'baz'), $column->getCustomSchemaOptions());
35 $this->assertTrue($column->hasCustomSchemaOption('bar'));
36 $this->assertEquals('baz', $column->getCustomSchemaOption('bar'));
37 $this->assertFalse($column->hasCustomSchemaOption('foo'));
40 public function testToArray()
44 'type' => Type::getType('string'),
52 'autoincrement' => false,
53 'columnDefinition' => null,
59 $this->assertEquals($expected, $this->createColumn()->toArray());
65 public function createColumn()
75 'platformOptions' => array('foo' => 'bar'),
76 'customSchemaOptions' => array('bar' => 'baz'),
79 $string = Type::getType('string');
80 return new Column("foo", $string, $options);
86 public function testQuotedColumnName()
88 $string = Type::getType('string');
89 $column = new Column("`bar`", $string, array());
91 $mysqlPlatform = new \Doctrine\DBAL\Platforms\MySqlPlatform();
92 $sqlitePlatform = new \Doctrine\DBAL\Platforms\SqlitePlatform();
94 $this->assertEquals('bar', $column->getName());
95 $this->assertEquals('`bar`', $column->getQuotedName($mysqlPlatform));
96 $this->assertEquals('"bar"', $column->getQuotedName($sqlitePlatform));
102 public function testColumnComment()
104 $column = new Column("bar", Type::getType('string'));
105 $this->assertNull($column->getComment());
107 $column->setComment("foo");
108 $this->assertEquals("foo", $column->getComment());
110 $columnArray = $column->toArray();
111 $this->assertArrayHasKey('comment', $columnArray);
112 $this->assertEquals('foo', $columnArray['comment']);