/** * @return void */ public function testExtractSharedStringsShouldCreateTempFileWithSharedStrings() { $this->sharedStringsHelper->extractSharedStrings(); $tempFolder = \ReflectionHelper::getValueOnObject($this->sharedStringsHelper, 'tempFolder'); $filesInTempFolder = $this->getFilesInFolder($tempFolder); $this->assertEquals(1, count($filesInTempFolder), 'One temp file should have been created in the temp folder.'); $tempFileContents = file_get_contents($filesInTempFolder[0]); $tempFileContentsPerLine = explode(PHP_EOL, $tempFileContents); $this->assertEquals('s1--A1', $tempFileContentsPerLine[0]); $this->assertEquals('s1--E5', $tempFileContentsPerLine[24]); }
/** * @return void */ public function testGetStringAtIndexWithFileBasedStrategy() { // force the file-based strategy by setting no memory limit $originalMemoryLimit = ini_get('memory_limit'); ini_set('memory_limit', '-1'); $resourcePath = $this->getResourcePath('sheet_with_lots_of_shared_strings.xlsx'); $sharedStringsHelper = new SharedStringsHelper($resourcePath); $sharedStringsHelper->extractSharedStrings(); $sharedString = $sharedStringsHelper->getStringAtIndex(0); $this->assertEquals('str', $sharedString); $sharedString = $sharedStringsHelper->getStringAtIndex(CachingStrategyFactory::MAX_NUM_STRINGS_PER_TEMP_FILE + 1); $this->assertEquals('str', $sharedString); $usedCachingStrategy = \ReflectionHelper::getValueOnObject($sharedStringsHelper, 'cachingStrategy'); $this->assertTrue($usedCachingStrategy instanceof FileBasedStrategy); $sharedStringsHelper->cleanup(); ini_set('memory_limit', $originalMemoryLimit); }