Ejemplo n.º 1
0
 /**
  * Sets up the database to work with Platform from the given repository.
  *
  * @return void
  */
 protected function setupDatabase()
 {
     $driver = $this->repository->getDatabaseDriver();
     $config = $this->repository->getDatabaseData($driver);
     try {
         $this->laravel['db.factory']->make(array_merge(compact('driver'), $config));
     } catch (\PDOException $e) {
         throw $e;
     }
     $configFile = __DIR__ . "/stubs/database/{$driver}.php";
     $envStub = __DIR__ . '/stubs/env.stub';
     // Now, let's update our stub file with
     // our actual database credentials
     $contents = str_replace(array_map(function ($key) {
         return '{{' . $key . '}}';
     }, array_keys($config)), array_values($config), $this->laravel['files']->get($envStub));
     // Generate a key
     $contents = str_replace('{{key}}', Str::random(32), $contents);
     // Just a triple check we can actually
     // write the configuration.
     if ($this->laravel['files']->put($envFile = $this->laravel['path.base'] . '/.env', $contents) === false) {
         throw new \RuntimeException("Could not write env file to [{$envFile}].");
     }
     if ($this->laravel['files']->put($newConfigFile = $this->laravel['path.base'] . '/config/database.php', $this->laravel['files']->get($configFile)) === false) {
         throw new \RuntimeException("Could not write database config file to [{$newConfigFile}].");
     }
     // Reload env file
     $this->laravel['Illuminate\\Foundation\\Bootstrap\\DetectEnvironment']->bootstrap($this->laravel);
     // Reload config
     $this->laravel['Illuminate\\Foundation\\Bootstrap\\LoadConfiguration']->bootstrap($this->laravel);
     // Purge old connection
     $this->laravel['db']->purge();
     // Set table prefix on the connection
     $this->laravel['db']->setTablePrefix(array_get($config, 'prefix'));
     // Reconnect using the new config
     $this->laravel['db']->reconnect($driver);
 }
Ejemplo n.º 2
0
 /** @test */
 public function it_can_get_the_database_rules()
 {
     $this->assertCount(4, $this->repository->getDatabaseRules());
     $this->assertCount(5, $this->repository->getDatabaseRules('mysql'));
 }