public function check($templateFile, nbConfiguration $configuration) { if (!file_exists($templateFile)) { throw new Exception(sprintf('Template %s does not exist', $templateFile)); } $template = new nbConfiguration(); $template->add(sfYaml::load($templateFile), ''); // $config = new nbConfiguration(); // $config->add($values, '', true); $this->errors = array(); $this->doCheck('', $configuration->getAll(), $template->getAll()); if ($this->hasErrors()) { $message = "Configuration has errors: \n"; foreach ($this->errors as $key => $error) { $message .= sprintf("%s: %s\n", $key, $error); } throw new Exception($message); } return true; }
$configuration->add($key2); $t->is($configuration->getAll(), array('foo' => 'fooValue', 'bar' => 'barVal', 'bar2' => 'barValue2'), '$configuration->add() old and new values'); $key1 = array('foo' => 'fooVal', 'foo2' => 'fooValue2'); $configuration->add($key1); $t->is($configuration->getAll(), array('foo' => 'fooVal', 'foo2' => 'fooValue2', 'bar' => 'barVal', 'bar2' => 'barValue2'), '$configuration->add() old and new values'); $key2 = array('foo2' => 'fooVal2', 'bar' => 'barVal', 'bar2' => 'barValue2'); $configuration->add($key2); $t->is($configuration->getAll(), array('foo' => 'fooVal', 'foo2' => 'fooVal2', 'bar' => 'barVal', 'bar2' => 'barValue2'), '$configuration->add() old and new values'); $t->comment('nbConfigTest - Test add with prefix'); $configuration = new nbConfiguration(); $key1 = array('foo' => 'fooValue'); $key2 = array('bar' => 'barValue'); $result = array('myprefix' => array('foo' => 'fooValue', 'bar' => 'barValue')); $configuration->add($key1, 'myprefix'); $configuration->add($key2, 'myprefix'); $t->is($configuration->get('myprefix_foo'), 'fooValue', '$configuration->add() can set a prefix for 1st level keys'); $t->is($configuration->getAll(), $result, '$configuration->add() can set a prefix for 1st level keys'); $t->comment('nbConfigTest - Test add with replace tokens'); $configuration = new nbConfiguration(); $key1 = array('foo' => 'bar'); $key2 = array('baz' => '%foo%'); $key3 = array('blu' => array('%foo%', '%baz%')); $key4 = array('bup' => '%flo%'); $configuration->add($key1, ''); $configuration->add($key2, '', true); $configuration->add($key3, '', true); $configuration->add($key4, '', true); $t->is($configuration->get('baz'), $configuration->get('foo'), '->add() can replace tokens'); $t->is($configuration->get('baz'), 'bar', '->add() can replace child tokens'); $t->is($configuration->get('blu'), array('bar', 'bar'), '->add() can replace array tokens'); $t->is($configuration->get('bup'), '%flo%', '->add() will not replace a value if not set');