protected function processAll($filepath, $preview = false) { //configre a CsvBulkLoaderSource $source = new CsvBulkLoaderSource(); $source->setFilePath($filepath); $source->setHasHeader($this->hasHeaderRow); $source->setFieldDelimiter($this->delimiter); $source->setFieldEnclosure($this->enclosure); $this->setSource($source); return parent::processAll($filepath, $preview); }
/** * @group testme */ public function testWithHeaderFile() { $source = new CsvBulkLoaderSource(); $source->setFilePath(dirname(__FILE__) . "/fixtures/Players_WithHeader.csv")->setHasHeader(true); $rowassertions = array(array("FirstName" => "John", "Biography" => "He's a good guy", "Ignore" => "ignored", "Birthday" => "31/01/1988", "IsRegistered" => "1"), array("FirstName" => "Jane", "Biography" => "She is awesome.\\nSo awesome that she gets multiple rows and \\\"escaped\\\" strings in her biography", "Ignore" => "ignored", "Birthday" => "31/01/1982", "IsRegistered" => "0"), array("FirstName" => "Jamie", "Biography" => "Pretty old\\, with an escaped comma", "Ignore" => "ignored", "Birthday" => "31/01/1882", "IsRegistered" => "1"), array("FirstName" => "Järg", "Biography" => "Unicode FTW", "Ignore" => "ignored", "Birthday" => "31/06/1982", "IsRegistered" => "1"), array("FirstName" => "", "Biography" => "nobio missing data", "Ignore" => "ignored")); $iterator = $source->getIterator(); $count = 0; foreach ($iterator as $record) { $this->assertEquals($rowassertions[$count], $record, "Row {$count} is valid"); $count++; } //assert header is correct $this->assertEquals($source->getFirstRow(), array("FirstName", "Biography", "Ignore", "Birthday", "IsRegistered")); }