|
5 | 5 | use Illuminate\Contracts\Support\Jsonable;
|
6 | 6 | use Illuminate\Database\Eloquent\Model;
|
7 | 7 | use Illuminate\Database\Eloquent\SoftDeletes;
|
| 8 | +use Illuminate\Database\Events\QueryExecuted; |
8 | 9 | use Illuminate\Support\Arr;
|
9 | 10 | use Illuminate\Support\Facades\DB;
|
10 | 11 | use Illuminate\Testing\Constraints\CountInDatabase;
|
@@ -177,15 +178,21 @@ protected function assertModelMissing($model)
|
177 | 178 | */
|
178 | 179 | public function expectsDatabaseQueryCount($expected, $connection = null)
|
179 | 180 | {
|
180 |
| - with($this->getConnection($connection), function ($connection) use ($expected) { |
| 181 | + with($this->getConnection($connection), function ($connectionInstance) use ($expected, $connection) { |
181 | 182 | $actual = 0;
|
182 | 183 |
|
183 |
| - $connection->listen(function () use (&$actual) { |
184 |
| - $actual++; |
| 184 | + $connectionInstance->listen(function (QueryExecuted $event) use (&$actual, $connectionInstance, $connection) { |
| 185 | + if (is_null($connection) || $connectionInstance === $event->connection) { |
| 186 | + $actual++; |
| 187 | + } |
185 | 188 | });
|
186 | 189 |
|
187 |
| - $this->beforeApplicationDestroyed(function () use (&$actual, $expected, $connection) { |
188 |
| - $this->assertSame($actual, $expected, "Expected {$expected} database queries on the [{$connection->getName()}] connection. {$actual} occurred."); |
| 190 | + $this->beforeApplicationDestroyed(function () use (&$actual, $expected, $connectionInstance) { |
| 191 | + $this->assertSame( |
| 192 | + $actual, |
| 193 | + $expected, |
| 194 | + "Expected {$expected} database queries on the [{$connectionInstance->getName()}] connection. {$actual} occurred." |
| 195 | + ); |
189 | 196 | });
|
190 | 197 | });
|
191 | 198 |
|
|
0 commit comments