function case_template_schema_iterator() { $this->given($sqlite = $this->helper->sqlite(), $database = new CUT($sqlite))->when($result = $database->getTemplateSchemaIterator())->then->object($result)->isInstanceOf('Hoa\\File\\Finder')->foreach($result, function ($test, $value, $key) { $test->string($key)->match('/\\.sqlite.sql/')->object($value)->isInstanceOf('Hoa\\File\\SplFileInfo')->string($value->getFilename())->match('/\\.sqlite.sql/'); }); }
/** * Create the database. * * @param Configuration $configuration Configuration. * @return Database * @throw Exception\Installation */ static function createDatabase(Configuration $configuration) { if (!isset($configuration->database)) { throw new Exception\Installation('Configuration is corrupted, the database branch is missing.', 8); } try { $database = new Database($configuration->database->dsn, $configuration->database->username, $configuration->database->password); } catch (PDOException $exception) { throw new Exception\Installation('Cannot create the database.', 9, null, $exception); } $templateSchemaIterator = $database->getTemplateSchemaIterator(); try { foreach ($templateSchemaIterator as $templateSchema) { $schema = $templateSchema->open()->readAll(); $verdict = $database->exec($schema); if (false === $verdict) { throw new PDOException('Unable to execute the following schema:' . "\n" . $schema, 10); } $templateSchema->close(); } } catch (PDOException $exception) { throw new Exception\Installation('An error occured while setting up the database.', 11, null, $exception); } return $database; }