Пример #1
0
 /**
  * Parse table create statement.
  *
  * @throws SchemaException
  */
 protected function parseTableCS()
 {
     $lines = explode("\n", $this->tableCS);
     foreach ($lines as $index => $line) {
         $line = trim($line);
         // Column definitions start with `
         if (0 === strpos($line, '`')) {
             $this->addColumn(new Column($line, $index, $this));
         } elseif (Index::isIndexDef($line)) {
             $this->addIndex(new Index($line, $this));
         } elseif (Constraint::isConstraintDef($line)) {
             $this->addConstraint(new Constraint($line, $this));
         } elseif (preg_match('/CREATE TABLE `(.*?)`/', $line, $matches) === 1) {
             $this->name = $matches[1];
             $this->type = TableItf::TYPE_TABLE;
         } elseif (preg_match('/VIEW `(.*?)` AS /i', $line, $matches) === 1) {
             $this->name = $matches[1];
             $this->type = TableItf::TYPE_VIEW;
         }
     }
 }
Пример #2
0
 /**
  * @covers ::getColumnNames
  */
 public function test_getColumnNames_multiple()
 {
     // Given
     $index = new Index("KEY `my_key` (`id`, `name`)", $this->tableMock);
     // When
     $columns = $index->getColumnNames();
     // Then
     $this->assertSame(['id', 'name'], $columns);
 }