Skip to content

Commit

Permalink
FIX: Tests now run (But fail)
Browse files Browse the repository at this point in the history
- Minor tweaks to README and supported PHP versions
  • Loading branch information
phptek committed Jun 18, 2019
1 parent c8acac2 commit efe50b7
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2016, Russell Michell - theruss.com
Copyright (c) 2016-2019, Russell Michell - theruss.com
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ This module binds Sentry.io and locally-hosted Sentry installations, to the erro

### SilverStripe 4

* PHP5.6+, <7.2
* SilverStripe v4.0.0+
* PHP >7.0
* SilverStripe ^4.0

### SilverStripe 3

Expand All @@ -35,6 +35,11 @@ Add the Composer package as a dependency to your project:

composer require phptek/sentry: 2.x

composer require phptek/sentry: 3.x

Note that 2.x and 3.x should work with the same setups, the latter simply uses a
newer version of the Sentry PHP SDK, and has a leaner codebase.

Configure your application or site with the Sentry DSN into your project's YML config:

### SilverStripe 4
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"silverstripe/sentry": "*"
},
"require": {
"php": ">=5.6|<=7.2",
"php": ">=7.0",
"sentry/sdk": "^2.0",
"monolog/monolog": "^1.24.0",
"silverstripe/framework": "^4"
Expand Down
11 changes: 11 additions & 0 deletions src/Handler/SentryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Monolog\Handler\AbstractProcessingHandler;
use Monolog\Logger;
use Sentry\Severity;
use SilverStripe\Core\Injector\Injectable;
use PhpTek\Sentry\Log\SentryLogger;

/**
Expand All @@ -23,6 +24,8 @@
*/
class SentryHandler extends AbstractProcessingHandler
{
use Injectable;

/**
* A mapping of log-level values between Zend_Log => Raven_Client
*
Expand Down Expand Up @@ -85,4 +88,12 @@ protected function write(array $record) : void
$this->client->getSDK()->captureMessage($record['formatted'], new Severity(strtolower($record['level_name'])));
}
}

/**
* @return
*/
public function getClient()
{
return $this->client;
}
}
18 changes: 8 additions & 10 deletions tests/RavenClientTest.php → tests/SentryHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@
* @package phptek/sentry
*/

use PhpTek\Sentry\Handler\SentryMonologHandler,
SilverStripe\Dev\SapphireTest,
SilverStripe\Core\Config\Config,
Monolog\Logger;
use SilverStripe\Dev\SapphireTest;
use Monolog\Logger;
use PhpTek\Sentry\Handler\SentryHandler;

/**
* Exercises RavenClient.
* Exercises {@link SentryHandler}.
*/
class RavenClientTest extends SapphireTest
class SentryHandlerTest extends SapphireTest
{

/**
* In the absence of fixture files, this is needed to force SaphhireTest into
* creating us a test DB.
Expand All @@ -34,7 +32,7 @@ class RavenClientTest extends SapphireTest
public function testDefaultTagsAvailable()
{
$logger = new Logger('error-log');
$logger->pushHandler(new SentryMonologHandler());
$logger->pushHandler(SentryHandler::create());
$handler = $logger->getHandlers()[0];
$tagsThatWereSet = $handler->getClient()->getData()['tags'];

Expand All @@ -54,7 +52,7 @@ public function testDefaultTagsAvailable()
public function testdefaultUserDataAvailable()
{
$logger = new Logger('error-log');
$logger->pushHandler(new SentryMonologHandler());
$logger->pushHandler(SentryHandler::create());
$handler = $logger->getHandlers()[0];

// Setup the "fixture data" for this test
Expand Down Expand Up @@ -83,7 +81,7 @@ public function testExtrasAvailable()
'env' => 'live'
];
$logger = new Logger('error-log');
$logger->pushHandler(new SentryMonologHandler(100, true, $fixture));
$logger->pushHandler(SentryHandler::create(100, true, $fixture));
$handler = $logger->getHandlers()[0];
$envThatWasSet = $handler->getClient()->getData()['env'];
$xtraThatWasSet = $handler->getClient()->getData()['extra'];
Expand Down

0 comments on commit efe50b7

Please sign in to comment.