Laravel

Testing invoice PDF generation

Hello,

I am running into a strange issue with a failing test.

Error:

Unable to find a file or directory at path

The test:

(I have slimmed it down)

test('a PDF is generated when an invoice is created', function () {
    Storage::fake();

    // create a user with it's roles and permissions, login, etc

    // prepare the data
    $invoice = Invoice::factory()->make(...);

    post(..., ...);

    // do some basic assertions

    // we need to fetch the invoice so we have a model instance, we know that the first invoice will be the correct invoice
    $invoice = Invoice::first();

    Storage::disk()->assertExists($invoice->path());
});

I can see the PDF in the storage folder. What's very strange is, even if I sleep 30 seconds, the PDF doesn't appear to generate (as observed in the file explorer) until the test has finished running (failed).

Haz
Haz
Moderator
0
0
268