Skip to content

Commit 2c93154

Browse files
committed
Merge branch 'updates' of https://github.com/beyondcode/laravel-query-detector into updates
2 parents a4c3b34 + a57ba05 commit 2c93154

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ composer.lock
33
vendor
44
coverage
55
.idea
6-
nbproject
6+
nbproject
7+
.phpunit.result.cache

src/QueryDetector.php

+5
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,9 @@ public function output($request, $response)
233233

234234
return $response;
235235
}
236+
237+
public function emptyQueries()
238+
{
239+
$this->queries = Collection::make();
240+
}
236241
}

tests/QueryDetectorTest.php

+23
Original file line numberDiff line numberDiff line change
@@ -336,4 +336,27 @@ public function it_uses_the_trace_line_to_detect_queries()
336336
$this->assertSame(Author::class, $queries[0]['model']);
337337
$this->assertSame('profile', $queries[0]['relation']);
338338
}
339+
340+
/** @test */
341+
public function it_empty_queries()
342+
{
343+
Route::get('/', function (){
344+
$authors = Author::all();
345+
346+
foreach ($authors as $author) {
347+
$author->profile;
348+
}
349+
});
350+
351+
$this->get('/');
352+
353+
$queryDetector = app(QueryDetector::class);
354+
355+
$queries = $queryDetector->getDetectedQueries();
356+
$this->assertCount(1, $queries);
357+
358+
$queryDetector->emptyQueries();
359+
$queries = $queryDetector->getDetectedQueries();
360+
$this->assertCount(0, $queries);
361+
}
339362
}

0 commit comments

Comments
 (0)