1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace Maatwebsite\Excel\Tests\Concerns;
- use Maatwebsite\Excel\Concerns\Importable;
- use Maatwebsite\Excel\Concerns\RemembersChunkOffset;
- use Maatwebsite\Excel\Concerns\ToArray;
- use Maatwebsite\Excel\Concerns\WithChunkReading;
- use Maatwebsite\Excel\Tests\TestCase;
- class RemembersChunkOffsetTest extends TestCase
- {
- /**
- * @test
- */
- public function can_set_and_get_chunk_offset()
- {
- $import = new class
- {
- use Importable;
- use RemembersChunkOffset;
- };
- $import->setChunkOffset(50);
- $this->assertEquals(50, $import->getChunkOffset());
- }
- /**
- * @test
- */
- public function can_access_chunk_offset_on_import_to_array_in_chunks()
- {
- $import = new class implements ToArray, WithChunkReading
- {
- use Importable;
- use RemembersChunkOffset;
- public $offsets = [];
- public function array(array $array)
- {
- $this->offsets[] = $this->getChunkOffset();
- }
- public function chunkSize(): int
- {
- return 2000;
- }
- };
- $import->import('import-batches.xlsx');
- $this->assertEquals([1, 2001, 4001], $import->offsets);
- }
- }
|