protected function storeResults($resultsPath, $name, $incremental) { $configuration = new Configuration($resultsPath, $name, new Temp('test')); $files = [Table::create('first', ['col1', 'col2']), Table::create('second', ['col11', 'col12'])]; $files[0]->writeRow(['a', 'b']); $files[1]->writeRow(['c', 'd']); $configuration->storeResults($files, $name, true, $incremental); foreach (new \DirectoryIterator('./Tests/data/storeResultsTest/out/tables/' . $name) as $file) { self::assertFileEquals($file->getPathname(), $resultsPath . '/out/tables/' . $name . '/' . $file->getFilename()); } $this->rmDir($resultsPath); }
public function testPrimaryKeyEmpty() { $table = Table::create('pk', ['id', 'user', 'data']); $this->assertNull($table->getPrimaryKey()); }
/** * Parse the data * @param array|object $data shall be the response body * @param string $type is a WSDL data type (has to be obtained from the WSDL definition) * @param string $path a path to the results list(the array containing each record) within the response * @param string $parent used internally for naming child arrays/columns * @param string $parentId used internally to link child objects to parent */ public function parse($data, $type, $path = null, $parent = null, $parentId = null) { if (!empty($path)) { $data = Utils::getDataFromPath($path, $data); } $fileName = $type; if (empty($this->csvFiles[$fileName])) { $header = array_keys($this->struct[$type]); if ($parentId) { array_push($header, "WSDL_parentId"); } $this->csvFiles[$fileName] = Table::create($fileName, $header, $this->getTemp()); } $handle = $this->csvFiles[$fileName]; $struct = $this->struct[$type]; foreach (Utils::to_assoc($data) as $record) { $row = []; foreach ($struct as $key => $valueType) { if (empty($record[$key])) { $row[$key] = null; } elseif (in_array($valueType, $this->stdTypes)) { $row[$key] = (string) $record[$key]; } elseif (array_key_exists($valueType, $this->struct)) { // Walk through the data type and parse children foreach ($this->struct[$valueType] as $attr => $attrType) { $childId = $type . "_" . $attrType . "_" . (!empty($row["id"]) ? $row["id"] : uniqid()); $row[$key] = $childId; $childPath = "{$key}/{$attr}"; $this->parse($record, $attrType, $childPath, $type, $childId); } } else { $row[$key] = null; } } // FIXME set this in the data before actually caling the fn if ($parentId) { $row["WSDL_parentId"] = $parentId; } $handle->writeRow($row); } }
/** * @todo Add a $file parameter to use instead of $type * to allow saving a single type to different files * * @param string $type * @return Table */ protected function createCsvFile($type, $parentId) { if (empty($this->headers[$type])) { $this->headers[$type] = $this->getHeader($type, $parentId); } $safeType = $this->createSafeName($type); if (empty($this->csvFiles[$safeType])) { $this->csvFiles[$safeType] = Table::create($safeType, $this->headers[$type], $this->getTemp()); $this->csvFiles[$safeType]->addAttributes(["fullDisplayName" => $type]); if (!empty($this->primaryKeys[$safeType])) { $this->csvFiles[$safeType]->setPrimaryKey($this->primaryKeys[$safeType]); } } return $this->csvFiles[$safeType]; }