Closed tooshay closed 2 years ago
@tooshay I was not able to reproduce it, can you show the code of your test file?
@Sti3bas Here's what I have:
<?php
namespace Tests\Unit\Employees;
use App\Models\Employee;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Scout\Searchable;
use Sti3bas\ScoutArray\Search;
use Tests\TestCase;
class SearchIndexTest extends TestCase
{
use RefreshDatabase;
public function test_it_indexes_models()
{
$user = Employee::factory()->create([
'forename' => 'Oliver',
]);
$user2 = Employee::withoutSyncingToSearch(function () {
return Employee::factory()->create([
'forename' => 'John',
]);
});
Search::assertContains($user) // ✅
->assertContains($user2) // ❌
->assertContains($user, function ($record) { // ✅
return $record['forename'] === 'Oliver';
})
->assertContains($user, function ($record) { // ❌
return $record['forename'] === 'John';
})
->assertContains($user2, function ($record) { // ❌
return $record['forename'] === 'John';
});
}
}
@tooshay still can't reproduce it.. can you try to reproduce it yourself in a fresh Laravel installation and share a repository with me?
OK, figured it out. PHPStorm pulled in Sti3bas\ScoutArray\Search
instead of Sti3bas\ScoutArray\Facades\Search
!
I'm assuming it's a silly omission on my side, but when trying to run the first example test from your documentation (
Search::assertContains($user)...
), I get this error:Running Laravel 8.75, PHP 7.4 with Elastic as the Scout driver (using babenkoivan's implementation).