예제 #1
0
 /**
  * @test
  */
 public function is_should_concatenate_maps()
 {
     $coll3 = new Map(['key1' => 'value1', 'key2' => 'wrongValue', 'key3' => ['key31' => 'value31']]);
     $coll4 = new Map(['key2' => 'value2', 'key3' => ['key32' => 'value32']]);
     $concatenated = $coll3->concat($coll4);
     $this->assertEquals(['key1' => 'value1', 'key2' => ['wrongValue', 'value2'], 'key3' => ['key31' => 'value31', 'key32' => 'value32']], $concatenated->toArray());
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function load($path, array $arguments = [])
 {
     if ($this->caches->containsKey($path) === false) {
         $content = $this->loader->load($path, $arguments);
         $value = new Pair($path, $content);
         $this->caches->add($value);
     }
     return $this->caches->get($path);
 }
예제 #3
0
 public function save(StreamName $streamName, DomainMessage $event)
 {
     $id = (string) $event->getId();
     $name = (string) $streamName;
     $events = $this->events->get($name);
     if (null === $events) {
         $events = new Map();
         $this->events->add(new Pair($name, $events));
     }
     if (!$events->containsKey($id)) {
         $events->add(new Pair($id, new Vector()));
     }
     $events->get($id)->add($event);
 }
예제 #4
0
 /**
  * @see http://php.net/manual/fr/class.arrayaccess.php
  */
 public function offsetSet($offset, $value)
 {
     if (!isset($this->flip[$offset])) {
         throw new RuntimeException("Can not modify the value corresponding to this key, as it is not defined in structure");
     }
     return parent::offsetSet($offset, $value);
 }
예제 #5
0
 /**
  * {@inheritDoc}
  * @return $this
  */
 public function indexBy($callback)
 {
     $group = new Map();
     foreach ($this as $value) {
         $key = $callback($value);
         $group->set($key, $value);
     }
     return $group;
 }
예제 #6
0
 /**
  * @expectedException RuntimeException
  */
 public function testMergeFail()
 {
     $map1 = new Map(["a" => 1, "b" => 2]);
     $seq = new Sequence(["c" => 3, "d" => 3]);
     $map1->merge($seq);
 }
예제 #7
0
 /**
  * @test
  */
 public function it_should_index_deep()
 {
     $items = [['id' => 1, 'name' => 'foo', 'thing' => ['parent_id' => 10]], ['id' => 2, 'name' => 'bar', 'thing' => ['parent_id' => 11]], ['id' => 3, 'name' => 'baz', 'thing' => ['parent_id' => 10]]];
     $collection = new Map($items);
     $grouped = $collection->indexBy(function ($element) {
         return $element['thing']['parent_id'];
     });
     $expected = [10 => ['id' => 3, 'name' => 'baz', 'thing' => ['parent_id' => 10]], 11 => ['id' => 2, 'name' => 'bar', 'thing' => ['parent_id' => 11]]];
     $this->assertEquals($expected, $grouped->toArray());
 }
예제 #8
0
 public function testToValuesArray()
 {
     $dictionary = new Map();
     $dictionary->set('key1', 'value1')->set('key2', 'value2');
     $expected = ['value1', 'value2'];
     $this->assertEquals($expected, $dictionary->toValuesArray());
 }
예제 #9
0
 /**
  * Register the loader of fixture
  *
  * @param \holyshared\fixture\FixtureLoader $loader
  * @return holyshared\fixture\container\LoaderContainer
  */
 public function register(FixtureLoader $loader)
 {
     $value = new Pair($loader->getName(), $loader);
     $this->loaders->add($value);
     return $this;
 }
예제 #10
0
 /**
  * @param string $name
  * @return bool
  */
 public function has($name)
 {
     return $this->fixtures->containsKey($name);
 }