1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace Maatwebsite\Excel\Tests\Concerns;
- use Illuminate\Support\Collection;
- use Maatwebsite\Excel\Concerns\Importable;
- use Maatwebsite\Excel\Concerns\ToCollection;
- use Maatwebsite\Excel\Tests\TestCase;
- use PHPUnit\Framework\Assert;
- class ToCollectionTest extends TestCase
- {
- /**
- * @test
- */
- public function can_import_to_collection()
- {
- $import = new class implements ToCollection
- {
- use Importable;
- public $called = false;
- /**
- * @param Collection $collection
- */
- public function collection(Collection $collection)
- {
- $this->called = true;
- Assert::assertEquals([
- ['test', 'test'],
- ['test', 'test'],
- ], $collection->toArray());
- }
- };
- $import->import('import.xlsx');
- $this->assertTrue($import->called);
- }
- /**
- * @test
- */
- public function can_import_multiple_sheets_to_collection()
- {
- $import = new class implements ToCollection
- {
- use Importable;
- public $called = 0;
- /**
- * @param Collection $collection
- */
- public function collection(Collection $collection)
- {
- $this->called++;
- $sheetNumber = $this->called;
- Assert::assertEquals([
- [$sheetNumber . '.A1', $sheetNumber . '.B1'],
- [$sheetNumber . '.A2', $sheetNumber . '.B2'],
- ], $collection->toArray());
- }
- };
- $import->import('import-multiple-sheets.xlsx');
- $this->assertEquals(2, $import->called);
- }
- }
|