/**
  * @dataProvider dataProviderForTestGetBestCachingStrategy
  *
  * @param int $sharedStringsUniqueCount
  * @param int $memoryLimitInKB
  * @param string $expectedStrategyClassName
  * @return void
  */
 public function testGetBestCachingStrategy($sharedStringsUniqueCount, $memoryLimitInKB, $expectedStrategyClassName)
 {
     /** @var CachingStrategyFactory|\PHPUnit_Framework_MockObject_MockObject $factoryStub */
     $factoryStub = $this->getMockBuilder('\\Box\\Spout\\Reader\\XLSX\\Helper\\SharedStringsCaching\\CachingStrategyFactory')->disableOriginalConstructor()->setMethods(['getMemoryLimitInKB'])->getMock();
     $factoryStub->method('getMemoryLimitInKB')->willReturn($memoryLimitInKB);
     \ReflectionHelper::setStaticValue('\\Box\\Spout\\Reader\\XLSX\\Helper\\SharedStringsCaching\\CachingStrategyFactory', 'instance', $factoryStub);
     $strategy = $factoryStub->getBestCachingStrategy($sharedStringsUniqueCount, null);
     $fullExpectedStrategyClassName = 'Box\\Spout\\Reader\\XLSX\\Helper\\SharedStringsCaching\\' . $expectedStrategyClassName;
     $this->assertEquals($fullExpectedStrategyClassName, get_class($strategy));
     $strategy->clearCache();
     \ReflectionHelper::reset();
 }
示例#2
0
 /**
  * @return void
  */
 public function testAddRowShouldNotCreateNewSheetsIfMaxRowsReachedAndOptionTurnedOff()
 {
     $fileName = 'test_add_row_should_not_create_new_sheets_if_max_rows_reached_and_option_turned_off.xlsx';
     $dataRows = [['xlsx--sheet1--11', 'xlsx--sheet1--12'], ['xlsx--sheet1--21', 'xlsx--sheet1--22', 'xlsx--sheet1--23'], ['xlsx--sheet1--31', 'xlsx--sheet1--32']];
     // set the maxRowsPerSheet limit to 2
     \ReflectionHelper::setStaticValue('\\Box\\Spout\\Writer\\XLSX\\Internal\\Workbook', 'maxRowsPerWorksheet', 2);
     $writer = $this->writeToXLSXFile($dataRows, $fileName, true, $shouldCreateSheetsAutomatically = false);
     $this->assertEquals(1, count($writer->getSheets()), 'Only 1 sheet should have been created.');
     $this->assertInlineDataWasNotWrittenToSheet($fileName, 1, 'xlsx--sheet1--31');
     \ReflectionHelper::reset();
 }