RemembersChunkOffsetTest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace Maatwebsite\Excel\Tests\Concerns;
  3. use Maatwebsite\Excel\Concerns\Importable;
  4. use Maatwebsite\Excel\Concerns\RemembersChunkOffset;
  5. use Maatwebsite\Excel\Concerns\ToArray;
  6. use Maatwebsite\Excel\Concerns\WithChunkReading;
  7. use Maatwebsite\Excel\Tests\TestCase;
  8. class RemembersChunkOffsetTest extends TestCase
  9. {
  10. /**
  11. * @test
  12. */
  13. public function can_set_and_get_chunk_offset()
  14. {
  15. $import = new class
  16. {
  17. use Importable;
  18. use RemembersChunkOffset;
  19. };
  20. $import->setChunkOffset(50);
  21. $this->assertEquals(50, $import->getChunkOffset());
  22. }
  23. /**
  24. * @test
  25. */
  26. public function can_access_chunk_offset_on_import_to_array_in_chunks()
  27. {
  28. $import = new class implements ToArray, WithChunkReading
  29. {
  30. use Importable;
  31. use RemembersChunkOffset;
  32. public $offsets = [];
  33. public function array(array $array)
  34. {
  35. $this->offsets[] = $this->getChunkOffset();
  36. }
  37. public function chunkSize(): int
  38. {
  39. return 2000;
  40. }
  41. };
  42. $import->import('import-batches.xlsx');
  43. $this->assertEquals([1, 2001, 4001], $import->offsets);
  44. }
  45. }