/** * Unserializes a snippet of configuration that was saved at the time this step * was created at {@link Pipeline::start()} so that this step can use that configuration * to determine what it needs to do. e.g for SmokeTestPipelineStep this might contain * a list of URLs that need to be checked and which status codes to check for. * * @return array */ public function getConfigData() { if (!$this->Config) { return array(); } // Merge with defaults if (!$this->mergedConfig) { $this->mergedConfig = unserialize($this->Config); if ($default = self::config()->default_config) { Config::merge_array_low_into_high($this->mergedConfig, $default); } } return $this->mergedConfig; }
/** * Get all tests to be run by this smoketest * * @return array List of tests */ protected function getTests() { // Get core tests $tests = $this->getConfigSetting('Tests'); // Merge with default tests $defaultTests = $this->Pipeline()->getConfigSetting('PipelineConfig', 'Tests'); if ($tests && $defaultTests) { Config::merge_array_low_into_high($tests, $defaultTests); } elseif (!$tests && $defaultTests) { $tests = $defaultTests; } if ($tests) { return $tests; } // if there's no tests to check for, fallback to trying to find the // site's homepage by looking at the DNEnvironment fields. $environment = $this->getDependentEnvironment(); $url = $environment->URL; if ($url) { return array('default' => array('URL' => $url, 'ExpectStatus' => 200)); } }
public function testMerges() { $result = array('A' => 1, 'B' => 2, 'C' => 3); Config::merge_array_low_into_high($result, array('C' => 4, 'D' => 5)); $this->assertEquals($result, array('A' => 1, 'B' => 2, 'C' => 3, 'D' => 5)); $result = array('A' => 1, 'B' => 2, 'C' => 3); Config::merge_array_high_into_low($result, array('C' => 4, 'D' => 5)); $this->assertEquals($result, array('A' => 1, 'B' => 2, 'C' => 4, 'D' => 5)); $result = array('A' => 1, 'B' => 2, 'C' => array(1, 2, 3)); Config::merge_array_low_into_high($result, array('C' => array(4, 5, 6), 'D' => 5)); $this->assertEquals($result, array('A' => 1, 'B' => 2, 'C' => array(1, 2, 3, 4, 5, 6), 'D' => 5)); $result = array('A' => 1, 'B' => 2, 'C' => array(1, 2, 3)); Config::merge_array_high_into_low($result, array('C' => array(4, 5, 6), 'D' => 5)); $this->assertEquals($result, array('A' => 1, 'B' => 2, 'C' => array(4, 5, 6, 1, 2, 3), 'D' => 5)); $result = array('A' => 1, 'B' => 2, 'C' => array('Foo' => 1, 'Bar' => 2), 'D' => 3); Config::merge_array_low_into_high($result, array('C' => array('Bar' => 3, 'Baz' => 4))); $this->assertEquals($result, array('A' => 1, 'B' => 2, 'C' => array('Foo' => 1, 'Bar' => 2, 'Baz' => 4), 'D' => 3)); $result = array('A' => 1, 'B' => 2, 'C' => array('Foo' => 1, 'Bar' => 2), 'D' => 3); Config::merge_array_high_into_low($result, array('C' => array('Bar' => 3, 'Baz' => 4))); $this->assertEquals($result, array('A' => 1, 'B' => 2, 'C' => array('Foo' => 1, 'Bar' => 3, 'Baz' => 4), 'D' => 3)); }
/** * Get this pipeline configuration. If the configuration has been serialized * and saved into the Config field, it'll use that. If that field is empty, * it'll read the YAML file directly and return that instead. * * @return array */ public function getConfigData() { // Lazy load if necessary $data = null; if (!$this->Config && ($data = $this->Environment()->loadPipelineConfig())) { $this->Config = serialize($data); } // Merge with defaults if ($this->Config) { if (!$this->mergedConfig) { $this->mergedConfig = $data ?: unserialize($this->Config); if ($default = self::config()->default_config) { Config::merge_array_low_into_high($this->mergedConfig, $default); } } return $this->mergedConfig; } // Fail if no data available $path = $this->Environment()->getPipelineFilename(); throw new Exception(sprintf('YAML configuration for pipeline not found at path "%s"', $path)); }