Example #1
0
 /**
  * Returns the SQL for the primary key of a Table object.
  *
  * @return string
  */
 public function getPrimaryKeyDDL(Table $table)
 {
     if ($table->hasPrimaryKey() && 1 < count($table->getPrimaryKey())) {
         if ($table->hasAutoIncrementPrimaryKey()) {
             return 'UNIQUE (' . $this->getColumnListDDL($table->getPrimaryKey()) . ')';
         }
         return 'PRIMARY KEY (' . $this->getColumnListDDL($table->getPrimaryKey()) . ')';
     }
 }
 public function testGetAutoIncrementPrimaryKey()
 {
     $column1 = $this->getColumnMock('id', array('primary' => true, 'auto_increment' => true));
     $column2 = $this->getColumnMock('title');
     $column3 = $this->getColumnMock('isbn');
     $table = new Table();
     $table->setIdMethod('native');
     $table->addColumn($column1);
     $table->addColumn($column2);
     $table->addColumn($column3);
     $this->assertCount(1, $table->getPrimaryKey());
     $this->assertTrue($table->hasPrimaryKey());
     $this->assertTrue($table->hasAutoIncrementPrimaryKey());
     $this->assertSame($column1, $table->getAutoIncrementPrimaryKey());
 }