-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #427 from facade/feature/query-exception-recording
Add support for recording raw sql queries
- Loading branch information
Showing
6 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,7 @@ const predefinedContextItemGroups = [ | |
'context', | ||
'logs', | ||
'dumps', | ||
'exception', | ||
]; | ||
export default { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Facade\Ignition\Middleware; | ||
|
||
use Facade\FlareClient\Report; | ||
use Illuminate\Database\QueryException; | ||
|
||
class AddExceptionInformation | ||
{ | ||
public function handle(Report $report, $next) | ||
{ | ||
$throwable = $report->getThrowable(); | ||
|
||
if (! $throwable instanceof QueryException) { | ||
return $next($report); | ||
} | ||
|
||
$report->group('exception', [ | ||
'raw_sql' => $throwable->getSql(), | ||
]); | ||
|
||
return $next($report); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Facade\Ignition\Tests\Middleware; | ||
|
||
use Exception; | ||
use Facade\Ignition\Facades\Flare; | ||
use Facade\Ignition\Tests\TestCase; | ||
use Illuminate\Database\QueryException; | ||
|
||
class AddExceptionInformationTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_will_add_query_information_with_a_query_exception() | ||
{ | ||
$sql = 'select * from users where emai = "[email protected]"'; | ||
|
||
$report = Flare::createReport(new QueryException( | ||
'' . $sql . '', | ||
[], | ||
new Exception() | ||
)); | ||
|
||
$context = $report->toArray()['context']; | ||
|
||
$this->assertArrayHasKey('exception', $context); | ||
$this->assertSame($sql, $context['exception']['raw_sql']); | ||
} | ||
|
||
/** @test */ | ||
public function it_wont_add_query_information_without_a_query_exception() | ||
{ | ||
$report = Flare::createReport(new Exception()); | ||
|
||
$context = $report->toArray()['context']; | ||
|
||
$this->assertArrayNotHasKey('exception', $context); | ||
} | ||
} |