Skip to content

Commit 92bc254

Browse files
authored
Merge pull request #86 from honeybadger-io/report-data
Warn of `report_data` when running a test
2 parents fd05887 + 4fe327b commit 92bc254

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

src/Commands/HoneybadgerInstallCommand.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ private function addTestExceptionTask(): void
113113
$this->tasks->addTask(
114114
'Send test exception to Honeybadger',
115115
function () {
116+
if (! config('honeybadger.report_data')) {
117+
$this->info("You have `report_data` set to false in your config. Errors won't be reported in this environment.");
118+
$this->info("We've switched it to true for this test, but you should check that it's enabled for your production environments.");
119+
}
116120
$result = $this->installer->sendTestException();
117121

118122
return empty($result) ? false : $result;

src/Commands/HoneybadgerTestCommand.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Honeybadger\Contracts\Reporter;
77
use Honeybadger\HoneybadgerLaravel\Exceptions\TestException;
88
use Illuminate\Console\Command;
9-
use Illuminate\Support\Arr;
109

1110
class HoneybadgerTestCommand extends Command
1211
{
@@ -30,13 +29,18 @@ public function handle()
3029
$honeybadger = app('honeybadger.loud');
3130

3231
try {
32+
if (! config('honeybadger.report_data')) {
33+
$this->info("You have `report_data` set to false in your config. Errors won't be reported in this environment.");
34+
$this->info("We've switched it to true for this test, but you should check that it's enabled for your production environments.");
35+
}
3336
$result = $honeybadger->notify(new TestException);
34-
$this->info('A test exception was sent to Honeybadger');
35-
if (is_null(Arr::get($result, 'id'))) {
37+
$id = $result['id'] ?? null;
38+
if (is_null($id)) {
3639
throw new Exception('There was an error sending the exception to Honeybadger');
3740
}
3841

39-
$this->line(sprintf('https://app.honeybadger.io/notice/', Arr::get($result, 'id')));
42+
$noticeUrl = "https://app.honeybadger.io/notice/$id";
43+
$this->info("Successfully sent a test exception to Honeybadger: $noticeUrl");
4044
} catch (Exception $e) {
4145
$this->error($e->getMessage());
4246
}

src/HoneybadgerLaravel.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Honeybadger\Contracts\Reporter;
66
use Honeybadger\Exceptions\ServiceException;
77
use Honeybadger\Honeybadger;
8+
use Honeybadger\HoneybadgerLaravel\Exceptions\TestException;
89
use Illuminate\Support\Facades\Log;
910
use Symfony\Component\HttpFoundation\Request;
1011
use Throwable;
@@ -62,6 +63,18 @@ public function notify(Throwable $throwable, Request $request = null, array $add
6263
return $result;
6364
}
6465

66+
protected function shouldReport(Throwable $throwable): bool
67+
{
68+
// Always report if the user is running a test.
69+
if ($throwable instanceof TestException) {
70+
return true;
71+
}
72+
73+
return ! $this->excludedException($throwable)
74+
&& ! empty($this->config['api_key'])
75+
&& $this->config['report_data'];
76+
}
77+
6578
protected function setRouteActionAndUserContext(Request $request): void
6679
{
6780
// For backwards compatibility, check if context has already been set by the middleware

tests/Commands/HoneybadgerTestCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function it_outputs_success()
2929
{
3030
$mock = $this->createMock(Reporter::class);
3131
$mock->method('notify')
32-
->willReturn([]);
32+
->willReturn(['id' => 8633]);
3333

3434
$this->app->instance('honeybadger.loud', $mock);
3535

@@ -40,7 +40,7 @@ public function it_outputs_success()
4040

4141
$command->expects($this->once())
4242
->method('info')
43-
->with('A test exception was sent to Honeybadger');
43+
->with('Successfully sent a test exception to Honeybadger: https://app.honeybadger.io/notice/8633');
4444

4545
$this->app[Kernel::class]->registerCommand($command);
4646

0 commit comments

Comments
 (0)