Skip to content

Commit

Permalink
Laravel - filter migration queries when running in a unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
itsgoingd committed Nov 5, 2019
1 parent e3afeb1 commit dced783
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Clockwork/Support/Laravel/ClockworkServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Clockwork\DataSource\PhpDataSource;
use Clockwork\DataSource\SwiftDataSource;
use Clockwork\DataSource\XdebugDataSource;
use Clockwork\Helpers\StackFilter;
use Clockwork\Request\Log;
use Clockwork\Storage\StorageInterface;

Expand Down Expand Up @@ -130,14 +131,25 @@ protected function registerDataSources()
});

$this->app->singleton('clockwork.eloquent', function ($app) {
return (new EloquentDataSource(
$dataSource = (new EloquentDataSource(
$app['db'],
$app['events'],
$app['clockwork.support']->getConfig('features.database.collect_queries'),
$app['clockwork.support']->getConfig('features.database.slow_threshold'),
$app['clockwork.support']->getConfig('features.database.slow_only'),
$app['clockwork.support']->getConfig('features.database.detect_duplicate_queries')
));

if ($app->runningUnitTests()) {
$dataSource->addFilter(function ($query, $trace) {
return ! $trace->first(StackFilter::make()->isClass([
\Illuminate\Database\Migrations\Migrator::class,
\Illuminate\Database\Console\Migrations\MigrateCommand::class
]));
});
}

return $dataSource;
});

$this->app->singleton('clockwork.events', function ($app) {
Expand Down

0 comments on commit dced783

Please sign in to comment.