Skip to content

Commit 47f25f2

Browse files
erikn69SudoGetBeer
andauthored
Test collect real path from compiled views on QueryCollector (#1543)
Co-authored-by: Lars <[email protected]>
1 parent 9506950 commit 47f25f2

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

tests/DataCollector/QueryCollectorTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,30 @@ public function testDollarBindingsArePresentedCorrectly()
5959
);
6060
});
6161
}
62+
63+
public function testFindingCorrectPathForView()
64+
{
65+
debugbar()->boot();
66+
67+
/** @var \Barryvdh\Debugbar\DataCollector\QueryCollector $collector */
68+
$collector = debugbar()->getCollector('queries');
69+
70+
view('query')
71+
->with('db', $this->app['db']->connection())
72+
->with('collector', $collector)
73+
->render();
74+
75+
tap(Arr::first($collector->collect()['statements']), function (array $statement) {
76+
$this->assertEquals(
77+
"SELECT a FROM b WHERE c = '$10' AND d = '$2y$10_DUMMY_BCRYPT_HASH' AND e = '\$_$\$_$$\$_$2_$3'",
78+
$statement['sql']
79+
);
80+
81+
$this->assertTrue(@file_exists($statement['backtrace'][1]->file));
82+
$this->assertEquals(
83+
realpath(__DIR__ . '/../resources/views/query.blade.php'),
84+
realpath($statement['backtrace'][1]->file)
85+
);
86+
});
87+
}
6288
}

tests/resources/views/query.blade.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@php
2+
$collector->addQuery(new \Illuminate\Database\Events\QueryExecuted(
3+
"SELECT a FROM b WHERE c = ? AND d = ? AND e = ?",
4+
['$10', '$2y$10_DUMMY_BCRYPT_HASH', '$_$$_$$$_$2_$3'],
5+
0,
6+
$db
7+
));
8+
@endphp

0 commit comments

Comments
 (0)