Skip to content

Commit

Permalink
Now catch incomplete snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewbdaly committed Nov 18, 2017
1 parent 71c5945 commit 015488a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/Exceptions/SnapshotDataIncomplete.php
@@ -0,0 +1,10 @@
<?php

namespace Matthewbdaly\LaravelErrorSnapshot\Exceptions;

/**
* Snapshot data incomplete exception
*/
class SnapshotDataIncomplete extends \Exception
{
}
7 changes: 6 additions & 1 deletion src/Listeners/SnapshotCaptured.php
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Contracts\Queue\ShouldQueue;
use Matthewbdaly\LaravelErrorSnapshot\Events\SnapshotCaptured as Capture;
use Matthewbdaly\LaravelErrorSnapshot\Contracts\Repositories\Snapshot;
use Matthewbdaly\LaravelErrorSnapshot\Exceptions\SnapshotDataIncomplete;

/**
* Handles snapshot capture
Expand Down Expand Up @@ -38,6 +39,10 @@ public function __construct(Snapshot $repository)
*/
public function handle(Capture $event)
{
$this->repository->create($event->getData());
$data = $event->getData();
if (!array_key_exists('trace', $data)) {
throw new SnapshotDataIncomplete;
}
$this->repository->create($data);
}
}
11 changes: 11 additions & 0 deletions tests/Unit/Events/SnapshotCapturedTest.php
Expand Up @@ -19,6 +19,17 @@ public function testCaptureSnapshot($data)
$this->app->instance('Matthewbdaly\LaravelErrorSnapshot\Contracts\Repositories\Snapshot', $repo);
event(new SnapshotCaptured($data));
}
/**
* @dataProvider dataProvider
* @expectedException Matthewbdaly\LaravelErrorSnapshot\Exceptions\SnapshotDataIncomplete
*/
public function testCaptureSnapshotIncompleteData($data)
{
unset($data['trace']);
$repo = m::mock('Matthewbdaly\LaravelErrorSnapshot\Contracts\Repositories\Snapshot');
$this->app->instance('Matthewbdaly\LaravelErrorSnapshot\Contracts\Repositories\Snapshot', $repo);
event(new SnapshotCaptured($data));
}

public function dataProvider()
{
Expand Down

0 comments on commit 015488a

Please sign in to comment.