Could you post the full test, as well as how $this->batch_uploadis set ?
Laravel 8 - Testing a Package: record not found in db after queue has altered it
In my test, I post a fake image that is saved on a fake disk. This works
the tested controller save a record and dispatch a job
Queue::assertPushed(UnpackUploadedFile::class, 1);
This test passes, I've a job dispatched
The job's handle() method alters the row just created, using update
$this->batch_upload->update([
'mime_type' => $mime,
'status' => BatchUploadStatus::MIME_IDENTIFIED
]);
Then I dump (just for debugging ...) the record, and I can see
[mime_type] => image/jpeg
[status] => mime_identified
So I think that record has been altered in db.
Then my test [SAME TEST !] go on and tests db record
$this->assertDatabaseHas(app(BatchUpload::class)->getTable(), [
'original_file_name' => $fake_image->getClientOriginalName(),
'disk_name' => $this->disk_name,
'disk_path' => $fake_image->getClientOriginalName(),
'status' => BatchUploadStatus::MIME_IDENTIFIED,
'mime_type' => 'image/jpeg'
]);
I am getting this
Failed asserting that a row in the table [product_image_batch_uploads] matches the attributes {
"original_file_name": "photo1.jpg",
"disk_name": "product_image",
"disk_path": "photo1.jpg",
"status": "mime_identified",
"mime_type": "image\/jpeg"
}.
Found similar results: [
{
"id": "1",
"token": "a27afd8c-5c11-45e8-a0f7-36a8b56fced0",
"original_file_name": "photo1.jpg",
"disk_name": "product_image",
"disk_path": "photo1.jpg",
"mime_type": null,
"status": "uploaded_locally",
"created_at": "2020-12-01 10:28:23",
"updated_at": "2020-12-01 10:28:23",
"deleted_at": null
}
].
So, in brief, job is dispatched, job does things and really alters the record, but when doing a lookup, the record looks like it has not been altered.
Note: I repeat: it's a single function, so db is not truncated and recreated in between the two actions
For testing I am using sqlite with :memory: as db
Please or to participate in this conversation.