spatie/laravel-pdf

[Bug]: Defaults not used when running queue:work

Propaganistas opened this issue · 10 comments

What happened?

I've set defaults for the PdfBuilder in a service provider's boot() method as described in the docs.

When a PDF gets generated in a queued job:

  • the defaults are applied when powering the queue using queue:listen
  • the defaults are NOT applied when powering the queue using queue:work

How to reproduce the bug

  1. Create a fresh Laravel application (I'm on 10.x).
  2. Change queue connection to database and publish the jobs table
  3. Set defaults in AppServiceProvider boot() (e.g. Pdf::default()->margin(0.4, 0.4, 0.4, 0.4, Unit::Inch)
  4. Create a job that generates a PDF ( e.g. Pdf::view('welcome')->save('somewhere'))
  5. Run queue:work
  6. Enqueue the job using Tinker (or otherwise) and check result

Or temporarily add a dump statement in PdfBuilder's view() method to check the margins property and return early.
You'll notice the margins are set when running queue:listen but remain null when running queue:work.

Package Version

1.4.0

PHP Version

8.3.3

Laravel Version

10.48.4

Is there some way to add a test for this?

Is there some way to add a test for this?

Not sure. I think you could borrow ideas from framework tests?

https://github.com/laravel/framework/blob/10.x/tests/Queue/QueueWorkerTest.php