/** * Get create statements string. * * @param string $format The format of the file: self::FORMAT_* * * @throws SchemaException * * @return array|string */ public function getCreateStatements($format = null) { $exportType = Arr::get($this->config, self::CONFIG_KEY_EXPORT_FORMAT); // Override format from config. if ($format != null) { $exportType = $format; } $aine = Arr::get($this->config, self::CONFIG_KEY_AINE, false); $createStatements = []; $tableNames = array_merge($this->db->dbGetTableNames(), $this->db->dbGetViewNames()); foreach ($tableNames as $tableName) { $table = $this->db->dbGetTableDefinition($tableName); $createStatements[$table->getName()] = $table->getCreateStatement($aine); } $ret = null; switch ($exportType) { case self::FORMAT_PHP_ARRAY: $ret = $createStatements; break; case self::FORMAT_PHP_FILE: $createStatements = array_map(['\\Kicaj\\Tools\\Helper\\Str', 'oneLine'], $createStatements); $configArray = var_export($createStatements, true); $ret = "<?php\n\n" . '$createStatements = ' . $configArray . ";\n\n"; $ret .= 'return $createStatements;' . "\n"; break; case self::FORMAT_SQL: $createStatements = array_map(['\\Kicaj\\Tools\\Helper\\Str', 'oneLine'], array_values($createStatements)); $ret = implode("\n", array_values($createStatements)) . "\n"; break; default: throw new SchemaException('unknown format: ' . $exportType); } return $ret; }
public function setUp() { Db::_resetInstances(); $this->schema = Schema::make($this->getSchemaConfig('SCHEMA1')); }
/** * @covers ::dbGetTableNames * * @expectedException \Kicaj\Schema\SchemaException * @expectedExceptionMessage Table 'testschemalib.not_existing' doesn't exist */ public function test_dbGetTableDefinition_error() { // Given $db = Db::factory(self::getSchemaConfig('SCHEMA1')); // Then $db->dbGetTableDefinition('not_existing'); }