public function testNoMappingFallback() { $config = new Config('ex', 'test', []); $config->setAttributes(['mappings' => ['notfirst' => ['id' => ['mapping' => ['destination' => 'id']]]]]); $fallback = Json::create($config, $this->getLogger('test', true), new Temp()); $parser = JsonMap::create($config, $fallback); $data = json_decode('[ { "id": 1, "arr": [1,2,3] }, { "id": 2, "arr": ["a","b","c"], "tags": [ { "user": "******", "tag": "tag1" }, { "user": "******", "tag": "tag2" } ] } ]'); $parser->process($data, 'first'); $parser->process($data, 'notfirst'); $this->assertContainsOnlyInstancesOf('Keboola\\CsvTable\\Table', $parser->getResults()); $this->assertEquals(['notfirst', 'first', 'first_arr', 'first_tags'], array_keys($parser->getResults())); }
public function testGetParser() { $temp = new Temp(); $parser = Json::create(new Config('testApp', 'testCfg', []), $this->getLogger(), $temp); $extractor = new GenericExtractor($temp); $extractor->setParser($parser); self::assertEquals($parser, $extractor->getParser()); }
/** * @param Config $config * @return ParserInterface */ protected function initParser(Config $config) { if (!empty($this->parser) && $this->parser instanceof ParserInterface) { return $this->parser; } $parser = Json::create($config, $this->getLogger(), $this->getTemp(), $this->metadata); $parser->getParser()->getStruct()->setAutoUpgradeToArray(true); $parser->getParser()->setCacheMemoryLimit('2M'); $parser->getParser()->getAnalyzer()->setNestedArrayAsJson(true); if (empty($config->getAttribute('mappings'))) { $this->parser = $parser; } else { $this->parser = JsonMap::create($config, $parser); } return $this->parser; }
/** * I'm not too sure this is optimal! * If it looks stupid, but works, it ain't stupid! */ public function getJob($dir = 'recursive') { $temp = new Temp('recursion'); $configuration = new Configuration(__DIR__ . '/../data/' . $dir, 'test', $temp); $jobConfig = array_values($configuration->getConfig()->getJobs())[0]; $parser = Json::create($configuration->getConfig(), $this->getLogger('test', true), $temp); $client = RestClient::create(); $history = new History(); $client->getClient()->getEmitter()->attach($history); $job = $this->getMockForAbstractClass('Keboola\\Juicer\\Extractor\\RecursiveJob', [$jobConfig, $client, $parser]); return [$job, $client, $parser, $history, $jobConfig]; }
/** * @param JobConfig $config * @return GenericExtractorJob */ protected function getJob(JobConfig $config) { return new GenericExtractorJob($config, RestClient::create(['base_url' => 'http://example.com/api/']), Json::create(new Config('ex-generic-test', 'test', []), $this->getLogger(), new Temp())); }