QueuedExportWithFailedHook.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace Maatwebsite\Excel\Tests\Data\Stubs;
  3. use Exception;
  4. use Illuminate\Database\Eloquent\Collection;
  5. use Maatwebsite\Excel\Concerns\Exportable;
  6. use Maatwebsite\Excel\Concerns\FromCollection;
  7. use Maatwebsite\Excel\Concerns\WithMapping;
  8. use Maatwebsite\Excel\Tests\Data\Stubs\Database\User;
  9. use PHPUnit\Framework\Assert;
  10. class QueuedExportWithFailedHook implements FromCollection, WithMapping
  11. {
  12. use Exportable;
  13. /**
  14. * @var bool
  15. */
  16. public $failed = false;
  17. /**
  18. * @return Collection
  19. */
  20. public function collection()
  21. {
  22. return collect([
  23. new User([
  24. 'firstname' => 'Patrick',
  25. 'lastname' => 'Brouwers',
  26. ]),
  27. ]);
  28. }
  29. /**
  30. * @param User $user
  31. * @return array
  32. */
  33. public function map($user): array
  34. {
  35. throw new Exception('we expect this');
  36. }
  37. /**
  38. * @param Exception $exception
  39. */
  40. public function failed(Exception $exception)
  41. {
  42. Assert::assertEquals('we expect this', $exception->getMessage());
  43. app()->bind('queue-has-failed', function () {
  44. return true;
  45. });
  46. }
  47. }