Skip to content

Commit

Permalink
Improve flush callbacks and fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jenssegers committed Feb 8, 2015
1 parent 436a5c7 commit 929814c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/RollbarServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,28 @@ public function boot()
$app['rollbar.handler']->log($level, $message, $context);
});

if (method_exists($app, 'version') and starts_with($app->version(), '5'))
// Flush callback
$flush = function() use ($app)
{
// Register Laravel 5 shutdown function
$this->app->terminating(function() use ($app)
if ($app->resolved('rollbar.client'))
{
$app['rollbar.client']->flush();
});
}
};

if (method_exists($app, 'version') and starts_with($app->version(), '5'))
{
// Register Laravel 5 shutdown function
$this->app->terminating($flush);
}
else
{
// Register Laravel 4 shutdown function
$this->app->shutdown(function() use ($app)
{
$app['rollbar.client']->flush();
});
$this->app->shutdown($flush);
}

// Register PHP shutdown function
register_shutdown_function(function() use ($app)
{
$app['rollbar.client']->flush();
});
register_shutdown_function($flush);
}

/**
Expand Down
22 changes: 22 additions & 0 deletions tests/RollbarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public function setUp()
public function tearDown()
{
Mockery::close();

parent::tearDown();
}

protected function getPackageProviders($app)
Expand Down Expand Up @@ -159,4 +161,24 @@ public function testAboveLevel()
$this->app->log->emergency('hello');
}

public function testFlushOnTerminate()
{
$clientMock = Mockery::mock('RollbarNotifier');
$clientMock->shouldReceive('flush')->once();
$this->app['rollbar.client'] = $clientMock;

$handler = $this->app->make('rollbar.handler');

$this->app->terminate();
}

public function testDontFlushIfUnresolved()
{
$clientMock = Mockery::mock('RollbarNotifier');
$clientMock->shouldReceive('flush')->times(0);
$this->app['rollbar.client'] = $clientMock;

$this->app->terminate();
}

}

0 comments on commit 929814c

Please sign in to comment.