Ejemplo n.º 1
0
 public function testBuildCommand()
 {
     $counter = new CounterUpdate();
     $builder = StoreMap::builder($this->location, [])->withLocation($this->location)->withContext('context-hash')->removeMap('map_key_remove')->removeSet('set_key_remove')->removeFlag('flag_key_remove')->removeCounter('map_counter_remove')->removeRegister('map_register_remove')->updateMap('map_key', MapUpdate::create())->updateSet('set_key', SetUpdate::create())->updateRegister('map_register', 'foo')->updateCounter('map_counter', 1)->updateFlag('flag_key', true)->withContext('context-hash')->withReturnBody(true)->withDw(1)->withPw(2)->withW(3);
     $counter->withDelta(1);
     $builder->updateCounter('other_counter', $counter);
     $this->assertInstanceOf('Riak\\Client\\Command\\DataType\\StoreMap', $builder->build());
 }
Ejemplo n.º 2
0
 /**
  * @param array $updates
  *
  * @return \Riak\Client\Command\DataType\SetUpdate
  */
 public static function createFromArray(array $updates)
 {
     $update = new MapUpdate();
     foreach ($updates as $key => $val) {
         if (is_bool($val)) {
             $update->updateFlag($key, new FlagOp($val));
             continue;
         }
         if (is_string($val)) {
             $update->updateRegister($key, new RegisterOp($val));
             continue;
         }
         if (is_int($val)) {
             $update->updateCounter($key, new CounterOp($val));
             continue;
         }
         if (is_array($val) && $val === array_values($val)) {
             $update->updateSet($key, new SetOp($val, []));
             continue;
         }
         if (is_array($val)) {
             $update->updateMap($key, self::createFromArray($val)->getOp());
             continue;
         }
         $message = 'Map element "%s" must be of the type (boolean, string, integer, or an array), "%s" given.';
         $type = is_object($val) ? get_class($val) : gettype($val);
         throw new InvalidArgumentException(sprintf($message, $key, $type));
     }
     return $update;
 }
Ejemplo n.º 3
0
 /**
  * Update the map in Riak by adding/updating the flag mapped to the provided key.
  *
  * @param string  $key
  * @param boolean $value
  *
  * @return \Riak\Client\Command\DataType\StoreMap
  */
 public function updateFlag($key, $value)
 {
     $this->update->updateFlag($key, new FlagOp($value));
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * @expectedException InvalidArgumentException
  * @expectedExceptionMessage Map element "invalid_key" must be of the type (boolean, string, integer, or an array), "stdClass" given.
  */
 public function testCreateWithInvalidArgumentException()
 {
     MapUpdate::createFromArray(['invalid_key' => new \stdClass()]);
 }