public function testExtract()
 {
     $abstractObject = $this->getMockForAbstractClass('\\Matryoshka\\Model\\Object\\AbstractObject');
     $strategy = new HasOneStrategy($abstractObject);
     $strategy->setNullable(false);
     $this->assertInternalType('array', $strategy->extract($abstractObject));
     $this->assertInternalType('array', $strategy->extract([]));
     $this->assertInternalType('array', $strategy->extract(null));
     $strategy->setNullable(true);
     $this->assertNull($strategy->extract(null));
     $this->setExpectedException('\\Matryoshka\\Model\\Exception\\InvalidArgumentException');
     $strategy->extract('wrong value');
 }
 /**
  * Converts the given value so that it can be extracted by the hydrator.
  *
  * @param array|\Traversable|null $value The original value.
  * @return array|null Returns the value that should be extracted.
  */
 public function extract($value)
 {
     if ($this->nullable && $value === null) {
         return null;
     }
     $return = [];
     if (is_array($value) || $value instanceof \Traversable) {
         foreach ($value as $key => $object) {
             $return[$key] = $this->hasOneStrategy->extract($object);
         }
     } else {
         throw new Exception\InvalidArgumentException(sprintf('Value must be null (only if nullable option is enabled), or an array, or a Traversable: "%s" given', is_object($value) ? get_class($value) : gettype($value)));
     }
     return $return;
 }