/**
  * @param FlatItemBuffer $buffer
  * @param array          $writerOptions
  * @param int            $maxLinesPerFile
  * @param string         $basePathname
  *
  * @return array
  */
 protected function writeIntoSeveralFiles(FlatItemBuffer $buffer, array $writerOptions, $maxLinesPerFile, $basePathname)
 {
     $writtenFiles = [];
     $basePathPattern = $this->getNumberedPathname($basePathname);
     $writtenLinesCount = 0;
     $fileCount = 1;
     $headers = $this->sortHeaders($buffer->getHeaders());
     $hollowItem = array_fill_keys($headers, '');
     foreach ($buffer as $count => $incompleteItem) {
         if (0 === $writtenLinesCount % $maxLinesPerFile) {
             $filePath = $this->resolveFilePath($buffer, $maxLinesPerFile, $basePathPattern, $fileCount);
             $writtenLinesCount = 0;
             $writer = $this->getWriter($filePath, $writerOptions);
             $writer->addRow($headers);
         }
         $item = array_replace($hollowItem, $incompleteItem);
         $writer->addRow($item);
         $writtenLinesCount++;
         if (null !== $this->stepExecution) {
             $this->stepExecution->incrementSummaryInfo('write');
         }
         if (0 === $writtenLinesCount % $maxLinesPerFile || $buffer->count() === $count + 1) {
             $writer->close();
             $writtenFiles[] = $filePath;
             $fileCount++;
         }
     }
     return $writtenFiles;
 }
 function it_throws_an_exception_if_type_is_not_recognized($columnSorter, FlatItemBuffer $buffer, StepExecution $stepExecution, JobParameters $parameters)
 {
     $columnSorter->sort(Argument::any(), [])->willReturn(['colA', 'colB']);
     $stepExecution->getJobParameters()->willReturn($parameters);
     $parameters->all()->willReturn([]);
     $buffer->getHeaders()->willReturn(['colA', 'colB']);
     $this->shouldThrow('Box\\Spout\\Common\\Exception\\UnsupportedTypeException')->during('flush', [$buffer, ['type' => 'undefined'], Argument::any()]);
 }