public function testConfigWithoutSection() { $config = new IniFileConfig(dirname(__FILE__) . '/real.conf', dirname(__FILE__) . '/default.conf', $useSections = false); self::assertEquals(array('a1' => '1', 'a2' => 'overwritten', 'b1' => '3', 'b2' => 'also overwritten'), $config->getArray()); self::assertEquals('overwritten', $config->get('a2')); self::assertEquals('also overwritten', $config->get('b2', 'section_b')); try { $config->setDefaultSection('section_b'); self::fail('Setting a default section when not using sections should throw exception.'); } catch (ConfigException $e) { } try { $config->get('wrong_variable'); self::fail('Should have thrown an exception.'); } catch (ConfigException $e) { } }
/** * Work through all Set commands. * * @return void */ public function enumerateSets() { foreach ($this->sets as $set) { $value = $set->getValue(); $key = $set->getProperty(); $section = $set->getSection(); $operation = $set->getOperation(); if ($value !== null) { try { $this->ini->set($section, $key, $value); $this->log("[{$section}] {$key} set to {$value}", Project::MSG_DEBUG); } catch (Exception $ex) { $this->log("Error setting value for section '" . $section . "', key '" . $key . "'"); $this->log($ex->getMessage(), Project::MSG_DEBUG); } } elseif ($operation !== null) { $v = $this->ini->get($section, $key); // value might be wrapped in quotes with a semicolon at the end if (!is_numeric($v)) { if (preg_match('/^"(\\d*)";?$/', $v, $match)) { $v = $match[1]; } elseif (preg_match("/^'(\\d*)';?\$/", $v, $match)) { $v = $match[1]; } else { $this->log("Value {$v} is not numeric. Skipping {$operation} operation."); continue; } } if ($operation == '+') { ++$v; } elseif ($operation == '-') { --$v; } else { if ($operation != '-' && $operation != '+') { $msg = "Unrecognised operation {$operation}"; if ($this->haltonerror) { throw new BuildException($msg); } $this->log($msg, Project::MSG_ERR); } } try { $this->ini->set($section, $key, $v); $this->log("[{$section}] {$key} set to {$v}", Project::MSG_DEBUG); } catch (Exception $ex) { $this->log("Error setting value for section '" . $section . "', key '" . $key . "'"); $this->log($ex->getMessage(), Project::MSG_DEBUG); } } else { $this->log("Set: value and operation are both not set", Project::MSG_ERR); } } }