public function testGetResource() { $resources = new \Bonder\Collections\Map(); $resources->set("1", "one"); $resources->set("2", "two"); $context = new \Bonder\Contexts\MapContext($resources); $this->assertEquals("one", $context->get("1")); $this->assertEquals("two", $context->get("2")); $this->assertEquals("one", $context->get("1")); }
/** * Returns a new Map, built with the data given in the array. * * @param array $array the array. * @return \Bonder\Collections\Map the map. */ public static function fromArray(array $array) { $map = new \Bonder\Collections\Map(); foreach ($array as $k => $v) { $map->set($k, $v); } return $map; }
/** * (non-PHPdoc) * @see Bonder\Util.Matcher::getMatchVariables() */ public function getMatchVariables($expression, $literal) { $variables = array(); $result = @preg_match_all("#^{$expression}/?\$#Ui", $literal, $variables); if ($result === false) { throw new \Bonder\Exceptions\Exception("Unmatched regex {$expression} : {$literal}"); } $map = new \Bonder\Collections\Map(); foreach ($variables as $k => $v) { if (count($v) != 1) { throw new \Bonder\Exceptions\Exception("Unexpected array size in preg matching array"); } $map->set($k, reset($v)); } return $map; }
public function testContains() { $map = new \Bonder\Collections\Map(); $map->set("mykey", 79); $map->set("mykey2", 80); $otherMap = new \Bonder\Collections\Map(); $this->assertTrue($map->contains($otherMap)); $otherMap->set("mykey", 79); $this->assertTrue($map->contains($otherMap)); $otherMap->set("mykey3", 81); $this->assertFalse($map->contains($otherMap)); $this->assertFalse($otherMap->contains($map)); $map->remove("mykey2"); $this->assertTrue($otherMap->contains($map)); $map->set("mykey", "old_79"); $this->assertFalse($otherMap->contains($map)); }