WithCustomStartCellTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace Maatwebsite\Excel\Tests\Concerns;
  3. use Illuminate\Support\Collection;
  4. use Maatwebsite\Excel\Concerns\FromCollection;
  5. use Maatwebsite\Excel\Concerns\WithCustomStartCell;
  6. use Maatwebsite\Excel\Excel;
  7. use Maatwebsite\Excel\Tests\TestCase;
  8. class WithCustomStartCellTest extends TestCase
  9. {
  10. /**
  11. * @var Excel
  12. */
  13. protected $SUT;
  14. protected function setUp(): void
  15. {
  16. parent::setUp();
  17. $this->SUT = $this->app->make(Excel::class);
  18. }
  19. /**
  20. * @test
  21. */
  22. public function can_store_collection_with_custom_start_cell()
  23. {
  24. $export = new class implements FromCollection, WithCustomStartCell
  25. {
  26. /**
  27. * @return Collection
  28. */
  29. public function collection()
  30. {
  31. return collect([
  32. ['A1', 'B1'],
  33. ['A2', 'B2'],
  34. ]);
  35. }
  36. /**
  37. * @return string
  38. */
  39. public function startCell(): string
  40. {
  41. return 'B2';
  42. }
  43. };
  44. $this->SUT->store($export, 'custom-start-cell.csv');
  45. $contents = $this->readAsArray(__DIR__ . '/../Data/Disks/Local/custom-start-cell.csv', 'Csv');
  46. $this->assertEquals([
  47. [null, null, null],
  48. [null, 'A1', 'B1'],
  49. [null, 'A2', 'B2'],
  50. ], $contents);
  51. }
  52. }