/** * setValue() をテストします. 以下を確認します. * * - 引数に指定した値で MapEntry の値が更新されること * - 元の ArrayMap の該当するマッピングが上書きされること * * @covers Peach\Util\ArrayMapEntry::setValue */ public function testSetValue() { $this->entryList[0]->setValue("hoge"); $this->assertSame("hoge", $this->entryList[0]->getValue()); $expected = array("key1" => "hoge", "key2" => "bar", "key3" => "baz"); $this->assertSame($expected, $this->map->asArray()); }
public function __call($method, $arguments) { // 自動的に引数位置を変更するメソッド if (!$this->arg_push && in_array($method, self::$auto_push_method)) { $this->p(); } // 値が空の場合 if (empty($this->value)) { return $this; } // 値がスカラー値の場合でも動くように if (is_scalar($this->value)) { $arg = $arguments; if ($this->arg_push) { $arg[] = $this->value; } else { array_unshift($arg, $this->value); } $this->value = call_user_func_array($method, $arg); $this->arg_push = false; $this->is_call = false; return $this; } // 再帰を含めた要素処理 foreach ($this->value as $k => $v) { $arg = $arguments; if (is_array($v)) { $arr = new ArrayMap($v); if ($this->arg_push) { $arr->p(); } if ($this->is_call) { array_unshift($arg, $method); call_user_func_array(array($arr, 'call'), $arg); } else { call_user_func_array(array($arr, $method), $arguments); } $this->value[$k] = $arr->v(); continue; } if ($this->arg_push) { $arg[] = $v; } else { array_unshift($arg, $v); } $this->value[$k] = call_user_func_array($method, $arg); } $this->arg_push = false; $this->is_call = false; return $this; }
public function parseExecuteCode($json) { $decoded = json_decode($json, true); if ($this->isSuccess($decoded)) { $files = new ArrayMap(); if (isset($decoded['deployr']['response']['files'])) { foreach ($decoded['deployr']['response']['files'] as $name => $file) { $files->put($name, $file['value']); } } return new DeployRExecution($decoded['deployr']['response']['robjects'], $files); } else { throw new DeployRResponseException('session - execute code - success attribute is not true'); } }
/** * ArrayMap に登録されている各マッピングを取り出す Iterator を返すことを確認します. */ public function testGetIterator() { $i = $this->object->getIterator(); $this->assertInstanceOf("Traversable", $i); $result = array(); foreach ($i as $key => $value) { $result[$key] = $value; } $this->assertSame(array("key1" => "foo", "key2" => "bar", "key3" => "baz"), $result); }
/** * このエントリーの値を更新します. * @param mixed $value 新しくセットされる値 */ public function setValue($value) { $this->map->put($this->key, $value); $this->value = $value; }