Example #1
0
 public function testSameValueAs()
 {
     $array = \SplFixedArray::fromArray(array(new StringLiteral('one'), new StringLiteral('two'), new Integer(3)));
     $collection2 = new Collection($array);
     $array = \SplFixedArray::fromArray(array('one', 'two', array(1, 2)));
     $collection3 = Collection::fromNative($array);
     $this->assertTrue($this->collection->sameValueAs($collection2));
     $this->assertTrue($collection2->sameValueAs($this->collection));
     $this->assertFalse($this->collection->sameValueAs($collection3));
     $mock = $this->getMock('ValueObjects\\ValueObjectInterface');
     $this->assertFalse($this->collection->sameValueAs($mock));
 }
Example #2
0
 /**
  * Returns a new Dictionary object
  *
  * @param  array $array
  * @return self
  */
 public static function fromNative()
 {
     $array = \func_get_arg(0);
     $keyValuePairs = array();
     foreach ($array as $arrayKey => $arrayValue) {
         $key = new StringLiteral(\strval($arrayKey));
         if ($arrayValue instanceof \Traversable || \is_array($arrayValue)) {
             $value = Collection::fromNative($arrayValue);
         } else {
             $value = new StringLiteral(\strval($arrayValue));
         }
         $keyValuePairs[] = new KeyValuePair($key, $value);
     }
     $fixedArray = \SplFixedArray::fromArray($keyValuePairs);
     return new self($fixedArray);
 }