Page MenuHomeDevCentral

D311.id.diff
No OneTemporary

D311.id.diff

diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php
--- a/app/Exceptions/Handler.php
+++ b/app/Exceptions/Handler.php
@@ -9,6 +9,9 @@
use Illuminate\Foundation\Validation\ValidationException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
+use Config;
+use Raven;
+
class Handler extends ExceptionHandler
{
/**
@@ -33,10 +36,32 @@
*/
public function report(Exception $e)
{
+ if ($this->shouldReportToSentry()) {
+ $this->reportToSentry($e);
+ }
+
parent::report($e);
}
/**
+ * Determines if the error handler should report to Sentry
+ *
+ * @return bool
+ */
+ protected function shouldReportToSentry () {
+ return Raven::isConfigured() && Config::get('app.env') !== 'testing';
+ }
+
+ /**
+ * Reports the exception to Sentry
+ *
+ * @param Exception $e The exception to report
+ */
+ protected function reportToSentry (Exception $e) {
+ Raven::captureException($e);
+ }
+
+ /**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
diff --git a/app/Facades/Raven.php b/app/Facades/Raven.php
new file mode 100644
--- /dev/null
+++ b/app/Facades/Raven.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace Nasqueron\Notifications\Facades;
+
+use Illuminate\Support\Facades\Facade;
+
+use Config;
+
+/**
+ * @see \Raven_Client
+ */
+class Raven extends Facade {
+
+ /**
+ * Gets the registered name of the component.
+ *
+ * @return string
+ */
+ protected static function getFacadeAccessor() {
+ return 'raven';
+ }
+
+ /**
+ * Determines if a Sentry DSN is provided in the configuration
+ */
+ public static function isConfigured () {
+ return Config::get('services.sentry.dsn') !== null;
+ }
+}
diff --git a/app/Providers/SentryServiceProvider.php b/app/Providers/SentryServiceProvider.php
new file mode 100644
--- /dev/null
+++ b/app/Providers/SentryServiceProvider.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace Nasqueron\Notifications\Providers;
+
+use Illuminate\Contracts\Foundation\Application;
+use Illuminate\Support\ServiceProvider;
+
+class SentryServiceProvider extends ServiceProvider
+{
+ /**
+ * Bootstraps the application services.
+ *
+ * @return void
+ */
+ public function boot() {
+ }
+
+ /**
+ * Registers the application services.
+ *
+ * @return void
+ */
+ public function register() {
+ $this->app->singleton('raven', function (Application $app) {
+ $config = $app->make('config');
+ $dsn = $config->get('services.sentry.dsn');
+ return new \Raven_Client($dsn);
+ });
+ }
+}
diff --git a/composer.json b/composer.json
--- a/composer.json
+++ b/composer.json
@@ -14,7 +14,8 @@
"laravel/framework": "5.2.*",
"keruald/github": ">=0.2.0",
"keruald/broker": ">=0.3.3",
- "netresearch/jsonmapper": "~0.1.0"
+ "netresearch/jsonmapper": "~0.1.0",
+ "raven/raven": "^0.13.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
diff --git a/config/app.php b/config/app.php
--- a/config/app.php
+++ b/config/app.php
@@ -174,6 +174,7 @@
Nasqueron\Notifications\Providers\EventServiceProvider::class,
Nasqueron\Notifications\Providers\ReportServiceProvider::class,
Nasqueron\Notifications\Providers\RouteServiceProvider::class,
+ Nasqueron\Notifications\Providers\SentryServiceProvider::class,
Nasqueron\Notifications\Providers\ServicesServiceProvider::class
],
@@ -231,6 +232,7 @@
'Mail' => Illuminate\Support\Facades\Mail::class,
'Password' => Illuminate\Support\Facades\Password::class,
'Queue' => Illuminate\Support\Facades\Queue::class,
+ 'Raven' => Nasqueron\Notifications\Facades\Raven::class,
'Redirect' => Illuminate\Support\Facades\Redirect::class,
'Redis' => Illuminate\Support\Facades\Redis::class,
'Report' => Nasqueron\Notifications\Facades\Report::class,
diff --git a/config/services.php b/config/services.php
--- a/config/services.php
+++ b/config/services.php
@@ -35,6 +35,10 @@
'secret' => env('STRIPE_SECRET'),
],
+ 'sentry' => [
+ 'dsn' => env('SENTRY_DSN'),
+ ],
+
'github' => [
'analyzer' => [
'configDir' => env('GITHUB_ANALYZER_CONFIG_DIR', 'GitHubPayloadAnalyzer')
diff --git a/tests/Exceptions/HandlerTest.php b/tests/Exceptions/HandlerTest.php
new file mode 100644
--- /dev/null
+++ b/tests/Exceptions/HandlerTest.php
@@ -0,0 +1,39 @@
+<?php
+
+namespace Nasqueron\Notifications\Tests\Exceptions;
+
+use Nasqueron\Notifications\Exceptions\Handler;
+use Nasqueron\Notifications\Tests\TestCase;
+
+use App;
+use Config;
+use Mockery;
+
+class HandlerTest extends TestCase {
+
+ /**
+ * Illuminate\Foundation\Exceptions\Handler
+ */
+ private $handler;
+
+ public function setUp () {
+ parent::setUp();
+
+ $logger = App::make('log');
+ $this->handler = new Handler($logger);
+ }
+
+ protected function mockRavenClient () {
+ $mock = Mockery::mock('Raven_Client');
+ $mock->shouldReceive('captureException')->once();
+
+ Config::set('app.env', 'testing-raven');
+ Config::set('services.sentry.dsn', 'mock');
+ $this->app->instance('raven', $mock);
+ }
+
+ public function testRavenReport () {
+ $this->mockRavenClient();
+ $this->handler->report(new \Exception);
+ }
+}
diff --git a/tests/Facades/RavenTest.php b/tests/Facades/RavenTest.php
new file mode 100644
--- /dev/null
+++ b/tests/Facades/RavenTest.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace Nasqueron\Notifications\Tests\Facades;
+
+use Nasqueron\Notifications\Tests\TestCase;
+
+use Config;
+use Raven;
+
+class RavenTest extends TestCase {
+
+ public function testIfFacadeAccessorCouldBeResolvedInAppContainer () {
+ $this->assertInstanceOf(
+ 'Raven_Client',
+ Raven::getFacadeRoot()
+ );
+ }
+
+ public function testIsConfigured () {
+ Config::set("services.sentry.dsn", "something");
+ $this->assertTrue(Raven::isConfigured());
+ }
+
+ public function testIsConfiguredWhenItIsNot () {
+ Config::offsetUnset("services.sentry.dsn");
+ $this->assertFalse(Raven::isConfigured());
+ }
+
+}
diff --git a/tests/Providers/SentryServiceProviderTest.php b/tests/Providers/SentryServiceProviderTest.php
new file mode 100644
--- /dev/null
+++ b/tests/Providers/SentryServiceProviderTest.php
@@ -0,0 +1,14 @@
+<?php
+
+namespace Nasqueron\Notifications\Tests\Providers;
+
+class SentryServiceProviderTest extends TestCase {
+
+ public function testType () {
+ $this->assertServiceInstanceOf(
+ 'Raven_Client',
+ 'raven'
+ );
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Mon, Dec 23, 14:12 (12 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2312603
Default Alt Text
D311.id.diff (6 KB)

Event Timeline