QueuedExportWithFailedEvents.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace Maatwebsite\Excel\Tests\Data\Stubs;
  3. use Exception;
  4. use Maatwebsite\Excel\Concerns\Exportable;
  5. use Maatwebsite\Excel\Concerns\WithEvents;
  6. use Maatwebsite\Excel\Concerns\WithMultipleSheets;
  7. use Maatwebsite\Excel\Events\BeforeExport;
  8. use PHPUnit\Framework\Assert;
  9. use Throwable;
  10. class QueuedExportWithFailedEvents implements WithMultipleSheets, WithEvents
  11. {
  12. use Exportable;
  13. /**
  14. * @return SheetWith100Rows[]
  15. */
  16. public function sheets(): array
  17. {
  18. return [
  19. new SheetWith100Rows('A'),
  20. new SheetWith100Rows('B'),
  21. new SheetWith100Rows('C'),
  22. ];
  23. }
  24. /**
  25. * @param Throwable $exception
  26. */
  27. public function failed(Throwable $exception)
  28. {
  29. Assert::assertEquals('catch exception from QueueExport job', $exception->getMessage());
  30. app()->bind('queue-has-failed-from-queue-export-job', function () {
  31. return true;
  32. });
  33. }
  34. /**
  35. * @return array
  36. */
  37. public function registerEvents(): array
  38. {
  39. return [
  40. BeforeExport::class => function () {
  41. throw new Exception('catch exception from QueueExport job');
  42. },
  43. ];
  44. }
  45. }