Example #1
0
 /**
  * Test write to file and the read from that file
  */
 public function testIO()
 {
     $data = [1, 2, 'a'];
     $this->writer->printLine($data);
     $reader = new CsvReader($this->writer->getFilePath(), $this->separator);
     $line = $reader->getLine();
     $this->assertEquals($data, $line);
     $this->assertNull($reader->getLine());
     $reader->close();
 }
Example #2
0
 /**
  * in $this->setUp() we did not specify the escape character, so
  * we expect it to be the default which is <code>\</code>
  */
 public function testEscape()
 {
     $this->assertEquals('\\', $this->reader->getEscape());
 }
Example #3
0
 /**
  * @param string $filepath the path to a file containing tokens (one on every line
  *  with no header!).
  *
  * @param string $delimiter as expected by Fiedsch\Data\File\CsvReader
  */
 public function readFromFile($filepath, $delimiter = "\t")
 {
     $reader = new CsvReader($filepath, $delimiter);
     $this->tokensReadFromFile = [];
     while (($line = $reader->getLine()) !== null) {
         if (!$reader->isEmpty($line)) {
             $this->tokensReadFromFile[] = $line[0];
             // we expect the token in the first column
             // the second column might contain further info such as "use this many times"
         }
     }
 }