FromIteratorTest.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace Maatwebsite\Excel\Tests\Concerns;
  3. use ArrayIterator;
  4. use Iterator;
  5. use Maatwebsite\Excel\Concerns\Exportable;
  6. use Maatwebsite\Excel\Concerns\FromIterator;
  7. use Maatwebsite\Excel\Tests\TestCase;
  8. class FromIteratorTest extends TestCase
  9. {
  10. /**
  11. * @test
  12. */
  13. public function can_export_from_iterator()
  14. {
  15. $export = new class implements FromIterator
  16. {
  17. use Exportable;
  18. /**
  19. * @return array
  20. */
  21. public function array()
  22. {
  23. return [
  24. ['test', 'test'],
  25. ['test', 'test'],
  26. ];
  27. }
  28. /**
  29. * @return Iterator
  30. */
  31. public function iterator(): Iterator
  32. {
  33. return new ArrayIterator($this->array());
  34. }
  35. };
  36. $response = $export->store('from-iterator-store.xlsx');
  37. $this->assertTrue($response);
  38. $contents = $this->readAsArray(__DIR__ . '/../Data/Disks/Local/from-iterator-store.xlsx', 'Xlsx');
  39. $this->assertEquals($export->array(), $contents);
  40. }
  41. }