Skip to content

Commit

Permalink
More flexible configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jenssegers committed Apr 30, 2014
1 parent 56d716f commit f4ee499
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 32 deletions.
9 changes: 5 additions & 4 deletions src/RollbarServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ public function register()
{
$this->app->bindShared('rollbar', function($app)
{
$config = array(
'access_token' => Config::get('rollbar::token'),
// Automatic values
$automatic = array(
'environment' => App::environment(),
'root' => base_path(),
'max_errno' => Config::get('rollbar::max_errno')
'root' => base_path()
);

$config = array_merge($automatic, Config::get('rollbar::config'));

Rollbar::init($config, false, false);
return Rollbar::$instance;
});
Expand Down
24 changes: 7 additions & 17 deletions src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
| Rollbar Environments
|--------------------------------------------------------------------------
|
| Enable automatic error and log reporting for these environments.
| Enable automatic error and log reporting for these specific environments.
|
*/

Expand All @@ -16,27 +16,17 @@

/*
|--------------------------------------------------------------------------
| API Access Token
| Rollbar Configuration
|--------------------------------------------------------------------------
|
| This is your 'post_server_item' access token for the Rollbar API. This
| token can be found in the 'Project Access Tokens' section in
| your project settings.
| Any values below here will be passed directly as configuration to the
| Rollbar instance. For more information about the possible values
| check out: https://rollbar.com/docs/notifier/rollbar-php
|
*/

'token' => '',


/*
|--------------------------------------------------------------------------
| Maximum Error Number
|--------------------------------------------------------------------------
|
| The maximum error number to report. Default: ignore E_STRICT and above.
| Example: "access_token", "batch_size", "max_errno", "scrub_fields", ...
|
*/

'max_errno' => E_USER_NOTICE,
'access_token' => '',

);
34 changes: 23 additions & 11 deletions tests/ServiceProviderTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

use Config;

class ServiceProviderTest extends Orchestra\Testbench\TestCase {

public function setUp()
Expand Down Expand Up @@ -29,25 +27,39 @@ public function testBinding()
public function testPassConfiguration()
{
$token = 'B42nHP04s06ov18Dv8X7VI4nVUs6w04X';
Config::set('rollbar::token', $token);
Config::set('rollbar::access_token', $token);

$rollbar = App::make('rollbar');
$this->assertEquals($token, $rollbar->access_token);
}

public function testIsSingleton()
{
$rollbar1 = App::make('rollbar');
$rollbar2 = App::make('rollbar');
$this->assertEquals(spl_object_hash($rollbar1), spl_object_hash($rollbar2));
}

public function testEnvironment()
public function testDefaultConfiguration()
{
$rollbar = App::make('rollbar');
$this->assertEquals(App::environment(), $rollbar->environment);
$this->assertEquals(base_path(), $rollbar->root);
$this->assertEquals(E_USER_NOTICE, $rollbar->max_errno);
$this->assertEquals('https://api.rollbar.com/api/1/', $rollbar->base_api_url);
}

public function testCustomConfiguration()
{
Config::set('rollbar::environment', 'staging');
Config::set('rollbar::root', '/tmp');
Config::set('rollbar::max_errno', E_ERROR);

$rollbar = App::make('rollbar');
$this->assertEquals('staging', $rollbar->environment);
$this->assertEquals('/tmp', $rollbar->root);
$this->assertEquals(E_ERROR, $rollbar->max_errno);
$this->assertEquals('https://api.rollbar.com/api/1/', $rollbar->base_api_url);
}

public function testIsSingleton()
{
$rollbar1 = App::make('rollbar');
$rollbar2 = App::make('rollbar');
$this->assertEquals(spl_object_hash($rollbar1), spl_object_hash($rollbar2));
}

public function testRegisterErrorListener()
Expand Down

0 comments on commit f4ee499

Please sign in to comment.