public function testTsvAction() { $data = [['id' => '1', 'name' => 'ciao', 'a' => 'mondo'], ['id' => '2', 'name' => 'hello', 'a' => 'world']]; $writer = new TSV(); $writer->openURI('tsv.tsv'); echo $writer->beginOutput(); foreach ($data as $doc) { echo $writer->addDocument($doc); sleep(5); } echo $writer->endOutput(); }
/** * Setup a file, named after the child class, where to write test's data, before the first test of the child class * is executed * * Note that if this file already exists it will NOT be overriden. */ public static function setUpBeforeClass() { $directory = '../data/'; if (!file_exists($directory)) { mkdir($directory, 0777, true); } $fullname = get_called_class(); $fullname = strtolower(end(explode('\\', $fullname))); $fullname = str_replace('test', '', $fullname); self::$filename = $directory . $fullname . '.tsv'; self::$write = !file_exists(self::$filename) ? true : false; if (static::$write) { self::$writer = new TSV(); self::$writer->openURI(self::$filename); self::$writer->beginOutput(); self::$line = 0; self::$writer->addDocument(['id' => 'ID'] + static::$header); } }