/** * @param string $xmlFixtureFile * @param string $expect * @dataProvider provideData */ public function test($xmlFixtureFile, $expect) { $xml = file_get_contents(__DIR__ . '/../../data/xml/' . $xmlFixtureFile); $zip = $this->getMockBuilder(ZipArchive::class)->disableOriginalConstructor()->getMock(); $zip->expects($this->atLeastOnce())->method('getFromName')->with('xl/worksheet/sheet1.xml')->will($this->returnValue($xml)); $bookUtil = $this->getMock(BookUtil::class); $dummySheetMap = ['テスト' => 'xl/worksheet/sheet1.xml']; $bookUtil->expects($this->once())->method('makeSheetFileMap')->with($zip)->will($this->returnValue($dummySheetMap)); $reader = new CellSelectionReader($bookUtil); $this->assertEquals($expect, $reader->read($zip, 'テスト')); }
/** * @param ZipArchive $xlsx * @param ZipArchive|null $template */ public function setSelection(ZipArchive $xlsx, ZipArchive $template = null) { if (!$template instanceof ZipArchive) { throw new \RuntimeException('Invalid template'); } // テンプレートで選択されているシートを取得 $selectedSheet = $this->sheetReader->read($template); // テンプレートの各シートで選択されているセルを取得 $sheets = $this->bookUtil->makeSheetMap($template); $selectedCells = []; foreach ($sheets as $sheetId => $sheetName) { $selectedCells[$sheetName] = $this->cellReader->read($template, $sheetName); } // 選択シートを書き込む $this->sheetSetter->set($xlsx, $selectedSheet); // 各シートの選択セルを書き込む foreach ($selectedCells as $sheetName => $cellPosition) { $this->cellSetter->set($xlsx, $sheetName, $cellPosition); } }