public function testFilteredValue() { $map = new Map(); $map->add(Path::factory('/test/description', 'desc')->setDefault('value')->filter(function ($val) { return strrev($val); })); $result = $map->execute($this->object); $this->assertTrue(is_array($result)); $this->assertArrayHasKey('desc', $result); $this->assertEquals(strrev("test description"), $result['desc']); }
/** * Checks if all array values match given arguments * @return boolean */ public function execute() { $arr = parent::execute(); $args = $this->getArguments(); foreach ($args as $arg) { if (!in_array($arg, $arr)) { return false; } } return true; }
public function testWrongPath() { $map = new Map(); $map->add(Path::factory('/test', 'test')->addChildren(Path::factory('wrong>path', 'wrong', 'defaultFalse'))); $result = $map->execute(new XmlFile(__DIR__ . '/test.xml')); $this->assertTrue(is_array($result)); $this->assertArrayHasKey('test', $result); $this->assertTrue(is_array($result['test'])); $this->assertArrayHasKey('wrong', $result['test']); $this->assertEquals('defaultFalse', $result['test']['wrong']); }
/** * Checks if any array value matches given arguments * @return boolean */ public function execute() { $arr = parent::execute(); $args = $this->getArguments(); foreach ($args as $arg) { foreach ($arr as $value) { if ($value == $arg) { return true; } } } return false; }
/** * Adds all array values together * @return integer */ public function execute() { return array_sum(parent::execute()); }
/** * Retrieves item of largest value * @return integer */ public function execute() { return max(parent::execute()); }
/** * Retrieves the sum value of all array values * @return integer */ public function execute() { $arr = parent::execute(); return array_sum($arr) / count($arr); }