Example #1
0
 /**
  * @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;
 }
Example #2
0
 /**
  * @expectedException \Keboola\Juicer\Exception\UserException
  * @expectedExceptionMessage Missing mapping for 'first' in config.
  */
 public function testNoMapping()
 {
     $config = new Config('ex', 'test', []);
     $config->setJobs([JobConfig::create(['endpoint' => '1st', 'dataType' => 'first'])]);
     $config->setAttributes(['mappings' => ['notfirst' => ['id' => ['type' => 'column']]]]);
     $parser = JsonMap::create($config);
 }