1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- namespace Maatwebsite\Excel\Tests\Concerns;
- use ArrayIterator;
- use Iterator;
- use Maatwebsite\Excel\Concerns\Exportable;
- use Maatwebsite\Excel\Concerns\FromIterator;
- use Maatwebsite\Excel\Tests\TestCase;
- class FromIteratorTest extends TestCase
- {
- /**
- * @test
- */
- public function can_export_from_iterator()
- {
- $export = new class implements FromIterator
- {
- use Exportable;
- /**
- * @return array
- */
- public function array()
- {
- return [
- ['test', 'test'],
- ['test', 'test'],
- ];
- }
- /**
- * @return Iterator
- */
- public function iterator(): Iterator
- {
- return new ArrayIterator($this->array());
- }
- };
- $response = $export->store('from-iterator-store.xlsx');
- $this->assertTrue($response);
- $contents = $this->readAsArray(__DIR__ . '/../Data/Disks/Local/from-iterator-store.xlsx', 'Xlsx');
- $this->assertEquals($export->array(), $contents);
- }
- }
|