CustomPayloadTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace Illuminate\Tests\Integration\Queue;
  3. use Illuminate\Contracts\Bus\QueueingDispatcher;
  4. use Illuminate\Contracts\Queue\ShouldQueue;
  5. use Illuminate\Foundation\Testing\TestCase;
  6. use Illuminate\Queue\Queue;
  7. use Illuminate\Support\ServiceProvider;
  8. use Orchestra\Testbench\Concerns\CreatesApplication;
  9. class CustomPayloadTest extends TestCase
  10. {
  11. use CreatesApplication;
  12. protected function getPackageProviders($app)
  13. {
  14. return [QueueServiceProvider::class];
  15. }
  16. public function websites()
  17. {
  18. yield ['laravel.com'];
  19. yield ['blog.laravel.com'];
  20. }
  21. /**
  22. * @dataProvider websites
  23. */
  24. public function test_custom_payload_gets_cleared_for_each_data_provider(string $websites)
  25. {
  26. $dispatcher = $this->app->make(QueueingDispatcher::class);
  27. $dispatcher->dispatchToQueue(new MyJob);
  28. }
  29. }
  30. class QueueServiceProvider extends ServiceProvider
  31. {
  32. public function register()
  33. {
  34. $this->app->bind('one.time.password', function () {
  35. return random_int(1, 10);
  36. });
  37. Queue::createPayloadUsing(function () {
  38. $password = $this->app->make('one.time.password');
  39. $this->app->offsetUnset('one.time.password');
  40. return ['password' => $password];
  41. });
  42. }
  43. }
  44. class MyJob implements ShouldQueue
  45. {
  46. public $connection = 'sync';
  47. public function handle()
  48. {
  49. //
  50. }
  51. }