/**
  * Tests that line count is correct.
  *
  * @test
  *
  * @covers ::count
  */
 public function countLines()
 {
     $expected = 15;
     $this->csvFileObject->setHeaderRowCount(1);
     $actual = $this->csvFileObject->count();
     $this->assertEquals($expected, $actual);
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function initializeIterator()
 {
     // File handler using header-rows-respecting extension of SPLFileObject.
     $file = new CSVFileObject($this->configuration['path']);
     // Set basics of CSV behavior based on configuration.
     $delimiter = !empty($this->configuration['delimiter']) ? $this->configuration['delimiter'] : ',';
     $enclosure = !empty($this->configuration['enclosure']) ? $this->configuration['enclosure'] : '"';
     $escape = !empty($this->configuration['escape']) ? $this->configuration['escape'] : '\\';
     $file->setCsvControl($delimiter, $enclosure, $escape);
     // Figure out what CSV column(s) to use.
     if (!empty($this->configuration['header_row_count'])) {
         $file->setHeaderRowCount($this->configuration['header_row_count']);
         // Find the last header line.
         $file->rewind();
         $file->seek($file->getHeaderRowCount() - 1);
         // Use the header row(s).
         if (empty($this->configuration['column_names'])) {
             $row = $file->current();
             foreach ($row as $header) {
                 $header = trim($header);
                 $column_names[] = array($header => $header);
             }
             $file->setColumnNames($column_names);
         }
     }
     // An explicit list of column name(s) is provided.
     if (!empty($this->configuration['column_names'])) {
         $file->setColumnNames($this->configuration['column_names']);
     }
     return $file;
 }