Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / dbal / tests / Doctrine / Tests / DBAL / Schema / ComparatorTest.php
1 <?php
2 /*
3  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14  *
15  * This software consists of voluntary contributions made by many individuals
16  * and is licensed under the MIT license. For more information, see
17  * <http://www.doctrine-project.org>.
18  */
19
20 namespace Doctrine\Tests\DBAL\Schema;
21
22 require_once __DIR__ . '/../../TestInit.php';
23
24 use Doctrine\DBAL\Schema\Schema,
25     Doctrine\DBAL\Schema\SchemaConfig,
26     Doctrine\DBAL\Schema\Table,
27     Doctrine\DBAL\Schema\Column,
28     Doctrine\DBAL\Schema\Index,
29     Doctrine\DBAL\Schema\Sequence,
30     Doctrine\DBAL\Schema\SchemaDiff,
31     Doctrine\DBAL\Schema\TableDiff,
32     Doctrine\DBAL\Schema\Comparator,
33     Doctrine\DBAL\Types\Type,
34     Doctrine\DBAL\Schema\ForeignKeyConstraint;
35
36 /**
37  * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
38  * @link    www.doctrine-project.org
39  * @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
40  * @license http://ez.no/licenses/new_bsd New BSD License
41  * @since   2.0
42  * @version $Revision$
43  * @author  Benjamin Eberlei <kontakt@beberlei.de>
44  */
45 class ComparatorTest extends \PHPUnit_Framework_TestCase
46 {
47     public function testCompareSame1()
48     {
49         $schema1 = new Schema( array(
50             'bugdb' => new Table('bugdb',
51                 array (
52                     'integerfield1' => new Column('integerfield1', Type::getType('integer' ) ),
53                 )
54             ),
55         ) );
56         $schema2 = new Schema( array(
57             'bugdb' => new Table('bugdb',
58                 array (
59                     'integerfield1' => new Column('integerfield1', Type::getType('integer') ),
60                 )
61             ),
62         ) );
63
64         $this->assertEquals(new SchemaDiff(), Comparator::compareSchemas( $schema1, $schema2 ) );
65     }
66
67     public function testCompareSame2()
68     {
69         $schema1 = new Schema( array(
70             'bugdb' => new Table('bugdb',
71                 array (
72                     'integerfield1' => new Column('integerfield1', Type::getType('integer')),
73                     'integerfield2' => new Column('integerfield2', Type::getType('integer')),
74                 )
75             ),
76         ) );
77         $schema2 = new Schema( array(
78             'bugdb' => new Table('bugdb',
79                 array (
80                     'integerfield2' => new Column('integerfield2', Type::getType('integer')),
81                     'integerfield1' => new Column('integerfield1', Type::getType('integer')),
82                 )
83             ),
84         ) );
85         $this->assertEquals(new SchemaDiff(), Comparator::compareSchemas( $schema1, $schema2 ) );
86     }
87
88     public function testCompareMissingTable()
89     {
90         $schemaConfig = new \Doctrine\DBAL\Schema\SchemaConfig;
91         $table = new Table('bugdb', array ('integerfield1' => new Column('integerfield1', Type::getType('integer'))));
92         $table->setSchemaConfig($schemaConfig);
93
94         $schema1 = new Schema( array($table), array(), $schemaConfig );
95         $schema2 = new Schema( array(),       array(), $schemaConfig );
96
97         $expected = new SchemaDiff( array(), array(), array('bugdb' => $table) );
98
99         $this->assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 ) );
100     }
101
102     public function testCompareNewTable()
103     {
104         $schemaConfig = new \Doctrine\DBAL\Schema\SchemaConfig;
105         $table = new Table('bugdb', array ('integerfield1' => new Column('integerfield1', Type::getType('integer'))));
106         $table->setSchemaConfig($schemaConfig);
107
108         $schema1 = new Schema( array(),       array(), $schemaConfig );
109         $schema2 = new Schema( array($table), array(), $schemaConfig );
110
111         $expected = new SchemaDiff( array('bugdb' => $table), array(), array() );
112         $this->assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 ) );
113     }
114
115     public function testCompareOnlyAutoincrementChanged()
116     {
117         $column1 = new Column('foo', Type::getType('integer'), array('autoincrement' => true));
118         $column2 = new Column('foo', Type::getType('integer'), array('autoincrement' => false));
119
120         $comparator = new Comparator();
121         $changedProperties = $comparator->diffColumn($column1, $column2);
122
123         $this->assertEquals(array('autoincrement'), $changedProperties);
124     }
125
126     public function testCompareMissingField()
127     {
128         $missingColumn = new Column('integerfield1', Type::getType('integer'));
129         $schema1 = new Schema( array(
130             'bugdb' => new Table('bugdb',
131                 array (
132                     'integerfield1' => $missingColumn,
133                     'integerfield2' => new Column('integerfield2', Type::getType('integer')),
134                 )
135             ),
136         ) );
137         $schema2 = new Schema( array(
138             'bugdb' => new Table('bugdb',
139                 array (
140                     'integerfield2' => new Column('integerfield2', Type::getType('integer')),
141                 )
142             ),
143         ) );
144
145         $expected = new SchemaDiff ( array(),
146             array (
147                 'bugdb' => new TableDiff( 'bugdb', array(), array(),
148                     array (
149                         'integerfield1' => $missingColumn,
150                     )
151                 )
152             )
153         );
154         $this->assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 ) );
155     }
156
157     public function testCompareNewField()
158     {
159         $schema1 = new Schema( array(
160             'bugdb' => new Table('bugdb',
161                 array (
162                     'integerfield1' => new Column('integerfield1', Type::getType('integer')),
163                 )
164             ),
165         ) );
166         $schema2 = new Schema( array(
167             'bugdb' => new Table('bugdb',
168                 array (
169                     'integerfield1' => new Column('integerfield1', Type::getType('integer')),
170                     'integerfield2' => new Column('integerfield2', Type::getType('integer')),
171                 )
172             ),
173         ) );
174
175         $expected = new SchemaDiff ( array(),
176             array (
177                 'bugdb' => new TableDiff ('bugdb',
178                     array (
179                         'integerfield2' => new Column('integerfield2', Type::getType('integer')),
180                     )
181                 ),
182             )
183         );
184         $this->assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 ) );
185     }
186
187     public function testCompareChangedColumns_ChangeType()
188     {
189         $column1 = new Column('charfield1', Type::getType('string'));
190         $column2 = new Column('charfield1', Type::getType('integer'));
191
192         $c = new Comparator();
193         $this->assertEquals(array('type'), $c->diffColumn($column1, $column2));
194         $this->assertEquals(array(), $c->diffColumn($column1, $column1));
195     }
196
197     public function testCompareChangedColumns_ChangeCustomSchemaOption()
198     {
199         $column1 = new Column('charfield1', Type::getType('string'));
200         $column2 = new Column('charfield1', Type::getType('string'));
201
202         $column1->setCustomSchemaOption('foo', 'bar');
203         $column2->setCustomSchemaOption('foo', 'bar');
204
205         $column1->setCustomSchemaOption('foo1', 'bar1');
206         $column2->setCustomSchemaOption('foo2', 'bar2');
207
208         $c = new Comparator();
209         $this->assertEquals(array('foo1', 'foo2'), $c->diffColumn($column1, $column2));
210         $this->assertEquals(array(), $c->diffColumn($column1, $column1));
211     }
212
213     public function testCompareRemovedIndex()
214     {
215         $schema1 = new Schema( array(
216             'bugdb' => new Table('bugdb',
217                 array (
218                     'integerfield1' => new Column('integerfield1', Type::getType('integer')),
219                     'integerfield2' => new Column('integerfield2', Type::getType('integer')),
220                 ),
221                 array (
222                     'primary' => new Index('primary',
223                         array(
224                             'integerfield1'
225                         ),
226                         true
227                     )
228                 )
229             ),
230         ) );
231         $schema2 = new Schema( array(
232             'bugdb' => new Table('bugdb',
233                 array (
234                     'integerfield1' => new Column('integerfield1', Type::getType('integer')),
235                     'integerfield2' => new Column('integerfield2', Type::getType('integer')),
236                 )
237             ),
238         ) );
239
240         $expected = new SchemaDiff ( array(),
241             array (
242                 'bugdb' => new TableDiff( 'bugdb', array(), array(), array(), array(), array(),
243                     array (
244                         'primary' => new Index('primary',
245                         array(
246                             'integerfield1'
247                         ),
248                         true
249                     )
250                     )
251                 ),
252             )
253         );
254         $this->assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 ) );
255     }
256
257     public function testCompareNewIndex()
258     {
259         $schema1 = new Schema( array(
260             'bugdb' => new Table('bugdb',
261                 array (
262                     'integerfield1' => new Column('integerfield1', Type::getType('integer')),
263                     'integerfield2' => new Column('integerfield2', Type::getType('integer')),
264                 )
265             ),
266         ) );
267         $schema2 = new Schema( array(
268             'bugdb' => new Table('bugdb',
269                 array (
270                     'integerfield1' => new Column('integerfield1', Type::getType('integer')),
271                     'integerfield2' => new Column('integerfield2', Type::getType('integer')),
272                 ),
273                 array (
274                     'primary' => new Index('primary',
275                         array(
276                             'integerfield1'
277                         ),
278                         true
279                     )
280                 )
281             ),
282         ) );
283
284         $expected = new SchemaDiff ( array(),
285             array (
286                 'bugdb' => new TableDiff( 'bugdb', array(), array(), array(),
287                     array (
288                         'primary' => new Index('primary',
289                             array(
290                                 'integerfield1'
291                             ),
292                             true
293                         )
294                     )
295                 ),
296             )
297         );
298         $this->assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 ) );
299     }
300
301     public function testCompareChangedIndex()
302     {
303         $schema1 = new Schema( array(
304             'bugdb' => new Table('bugdb',
305                 array (
306                     'integerfield1' => new Column('integerfield1', Type::getType('integer')),
307                     'integerfield2' => new Column('integerfield2', Type::getType('integer')),
308                 ),
309                 array (
310                     'primary' => new Index('primary',
311                         array(
312                             'integerfield1'
313                         ),
314                         true
315                     )
316                 )
317             ),
318         ) );
319         $schema2 = new Schema( array(
320             'bugdb' => new Table('bugdb',
321                 array (
322                     'integerfield1' => new Column('integerfield1', Type::getType('integer')),
323                     'integerfield2' => new Column('integerfield2', Type::getType('integer')),
324                 ),
325                 array (
326                     'primary' => new Index('primary',
327                         array('integerfield1', 'integerfield2'),
328                         true
329                     )
330                 )
331             ),
332         ) );
333
334         $expected = new SchemaDiff ( array(),
335             array (
336                 'bugdb' => new TableDiff( 'bugdb', array(), array(), array(), array(),
337                     array (
338                         'primary' => new Index('primary',
339                             array(
340                                 'integerfield1',
341                                 'integerfield2'
342                             ),
343                             true
344                         )
345                     )
346                 ),
347             )
348         );
349         $actual = Comparator::compareSchemas( $schema1, $schema2 );
350         $this->assertEquals($expected, $actual);
351     }
352
353     public function testCompareChangedIndexFieldPositions()
354     {
355         $schema1 = new Schema( array(
356             'bugdb' => new Table('bugdb',
357                 array (
358                     'integerfield1' => new Column('integerfield1', Type::getType('integer')),
359                     'integerfield2' => new Column('integerfield2', Type::getType('integer')),
360                 ),
361                 array (
362                     'primary' => new Index('primary', array('integerfield1', 'integerfield2'), true)
363                 )
364             ),
365         ) );
366         $schema2 = new Schema( array(
367             'bugdb' => new Table('bugdb',
368                 array (
369                     'integerfield1' => new Column('integerfield1', Type::getType('integer')),
370                     'integerfield2' => new Column('integerfield2', Type::getType('integer')),
371                 ),
372                 array (
373                     'primary' => new Index('primary', array('integerfield2', 'integerfield1'), true)
374                 )
375             ),
376         ) );
377
378         $expected = new SchemaDiff ( array(),
379             array (
380                 'bugdb' => new TableDiff('bugdb', array(), array(), array(), array(),
381                     array (
382                         'primary' => new Index('primary', array('integerfield2', 'integerfield1'), true)
383                     )
384                 ),
385             )
386         );
387         $actual = Comparator::compareSchemas( $schema1, $schema2 );
388         $this->assertEquals($expected, $actual);
389     }
390
391     public function testCompareSequences()
392     {
393         $seq1 = new Sequence('foo', 1, 1);
394         $seq2 = new Sequence('foo', 1, 2);
395         $seq3 = new Sequence('foo', 2, 1);
396
397         $c = new Comparator();
398
399         $this->assertTrue($c->diffSequence($seq1, $seq2));
400         $this->assertTrue($c->diffSequence($seq1, $seq3));
401     }
402
403     public function testRemovedSequence()
404     {
405         $schema1 = new Schema();
406         $seq = $schema1->createSequence('foo');
407
408         $schema2 = new Schema();
409
410         $c = new Comparator();
411         $diffSchema = $c->compare($schema1, $schema2);
412
413         $this->assertEquals(1, count($diffSchema->removedSequences));
414         $this->assertSame($seq, $diffSchema->removedSequences[0]);
415     }
416
417     public function testAddedSequence()
418     {
419         $schema1 = new Schema();
420
421         $schema2 = new Schema();
422         $seq = $schema2->createSequence('foo');
423
424         $c = new Comparator();
425         $diffSchema = $c->compare($schema1, $schema2);
426
427         $this->assertEquals(1, count($diffSchema->newSequences));
428         $this->assertSame($seq, $diffSchema->newSequences[0]);
429     }
430
431     public function testTableAddForeignKey()
432     {
433         $tableForeign = new Table("bar");
434         $tableForeign->addColumn('id', 'integer');
435
436         $table1 = new Table("foo");
437         $table1->addColumn('fk', 'integer');
438
439         $table2 = new Table("foo");
440         $table2->addColumn('fk', 'integer');
441         $table2->addForeignKeyConstraint($tableForeign, array('fk'), array('id'));
442
443         $c = new Comparator();
444         $tableDiff = $c->diffTable($table1, $table2);
445
446         $this->assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff);
447         $this->assertEquals(1, count($tableDiff->addedForeignKeys));
448     }
449
450     public function testTableRemoveForeignKey()
451     {
452         $tableForeign = new Table("bar");
453         $tableForeign->addColumn('id', 'integer');
454
455         $table1 = new Table("foo");
456         $table1->addColumn('fk', 'integer');
457
458         $table2 = new Table("foo");
459         $table2->addColumn('fk', 'integer');
460         $table2->addForeignKeyConstraint($tableForeign, array('fk'), array('id'));
461
462         $c = new Comparator();
463         $tableDiff = $c->diffTable($table2, $table1);
464
465         $this->assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff);
466         $this->assertEquals(1, count($tableDiff->removedForeignKeys));
467     }
468
469     public function testTableUpdateForeignKey()
470     {
471         $tableForeign = new Table("bar");
472         $tableForeign->addColumn('id', 'integer');
473
474         $table1 = new Table("foo");
475         $table1->addColumn('fk', 'integer');
476         $table1->addForeignKeyConstraint($tableForeign, array('fk'), array('id'));
477
478         $table2 = new Table("foo");
479         $table2->addColumn('fk', 'integer');
480         $table2->addForeignKeyConstraint($tableForeign, array('fk'), array('id'), array('onUpdate' => 'CASCADE'));
481
482         $c = new Comparator();
483         $tableDiff = $c->diffTable($table1, $table2);
484
485         $this->assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff);
486         $this->assertEquals(1, count($tableDiff->changedForeignKeys));
487     }
488
489     public function testTablesCaseInsensitive()
490     {
491         $schemaA = new Schema();
492         $schemaA->createTable('foo');
493         $schemaA->createTable('bAr');
494         $schemaA->createTable('BAZ');
495         $schemaA->createTable('new');
496
497         $schemaB = new Schema();
498         $schemaB->createTable('FOO');
499         $schemaB->createTable('bar');
500         $schemaB->createTable('Baz');
501         $schemaB->createTable('old');
502
503         $c = new Comparator();
504         $diff = $c->compare($schemaA, $schemaB);
505
506         $this->assertSchemaTableChangeCount($diff, 1, 0, 1);
507     }
508
509     public function testSequencesCaseInsenstive()
510     {
511         $schemaA = new Schema();
512         $schemaA->createSequence('foo');
513         $schemaA->createSequence('BAR');
514         $schemaA->createSequence('Baz');
515         $schemaA->createSequence('new');
516
517         $schemaB = new Schema();
518         $schemaB->createSequence('FOO');
519         $schemaB->createSequence('Bar');
520         $schemaB->createSequence('baz');
521         $schemaB->createSequence('old');
522
523         $c = new Comparator();
524         $diff = $c->compare($schemaA, $schemaB);
525
526         $this->assertSchemaSequenceChangeCount($diff, 1, 0, 1);
527     }
528
529     public function testCompareColumnCompareCaseInsensitive()
530     {
531         $tableA = new Table("foo");
532         $tableA->addColumn('id', 'integer');
533
534         $tableB = new Table("foo");
535         $tableB->addColumn('ID', 'integer');
536
537         $c = new Comparator();
538         $tableDiff = $c->diffTable($tableA, $tableB);
539
540         $this->assertFalse($tableDiff);
541     }
542
543     public function testCompareIndexBasedOnPropertiesNotName()
544     {
545         $tableA = new Table("foo");
546         $tableA->addColumn('id', 'integer');
547         $tableA->addIndex(array("id"), "foo_bar_idx");
548
549         $tableB = new Table("foo");
550         $tableB->addColumn('ID', 'integer');
551         $tableB->addIndex(array("id"), "bar_foo_idx");
552
553         $c = new Comparator();
554         $tableDiff = $c->diffTable($tableA, $tableB);
555
556         $this->assertFalse($tableDiff);
557     }
558
559     public function testCompareForeignKeyBasedOnPropertiesNotName()
560     {
561         $tableA = new Table("foo");
562         $tableA->addColumn('id', 'integer');
563         $tableA->addNamedForeignKeyConstraint('foo_constraint', 'bar', array('id'), array('id'));
564
565         $tableB = new Table("foo");
566         $tableB->addColumn('ID', 'integer');
567         $tableB->addNamedForeignKeyConstraint('bar_constraint', 'bar', array('id'), array('id'));
568
569         $c = new Comparator();
570         $tableDiff = $c->diffTable($tableA, $tableB);
571
572         $this->assertFalse($tableDiff);
573     }
574
575     public function testCompareForeignKey_RestrictNoAction_AreTheSame()
576     {
577         $fk1 = new ForeignKeyConstraint(array("foo"), "bar", array("baz"), "fk1", array('onDelete' => 'NO ACTION'));
578         $fk2 = new ForeignKeyConstraint(array("foo"), "bar", array("baz"), "fk1", array('onDelete' => 'RESTRICT'));
579
580         $c = new Comparator();
581         $this->assertFalse($c->diffForeignKey($fk1, $fk2));
582     }
583
584     public function testDetectRenameColumn()
585     {
586         $tableA = new Table("foo");
587         $tableA->addColumn('foo', 'integer');
588
589         $tableB = new Table("foo");
590         $tableB->addColumn('bar', 'integer');
591
592         $c = new Comparator();
593         $tableDiff = $c->diffTable($tableA, $tableB);
594
595         $this->assertEquals(0, count($tableDiff->addedColumns));
596         $this->assertEquals(0, count($tableDiff->removedColumns));
597         $this->assertArrayHasKey('foo', $tableDiff->renamedColumns);
598         $this->assertEquals('bar', $tableDiff->renamedColumns['foo']->getName());
599     }
600
601     /**
602      * You can easily have ambiguouties in the column renaming. If these
603      * are detected no renaming should take place, instead adding and dropping
604      * should be used exclusively.
605      *
606      * @group DBAL-24
607      */
608     public function testDetectRenameColumnAmbiguous()
609     {
610         $tableA = new Table("foo");
611         $tableA->addColumn('foo', 'integer');
612         $tableA->addColumn('bar', 'integer');
613
614         $tableB = new Table("foo");
615         $tableB->addColumn('baz', 'integer');
616
617         $c = new Comparator();
618         $tableDiff = $c->diffTable($tableA, $tableB);
619
620         $this->assertEquals(1, count($tableDiff->addedColumns), "'baz' should be added, not created through renaming!");
621         $this->assertArrayHasKey('baz', $tableDiff->addedColumns, "'baz' should be added, not created through renaming!");
622         $this->assertEquals(2, count($tableDiff->removedColumns), "'foo' and 'bar' should both be dropped, an ambigouty exists which one could be renamed to 'baz'.");
623         $this->assertArrayHasKey('foo', $tableDiff->removedColumns, "'foo' should be removed.");
624         $this->assertArrayHasKey('bar', $tableDiff->removedColumns, "'bar' should be removed.");
625         $this->assertEquals(0, count($tableDiff->renamedColumns), "no renamings should take place.");
626     }
627
628     public function testDetectChangeIdentifierType()
629     {
630         $this->markTestSkipped('DBAL-2 was reopened, this test cannot work anymore.');
631
632         $tableA = new Table("foo");
633         $tableA->addColumn('id', 'integer', array('autoincrement' => false));
634
635         $tableB = new Table("foo");
636         $tableB->addColumn('id', 'integer', array('autoincrement' => true));
637
638         $c = new Comparator();
639         $tableDiff = $c->diffTable($tableA, $tableB);
640
641         $this->assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff);
642         $this->assertArrayHasKey('id', $tableDiff->changedColumns);
643     }
644
645
646     /**
647      * @group DBAL-105
648      */
649     public function testDiff()
650     {
651         $table = new \Doctrine\DBAL\Schema\Table('twitter_users');
652         $table->addColumn('id', 'integer', array('autoincrement' => true));
653         $table->addColumn('twitterId', 'integer', array('nullable' => false));
654         $table->addColumn('displayName', 'string', array('nullable' => false));
655         $table->setPrimaryKey(array('id'));
656
657         $newtable = new \Doctrine\DBAL\Schema\Table('twitter_users');
658         $newtable->addColumn('id', 'integer', array('autoincrement' => true));
659         $newtable->addColumn('twitter_id', 'integer', array('nullable' => false));
660         $newtable->addColumn('display_name', 'string', array('nullable' => false));
661         $newtable->addColumn('logged_in_at', 'datetime', array('nullable' => true));
662         $newtable->setPrimaryKey(array('id'));
663
664         $c = new Comparator();
665         $tableDiff = $c->diffTable($table, $newtable);
666
667         $this->assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff);
668         $this->assertEquals(array('twitterid', 'displayname'), array_keys($tableDiff->renamedColumns));
669         $this->assertEquals(array('logged_in_at'), array_keys($tableDiff->addedColumns));
670         $this->assertEquals(0, count($tableDiff->removedColumns));
671     }
672
673
674     /**
675      * @group DBAL-112
676      */
677     public function testChangedSequence()
678     {
679         $schema = new Schema();
680         $sequence = $schema->createSequence('baz');
681
682         $schemaNew = clone $schema;
683         /* @var $schemaNew Schema */
684         $schemaNew->getSequence('baz')->setAllocationSize(20);
685
686         $c = new \Doctrine\DBAL\Schema\Comparator;
687         $diff = $c->compare($schema, $schemaNew);
688
689         $this->assertSame($diff->changedSequences[0] , $schemaNew->getSequence('baz'));
690     }
691
692     /**
693      * @group DBAL-106
694      */
695     public function testDiffDecimalWithNullPrecision()
696     {
697         $column = new Column('foo', Type::getType('decimal'));
698         $column->setPrecision(null);
699
700         $column2 = new Column('foo', Type::getType('decimal'));
701
702         $c = new Comparator();
703         $this->assertEquals(array(), $c->diffColumn($column, $column2));
704     }
705
706     /**
707      * @group DBAL-204
708      */
709     public function testFqnSchemaComparision()
710     {
711         $config = new SchemaConfig();
712         $config->setName("foo");
713
714         $oldSchema = new Schema(array(), array(), $config);
715         $oldSchema->createTable('bar');
716
717         $newSchema= new Schema(array(), array(), $config);
718         $newSchema->createTable('foo.bar');
719
720         $c = new Comparator();
721         $this->assertEquals(new SchemaDiff(), $c->compare($oldSchema, $newSchema));
722     }
723
724     /**
725      * @group DBAL-204
726      */
727     public function testFqnSchemaComparisionDifferentSchemaNameButSameTableNoDiff()
728     {
729         $config = new SchemaConfig();
730         $config->setName("foo");
731
732         $oldSchema = new Schema(array(), array(), $config);
733         $oldSchema->createTable('foo.bar');
734
735         $newSchema = new Schema();
736         $newSchema->createTable('bar');
737
738         $c = new Comparator();
739         $diff = $c->compare($oldSchema, $newSchema);
740         $this->assertEquals(new SchemaDiff(), $c->compare($oldSchema, $newSchema));
741     }
742
743     /**
744      * @group DBAL-204
745      */
746     public function testFqnSchemaComparisionNoSchemaSame()
747     {
748         $config = new SchemaConfig();
749         $config->setName("foo");
750         $oldSchema = new Schema(array(), array(), $config);
751         $oldSchema->createTable('bar');
752
753         $newSchema = new Schema();
754         $newSchema->createTable('bar');
755
756         $c = new Comparator();
757         $diff = $c->compare($oldSchema, $newSchema);
758
759         $this->assertEquals(new SchemaDiff(), $c->compare($oldSchema, $newSchema));
760     }
761
762     /**
763      * @group DDC-1657
764      */
765     public function testAutoIncremenetSequences()
766     {
767         $oldSchema = new Schema();
768         $table = $oldSchema->createTable("foo");
769         $table->addColumn("id", "integer", array("autoincrement" => true));
770         $table->setPrimaryKey(array("id"));
771         $oldSchema->createSequence("foo_id_seq");
772
773         $newSchema = new Schema();
774         $table = $newSchema->createTable("foo");
775         $table->addColumn("id", "integer", array("autoincrement" => true));
776         $table->setPrimaryKey(array("id"));
777
778         $c = new Comparator();
779         $diff = $c->compare($oldSchema, $newSchema);
780
781         $this->assertCount(0, $diff->removedSequences);
782     }
783
784     /**
785      * @param SchemaDiff $diff
786      * @param int $newTableCount
787      * @param int $changeTableCount
788      * @param int $removeTableCount
789      */
790     public function assertSchemaTableChangeCount($diff, $newTableCount=0, $changeTableCount=0, $removeTableCount=0)
791     {
792         $this->assertEquals($newTableCount, count($diff->newTables));
793         $this->assertEquals($changeTableCount, count($diff->changedTables));
794         $this->assertEquals($removeTableCount, count($diff->removedTables));
795     }
796
797     /**
798      * @param SchemaDiff $diff
799      * @param int $newSequenceCount
800      * @param int $changeSequenceCount
801      * @param int $changeSequenceCount
802      */
803     public function assertSchemaSequenceChangeCount($diff, $newSequenceCount=0, $changeSequenceCount=0, $removeSequenceCount=0)
804     {
805         $this->assertEquals($newSequenceCount, count($diff->newSequences), "Expected number of new sequences is wrong.");
806         $this->assertEquals($changeSequenceCount, count($diff->changedSequences), "Expected number of changed sequences is wrong.");
807         $this->assertEquals($removeSequenceCount, count($diff->removedSequences), "Expected number of removed sequences is wrong.");
808     }
809 }