Well @sti3bas I come hat-in-hand. You were right. After clearing the cache:
Call to a member function wait() on string
So, I've gone back and trying to implement your code base Sti3bas / laravel-scout-array-driver.
I'm having a hard time figuring out how to upload an image in addition to creating the job.
e.g. spatie laravel media-library uses the Media model - because the image path is not saved in the job model (by Spatie design)
$response = $this->actingAs($user)
->post('/jobs', $this->validParams(['document' => UploadedFile::fake()->image('lumber.jpg')]))
->assertRedirect('/searchjobs');
This error ErrorException: mb_strlen() expects parameter 1 to be string, object given is upset, I believe, that the file is an object and not the document name. It'd be easy to upload a string, but then the Media model would not have been created.
I've gone back to Adam Wathan's Test Driven Development course on uploading concert pictures, but the scenario is a bit different.
This is what I've got so far:
/** @test */
public function a_job_is_indexed_to_algolia()
{
$this->withoutExceptionHandling();
Event::fake();
Mail::fake();
Mail::assertNothingSent();
Search::assertEmpty();
Storage::fake('media');
$user = factory(User::class)->create();
$job = $this->actingAs($user)
->post('/jobs', $this->validParams(['document' => UploadedFile::fake()->image('lumber.jpg')]))
->assertRedirect('/searchjobs');
// this is where the error is occuring above.
Storage::disk('media')->assertExists('lumber.jpg');
// $thumbUrl = optional($job->getMedia('document')->first()->getUrl('thumbnail')); // your line
$job2 = SlugJob::withoutSyncingToSearch(function () {
return factory(SlugJob::class)->create([
'body' => 'Concrete',
]);
});
// Search::assertSynced($job);
// Search::assertEmpty($job2);
dd($job);
//
Search::assertContainsIn('jobs', $job)
->assertNotContains($job2)
->assertContains($job, function ($record) {
return $record['body'] === 'Sealants';
})
// ->assertContains($job, function ($record) {
// return $record['thumbUrl'] === $thumbUrl;
// })
->assertNotContains($job, function ($record) {
return $record['body'] === 'Concrete';
});
}
I've gone back to laravel media library to try and see what they do, but if I'm not mistaken, I shouldn't be concerned about the uploading functionality, just when the search index is sent to algolia.
At this point, I've got queues working, which seem to have a greater ability to save the image path in time for indexing, but I'd like to see what you do with events and how you prevent the syncing before the entire index is ready to send to algolia - if you can share `
Thank you