Exemplo n.º 1
0
 /**
  * @dataProvider parseExceptionsData
  *
  * @param string $csv
  * @param string $exception
  */
 public function testParseExceptions($csv, $exception)
 {
     $tokeniser = new StringTokeniser(new CsvConfiguration(), $csv);
     $parser = new Parser();
     static::expectException($exception);
     iterator_to_array($parser->parse($tokeniser->getTokens()));
 }
Exemplo n.º 2
0
 public function testParserIteratesSoNothingShouldHappenIfThereIsNoRequestForData()
 {
     $parser = new Parser();
     /** @var Iterator $tokens */
     $tokens = m::mock(Iterator::class);
     $output = $parser->parse($tokens);
     static::assertInstanceOf(Iterator::class, $output);
 }
Exemplo n.º 3
0
 /**
  * @dataProvider getFixtures
  *
  * @param string $path
  * @param int    $iterations
  */
 public function testPerformance($path, $iterations)
 {
     $runs = array_pad([], $iterations, -1);
     foreach ($runs as &$iteration) {
         $start = microtime(true);
         $parser = new Parser();
         $tokeniser = new StreamTokeniser(new CsvConfiguration(), fopen($path, 'r'));
         foreach ($parser->parse($tokeniser->getTokens()) as $row) {
             echo '';
         }
         $iteration = microtime(true) - $start;
     }
     $average = array_sum($runs) / count($runs);
     printf("\nPath: %s - iterations: %d - average: %.2f ms\n", $path, count($runs), $average * 1000);
 }
Exemplo n.º 4
0
 /**
  * @param resource $stream
  *
  * @return Iterator
  */
 public function parse($stream)
 {
     $tokeniser = new StreamTokeniser($this->csvFormat, $stream);
     $parser = new Parser();
     return $this->parseIterator($parser->parse($tokeniser->getTokens()));
 }
Exemplo n.º 5
0
 /**
  * @return Iterator Iterator of csv line arrays
  */
 public function read()
 {
     $tokens = new StreamTokeniser($this->config, $this->stream);
     $parser = new Parser();
     return $parser->parse($tokens->getTokens());
 }