Skip to content

Commit

Permalink
add support for non-standard PDOs (#1499)
Browse files Browse the repository at this point in the history
* add support for non-standard PDOs

* remove use of fake()

---------

Co-authored-by: Andrew Minion <[email protected]>
  • Loading branch information
macbookandrew and andrewminion-luminfire authored Aug 1, 2024
1 parent a678a14 commit 67fbff2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Watchers/QueryWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ public function replaceBindings($event)
protected function quoteStringBinding($event, $binding)
{
try {
return $event->connection->getPdo()->quote($binding);
$pdo = $event->connection->getPdo();

if ($pdo instanceof \PDO) {
return $pdo->quote($binding);
}
} catch (\PDOException $e) {
throw_if('IM001' !== $e->getCode(), $e);
}
Expand Down
39 changes: 39 additions & 0 deletions tests/Watchers/QueryWatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Laravel\Telescope\Tests\Watchers;

use Carbon\Carbon;
use Illuminate\Database\Connection;
use Illuminate\Database\Events\QueryExecuted;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Laravel\Telescope\EntryType;
Expand Down Expand Up @@ -101,4 +103,41 @@ public function test_query_watcher_can_prepare_named_bindings()

$this->assertSame('testbench', $entry->content['connection']);
}

public function test_query_watcher_can_prepare_bindings_for_nonstandard_connections()
{
$event = new QueryExecuted(<<<'SQL'
select
Method: post
URL: https://fms.example.com/fmi/data/vLatest/databases/Database_Name/layouts/dapi_layout/_find
Data: {
"query": [
{
"kp_iti": "=ITI0130"
}
],
"limit": 1
}
SQL,
['kp_id' => '=ABC001'],
500,
new Connection('filemaker'),
);

$sql = app()->make(QueryWatcher::class)->replaceBindings($event);

$this->assertSame(<<<'SQL'
select
Method: post
URL: https://fms.example.com/fmi/data/vLatest/databases/Database_Name/layouts/dapi_layout/_find
Data: {
"query": [
{
"kp_iti": "=ITI0130"
}
],
"limit": 1
}
SQL, $sql);
}
}

0 comments on commit 67fbff2

Please sign in to comment.