public function testCreateAuthQuery() { $config = new Config('testApp', 'testCfg', []); $config->setAttributes(['key' => 'val']); $api = ['authentication' => ['type' => 'query', 'query' => ['param' => ['attr' => 'key']]]]; $queryAuth = Api::createAuth($api, $config, []); self::assertEquals($api['authentication']['query'], self::getProperty($queryAuth, 'query')); self::assertEquals($config->getAttributes(), self::getProperty($queryAuth, 'attrs')); self::assertInstanceOf('\\Keboola\\GenericExtractor\\Authentication\\Query', $queryAuth); }
/** * @param array $params Values to override in the config * @return Config * @todo separate the loading of YML and pass it as an argument */ public function getConfig(array $params = null) { try { $configYml = $this->getYaml('/config.yml', 'parameters', 'config'); } catch (NoDataException $e) { throw new UserException($e->getMessage(), 0, $e); } if (!is_null($params)) { $configYml = array_replace($configYml, $params); } $configName = empty($configYml['id']) ? '' : $configYml['id']; $runtimeParams = []; // TODO get runtime params from console if (empty($configYml['jobs'])) { throw new UserException("No 'jobs' specified in the config!"); } $jobs = $configYml['jobs']; $jobConfigs = []; foreach ($jobs as $job) { $jobConfig = $this->createJob($job); $jobConfigs[$jobConfig->getJobId()] = $jobConfig; } unset($configYml['jobs']); // weird $config = new Config($this->appName, $configName, $runtimeParams); $config->setJobs($jobConfigs); $config->setAttributes($configYml); return $config; }
public function testMergeResults() { Logger::setLogger($this->getLogger('testMergeResults', true)); $configFirst = JobConfig::create(['endpoint' => '1st', 'dataType' => 'first']); $configTags = JobConfig::create(['endpoint' => '2nd', 'dataType' => 'tags']); $config = new Config('ex', 'test', []); $config->setAttributes(['mappings' => ['first' => ['id' => ['type' => 'column', 'mapping' => ['destination' => 'item_id']], 'tags' => ['type' => 'table', 'destination' => 'tags', 'tableMapping' => ['user' => ['mapping' => ['destination' => 'user', 'primaryKey' => true]], 'tag' => ['mapping' => ['destination' => 'tag', 'primaryKey' => true]]], 'parentKey' => ['disable' => true]]], 'tags' => ['user' => ['mapping' => ['destination' => 'user', 'primaryKey' => true]], 'tag' => ['mapping' => ['destination' => 'tag', 'primaryKey' => true]]]]]); $firstData = json_decode('[ { "id": 1, "arr": [1,2,3] }, { "id": 2, "arr": ["a","b","c"], "tags": [ { "user": "******", "tag": "tag1" }, { "user": "******", "tag": "tag2" } ] } ]'); $secondData = json_decode('[ { "user": "******", "tag": "tag3" }, { "user": "******", "tag": "tag4" } ]'); $parser = JsonMap::create($config); $parser->process($firstData, $configFirst->getDataType()); $parser->process($secondData, $configTags->getDataType()); self::assertEquals(['"user","tag"' . PHP_EOL, '"asd","tag1"' . PHP_EOL, '"asd","tag2"' . PHP_EOL, '"asd","tag3"' . PHP_EOL, '"asd","tag4"' . PHP_EOL], file($parser->getResults()['tags'])); }