mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-29 00:34:03 +02:00
Fix that current(), key(), etc does not work with Config objects
This commit is contained in:
parent
83f386f92a
commit
4537b2932e
@ -4,10 +4,9 @@
|
|||||||
|
|
||||||
namespace Icinga\Application;
|
namespace Icinga\Application;
|
||||||
|
|
||||||
|
use Iterator;
|
||||||
use Countable;
|
use Countable;
|
||||||
use ArrayAccess;
|
use ArrayAccess;
|
||||||
use ArrayIterator;
|
|
||||||
use IteratorAggregate;
|
|
||||||
use LogicException;
|
use LogicException;
|
||||||
use UnexpectedValueException;
|
use UnexpectedValueException;
|
||||||
use Icinga\Exception\NotReadableError;
|
use Icinga\Exception\NotReadableError;
|
||||||
@ -15,7 +14,7 @@ use Icinga\Exception\NotReadableError;
|
|||||||
/**
|
/**
|
||||||
* Container for configuration values and global registry of application and module related configuration.
|
* Container for configuration values and global registry of application and module related configuration.
|
||||||
*/
|
*/
|
||||||
class Config implements Countable, ArrayAccess, IteratorAggregate
|
class Config implements Countable, Iterator, ArrayAccess
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Configuration directory where ALL (application and module) configuration is located
|
* Configuration directory where ALL (application and module) configuration is located
|
||||||
@ -121,13 +120,53 @@ class Config implements Countable, ArrayAccess, IteratorAggregate
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a iterator for this config's data
|
* Reset the current position of $this->data
|
||||||
*
|
*
|
||||||
* @return ArrayIterator
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function getIterator()
|
public function rewind()
|
||||||
{
|
{
|
||||||
return new ArrayIterator($this->data);
|
return reset($this->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the section's or property's value of the current iteration
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function current()
|
||||||
|
{
|
||||||
|
return current($this->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return whether the position of the current iteration is valid
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function valid()
|
||||||
|
{
|
||||||
|
return key($this->data) !== null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the section's or property's name of the current iteration
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function key()
|
||||||
|
{
|
||||||
|
return key($this->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Advance the position of the current iteration and return the new section's or property's value
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function next()
|
||||||
|
{
|
||||||
|
return next($this->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,7 +85,26 @@ class ConfigTest extends BaseTestCase
|
|||||||
$config = new Config(array('a' => 'b', 'c' => array('d' => 'e')));
|
$config = new Config(array('a' => 'b', 'c' => array('d' => 'e')));
|
||||||
|
|
||||||
$this->assertInstanceOf('Countable', $config, 'Config objects do not implement interface `Countable\'');
|
$this->assertInstanceOf('Countable', $config, 'Config objects do not implement interface `Countable\'');
|
||||||
$this->assertEquals(2, $config->count(), 'Config objects do not count properties and sections correctly');
|
$this->assertEquals(2, count($config), 'Config objects do not count properties and sections correctly');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testWhetherConfigObjectsAreTraversable()
|
||||||
|
{
|
||||||
|
$config = new Config(array('a' => 'b', 'c' => 'd'));
|
||||||
|
$config->e = 'f';
|
||||||
|
|
||||||
|
$this->assertInstanceOf('Iterator', $config, 'Config objects do not implement interface `Iterator\'');
|
||||||
|
|
||||||
|
$actual = array();
|
||||||
|
foreach ($config as $key => $value) {
|
||||||
|
$actual[$key] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
array('a' => 'b', 'c' => 'd', 'e' => 'f'),
|
||||||
|
$actual,
|
||||||
|
'Config objects do not iterate properly in the order their values were inserted'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWhetherOneCanCheckWhetherConfigObjectsHaveACertainPropertyOrSection()
|
public function testWhetherOneCanCheckWhetherConfigObjectsHaveACertainPropertyOrSection()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user