Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / dbal / tests / Doctrine / Tests / DBAL / Schema / ColumnTest.php
1 <?php
2
3 namespace Doctrine\Tests\DBAL\Schema;
4
5 require_once __DIR__ . '/../../TestInit.php';
6
7 use Doctrine\DBAL\Schema\Schema;
8 use Doctrine\DBAL\Schema\Table;
9 use Doctrine\DBAL\Schema\Column;
10 use Doctrine\DBAL\Types\Type;
11
12 class ColumnTest extends \PHPUnit_Framework_TestCase
13 {
14     public function testGet()
15     {
16         $column = $this->createColumn();
17
18         $this->assertEquals("foo", $column->getName());
19         $this->assertSame(Type::getType('string'), $column->getType());
20
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());
28
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'));
33
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'));
38     }
39
40     public function testToArray()
41     {
42         $expected = array(
43             'name' => 'foo',
44             'type' => Type::getType('string'),
45             'default' => 'baz',
46             'notnull' => false,
47             'length' => 200,
48             'precision' => 5,
49             'scale' => 2,
50             'fixed' => true,
51             'unsigned' => true,
52             'autoincrement' => false,
53             'columnDefinition' => null,
54             'comment' => null,
55             'foo' => 'bar',
56             'bar' => 'baz'
57         );
58
59         $this->assertEquals($expected, $this->createColumn()->toArray());
60     }
61
62     /**
63      * @return Column
64      */
65     public function createColumn()
66     {
67         $options = array(
68             'length' => 200,
69             'precision' => 5,
70             'scale' => 2,
71             'unsigned' => true,
72             'notnull' => false,
73             'fixed' => true,
74             'default' => 'baz',
75             'platformOptions' => array('foo' => 'bar'),
76             'customSchemaOptions' => array('bar' => 'baz'),
77         );
78
79         $string = Type::getType('string');
80         return new Column("foo", $string, $options);
81     }
82
83     /**
84      * @group DBAL-64
85      */
86     public function testQuotedColumnName()
87     {
88         $string = Type::getType('string');
89         $column = new Column("`bar`", $string, array());
90
91         $mysqlPlatform = new \Doctrine\DBAL\Platforms\MySqlPlatform();
92         $sqlitePlatform = new \Doctrine\DBAL\Platforms\SqlitePlatform();
93
94         $this->assertEquals('bar', $column->getName());
95         $this->assertEquals('`bar`', $column->getQuotedName($mysqlPlatform));
96         $this->assertEquals('"bar"', $column->getQuotedName($sqlitePlatform));
97     }
98
99     /**
100      * @group DBAL-42
101      */
102     public function testColumnComment()
103     {
104         $column = new Column("bar", Type::getType('string'));
105         $this->assertNull($column->getComment());
106
107         $column->setComment("foo");
108         $this->assertEquals("foo", $column->getComment());
109
110         $columnArray = $column->toArray();
111         $this->assertArrayHasKey('comment', $columnArray);
112         $this->assertEquals('foo', $columnArray['comment']);
113     }
114 }