Skip to content

Commit

Permalink
Allow RAVEN_DSN env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
jenssegers committed May 30, 2015
1 parent 99e0bbc commit 2675387
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/RavenServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ public function register()

$this->app['raven.client'] = $this->app->share(function ($app)
{
$config = $app['config']->get('services.raven');
$config = $app['config']->get('services.raven', []);

if (empty($config['dsn']))
$dsn = env('RAVEN_DSN') ?: $app['config']->get('services.raven.dsn');

if ( ! $dsn)
{
throw new InvalidArgumentException('Raven DSN not configured');
}
Expand All @@ -54,7 +56,7 @@ public function register()
$config['curl_method'] = 'async';
}

return new Raven_Client($config['dsn'], array_except($config, ['dsn']));
return new Raven_Client($dsn, array_except($config, ['dsn']));
});

$this->app['raven.handler'] = $this->app->share(function ($app)
Expand All @@ -64,6 +66,7 @@ public function register()
return new RavenLogHandler($app['raven.client'], $app, $level);
});

// Register the fatal error handler.
register_shutdown_function(function () use ($app)
{
if (isset($app['raven.client']))
Expand Down
11 changes: 11 additions & 0 deletions tests/RavenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ public function testCustomConfiguration()
$this->assertEquals(['php_version' => phpversion()], $client->tags);
}

public function testEnvironmentConfiguration()
{
putenv('RAVEN_DSN=https://baz:qux@app.getsentry.com/54321');

$client = $this->app->make('raven.client');
$this->assertEquals('54321', $client->project);
$this->assertEquals('baz', $client->public_key);
$this->assertEquals('qux', $client->secret_key);
$this->assertEquals(['https://app.getsentry.com/api/54321/store/'], $client->servers);
}

public function testAutomaticContext()
{
$this->app->session->set('foo', 'bar');
Expand Down

0 comments on commit 2675387

Please sign in to comment.