diff --git a/src/Scout.php b/src/Scout.php new file mode 100644 index 00000000..16e0e975 --- /dev/null +++ b/src/Scout.php @@ -0,0 +1,45 @@ +first()->searchableUsing()->update($models); } - dispatch((new MakeSearchable($models)) + dispatch((new Scout::$makeSearchableJob($models)) ->onQueue($models->first()->syncWithSearchUsingQueue()) ->onConnection($models->first()->syncWithSearchUsing())); } @@ -85,7 +85,7 @@ public function queueRemoveFromSearch($models) return $models->first()->searchableUsing()->delete($models); } - dispatch(new RemoveFromSearch($models)) + dispatch(new Scout::$removeFromSearchJob($models)) ->onQueue($models->first()->syncWithSearchUsingQueue()) ->onConnection($models->first()->syncWithSearchUsing()); } diff --git a/tests/Feature/SearchableTest.php b/tests/Feature/SearchableTest.php index 3504bec4..0478c104 100644 --- a/tests/Feature/SearchableTest.php +++ b/tests/Feature/SearchableTest.php @@ -3,6 +3,12 @@ namespace Laravel\Scout\Tests\Feature; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Support\Facades\Queue; +use Laravel\Scout\Jobs\MakeSearchable; +use Laravel\Scout\Jobs\RemoveFromSearch; +use Laravel\Scout\Scout; +use Laravel\Scout\Tests\Fixtures\OverriddenMakeSearchable; +use Laravel\Scout\Tests\Fixtures\OverriddenRemoveFromSearch; use Laravel\Scout\Tests\Fixtures\SearchableModel; use Mockery as m; use Orchestra\Testbench\TestCase; @@ -29,6 +35,24 @@ public function test_searchable_using_update_is_not_called_on_empty_collection() $model->queueMakeSearchable($collection); } + public function test_overridden_make_searchable_is_dispatched() + { + Queue::fake(); + + config()->set('scout.queue', true); + Scout::makeSearchableUsing(OverriddenMakeSearchable::class); + + $collection = m::mock(); + $collection->shouldReceive('isEmpty')->andReturn(false); + $collection->shouldReceive('first->syncWithSearchUsingQueue'); + $collection->shouldReceive('first->syncWithSearchUsing'); + + $model = new SearchableModel; + $model->queueMakeSearchable($collection); + + Scout::makeSearchableUsing(MakeSearchable::class); + } + public function test_searchable_using_delete_is_called_on_collection() { $collection = m::mock(); @@ -49,6 +73,24 @@ public function test_searchable_using_delete_is_not_called_on_empty_collection() $model->queueRemoveFromSearch($collection); } + public function test_overridden_remove_from_search_is_dispatched() + { + Queue::fake(); + + config()->set('scout.queue', true); + Scout::removeFromSearchUsing(OverriddenRemoveFromSearch::class); + + $collection = m::mock(); + $collection->shouldReceive('isEmpty')->andReturn(false); + $collection->shouldReceive('first->syncWithSearchUsingQueue'); + $collection->shouldReceive('first->syncWithSearchUsing'); + + $model = new SearchableModel; + $model->queueRemoveFromSearch($collection); + + Scout::removeFromSearchUsing(RemoveFromSearch::class); + } + public function test_make_all_searchable_uses_order_by() { ModelStubForMakeAllSearchable::makeAllSearchable(); diff --git a/tests/Fixtures/OverriddenMakeSearchable.php b/tests/Fixtures/OverriddenMakeSearchable.php new file mode 100644 index 00000000..f624fbb4 --- /dev/null +++ b/tests/Fixtures/OverriddenMakeSearchable.php @@ -0,0 +1,15 @@ +