Skip to content

Commit 6f600f0

Browse files
committed
fix error on redirects - fixes #2
1 parent c56f6d6 commit 6f600f0

File tree

6 files changed

+26
-19
lines changed

6 files changed

+26
-19
lines changed

src/Outputs/Alert.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22

33
namespace BeyondCode\QueryDetector\Outputs;
44

5-
use Illuminate\Http\Response;
65
use Illuminate\Support\Collection;
6+
use Symfony\Component\HttpFoundation\Response;
77

88
class Alert implements Output
99
{
1010
public function output(Collection $detectedQueries, Response $response)
1111
{
12+
if ($response->isRedirection()) {
13+
return;
14+
}
15+
1216
$content = $response->getContent();
1317

1418
$outputContent = $this->getOutputContent($detectedQueries);

src/Outputs/Log.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
namespace BeyondCode\QueryDetector\Outputs;
44

55
use Log as LaravelLog;
6-
use Illuminate\Http\Response;
76
use Illuminate\Support\Collection;
7+
use Symfony\Component\HttpFoundation\Response;
88

99
class Log implements Output
1010
{

src/Outputs/Output.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace BeyondCode\QueryDetector\Outputs;
44

5-
use Illuminate\Http\Response;
65
use Illuminate\Support\Collection;
6+
use Symfony\Component\HttpFoundation\Response;
77

88
interface Output
99
{

src/QueryDetector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace BeyondCode\QueryDetector;
44

55
use DB;
6-
use Illuminate\Http\Response;
76
use Illuminate\Support\Collection;
87
use Illuminate\Database\Eloquent\Builder;
8+
use Symfony\Component\HttpFoundation\Response;
99
use Illuminate\Database\Eloquent\Relations\Relation;
1010

1111
class QueryDetector

tests/QueryDetectorTest.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace BeyondCode\QueryDetector\Tests;
44

5-
use BeyondCode\QueryDetector\Tests\Models\Comment;
65
use Route;
76
use BeyondCode\QueryDetector\QueryDetector;
87
use BeyondCode\QueryDetector\Tests\Models\Post;
98
use BeyondCode\QueryDetector\Tests\Models\Author;
9+
use BeyondCode\QueryDetector\Tests\Models\Comment;
1010

1111
class QueryDetectorTest extends TestCase
1212
{
@@ -207,4 +207,21 @@ public function it_ignores_whitelisted_relations_with_attributes()
207207

208208
$this->assertCount(0, $queries);
209209
}
210+
211+
/** @test */
212+
public function it_ignores_redirects()
213+
{
214+
Route::get('/', function (){
215+
foreach (Post::all() as $post) {
216+
$post->comments;
217+
}
218+
return redirect()->to('/random');
219+
});
220+
221+
$this->get('/');
222+
223+
$queries = app(QueryDetector::class)->getDetectedQueries();
224+
225+
$this->assertCount(1, $queries);
226+
}
210227
}

tests/TestCase.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,6 @@ protected function getEnvironmentSetUp($app)
4343
]);
4444

4545
$app['config']->set('app.key', 'base64:6Cu/ozj4gPtIjmXjr8EdVnGFNsdRqZfHfVjQkmTlg4Y=');
46-
47-
48-
$app['config']->set('logging.default', 'test');
49-
50-
$app['config']->set('logging.channels', [
51-
'test' => [
52-
'driver' => 'custom',
53-
'via' => function () {
54-
$monolog = new Logger('test');
55-
$monolog->pushHandler(new TestHandler());
56-
return $monolog;
57-
},
58-
],
59-
]);
6046
}
6147

6248

0 commit comments

Comments
 (0)