I'm writing a test for finding models with Scout. I'm on Laravel 5.4 and use the provider "tamayo/laravel-scout-elastic": "^3.0"
.
It seems that in my tests indexing the created items isn't completed when I start searching for a model. Is this true? How can I fix this? My queue is already set to sync
and SCOUT_QUEUE
is set to false
.
Here is an example of a test that keeps failing (Failed asserting that search results contain the given post). Any help is greatly appreciated.
<?php
namespace Tests\Unit;
use App\Models\Category;
use App\Models\Post;
use App\Models\User;
use Tests\TestCase;
class SearchTest extends TestCase
{
/** @test * */
public function it_searches_the_whole_category_tree_for_posts()
{
// Given
/** @var Category $parentCategory */
$parentCategory = \factory(Category::class)->create([
'title' => 'myParentCategory',
]);
/** @var Category $childCategory */
$childCategory = \factory(Category::class)->create();
$childCategory->makeChildOf($parentCategory);
/** @var Post $post */
$post = \factory(Post::class)->create([
'user_id' => \factory(User::class)->create()->id,
]);
$post->requestCategories()->attach($childCategory);
// When
$searchResults = Post::search('myParentCategory')->get();
// Then
$this->assertTrue($searchResults->contains($post), 'Failed asserting that search results contain the given post.');
}
}