public function testDescribeTableReturnsAccurateListingOfFruitsColumns() { $columns = $this->db->describeTable('dewdrop_test_fruits'); $this->assertTrue(array_key_exists('dewdrop_test_fruit_id', $columns)); $this->assertTrue($columns['dewdrop_test_fruit_id']['IDENTITY']); $this->assertEquals(1, $columns['dewdrop_test_fruit_id']['PRIMARY_POSITION']); $this->assertEquals(4, count($columns)); }
/** * Write metadata files for all the listed tables. * * @param string $path * @param DbAdapter $db * @param array $tables * @return void */ protected function writeMetadataFiles($path, DbAdapter $db, array $tables) { $inflector = new Inflector(); foreach ($tables as $table) { $columns = $db->describeTable($table); $references = $db->listForeignKeyReferences($table); $uniqueConstraints = $db->listUniqueConstraints($table); $title = $inflector->titleize($table); $replacements = array('{{singular}}' => $inflector->singularize($title), '{{plural}}' => $inflector->pluralize($title), '{{columns}}' => var_export($columns, true), '{{references}}' => var_export($references, true), '{{uniqueConstraints}}' => var_export($uniqueConstraints, true)); file_put_contents("{$path}/{$table}.php", str_replace(array_keys($replacements), $replacements, file_get_contents(__DIR__ . '/db-metadata/template.tpl'))); } }