Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Exceptions/Renderer/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function registerListeners(Dispatcher $events)
/**
* Returns the queries that have been executed.
*
* @return array<int, array{sql: string, time: float}>
* @return array<int, array{connectionName: string, time: float, sql: string, bindings: array}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be even done to the second array:

Suggested change
* @return array<int, array{connectionName: string, time: float, sql: string, bindings: array}>
* @return array<int, array{connectionName: string, time: float, sql: string, bindings: array<string, mixed>}>

*/
public function queries()
{
Expand Down
47 changes: 47 additions & 0 deletions tests/Foundation/Exceptions/Renderer/ListenerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Illuminate\Tests\Foundation\Exceptions\Renderer;

use Illuminate\Database\Events\QueryExecuted;
use Illuminate\Foundation\Exceptions\Renderer\Listener;
use Mockery as m;
use PHPUnit\Framework\TestCase;

class ListenerTest extends TestCase
{
protected function tearDown(): void
{
m::close();
}

public function test_queries_returns_expected_shape_after_query_executed()
{
$connection = m::mock();

$connection->shouldReceive('getName')->andReturn('testing');
$connection->shouldReceive('prepareBindings')->with(['foo'])->andReturn(['foo']);

$event = new QueryExecuted('select * from users where id = ?', ['foo'], 5.2, $connection);

$listener = new Listener();

$listener->onQueryExecuted($event);

$queries = $listener->queries();

$this->assertIsArray($queries);
$this->assertCount(1, $queries);

$query = $queries[0];

$this->assertArrayHasKey('connectionName', $query);
$this->assertArrayHasKey('time', $query);
$this->assertArrayHasKey('sql', $query);
$this->assertArrayHasKey('bindings', $query);

$this->assertEquals('testing', $query['connectionName']);
$this->assertEquals(5.2, $query['time']);
$this->assertEquals('select * from users where id = ?', $query['sql']);
$this->assertEquals(['foo'], $query['bindings']);
}
}