FromCollectionTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace Maatwebsite\Excel\Tests\Concerns;
  3. use Maatwebsite\Excel\Tests\Data\Stubs\QueuedExport;
  4. use Maatwebsite\Excel\Tests\Data\Stubs\SheetWith100Rows;
  5. use Maatwebsite\Excel\Tests\TestCase;
  6. class FromCollectionTest extends TestCase
  7. {
  8. /**
  9. * @test
  10. */
  11. public function can_export_from_collection()
  12. {
  13. $export = new SheetWith100Rows('A');
  14. $response = $export->store('from-collection-store.xlsx');
  15. $this->assertTrue($response);
  16. $contents = $this->readAsArray(__DIR__ . '/../Data/Disks/Local/from-collection-store.xlsx', 'Xlsx');
  17. $this->assertEquals($export->collection()->toArray(), $contents);
  18. }
  19. /**
  20. * @test
  21. */
  22. public function can_export_with_multiple_sheets_from_collection()
  23. {
  24. $export = new QueuedExport();
  25. $response = $export->store('multiple-sheets-collection-store.xlsx');
  26. $this->assertTrue($response);
  27. foreach ($export->sheets() as $sheetIndex => $sheet) {
  28. $spreadsheet = $this->read(
  29. __DIR__ . '/../Data/Disks/Local/multiple-sheets-collection-store.xlsx',
  30. 'Xlsx'
  31. );
  32. $worksheet = $spreadsheet->getSheet($sheetIndex);
  33. $this->assertEquals($sheet->collection()->toArray(), $worksheet->toArray());
  34. $this->assertEquals($sheet->title(), $worksheet->getTitle());
  35. }
  36. }
  37. }