/**
  * @param AggregateRoot $aggregateRoot
  */
 private function ensureAggregateRootIsSupported(AggregateRoot $aggregateRoot)
 {
     $supportedClassName = $this->aggregateRootType->className();
     if (!$aggregateRoot instanceof $supportedClassName) {
         throw new \InvalidArgumentException('Unsupported aggregate type.');
     }
 }
 /**
  * @param          $object
  * @param Contract $type
  *
  * @return Serializable
  */
 public function deserialize($object, Contract $type)
 {
     $reflectionClass = new \ReflectionClass($type->className());
     $data = json_decode($object, true);
     $instance = $reflectionClass->newInstanceWithoutConstructor();
     foreach ($data as $propertyName => $propertyValue) {
         if (!$reflectionClass->hasProperty($propertyName)) {
             continue;
         }
         $reflectionProperty = $reflectionClass->getProperty($propertyName);
         if (!$reflectionProperty->isPublic()) {
             $reflectionProperty->setAccessible(true);
         }
         $reflectionProperty->setValue($instance, $propertyValue);
     }
     return $instance;
 }
 /**
  * @param Contract    $aggregateRootType
  * @param EventStream $eventStream
  *
  * @return AggregateRoot
  */
 public function loadFromHistory(Contract $aggregateRootType, EventStream $eventStream)
 {
     $className = $aggregateRootType->className();
     return $className::loadFromHistory($eventStream);
 }
 public function it_can_load_an_aggregate_root_from_its_history(Contract $contract, EventStream $eventStream)
 {
     $contract->className()->willReturn('\\RayRutjes\\DomainFoundation\\Stub\\Domain\\AggregateRoot\\EventSourcedAggregateRootStub');
     $this->loadFromHistory($contract, $eventStream)->shouldHaveType('RayRutjes\\DomainFoundation\\Stub\\Domain\\AggregateRoot\\EventSourcedAggregateRootStub');
 }
 public function it_should_ignore_non_existent_parameter(Contract $contract)
 {
     $contract->className()->shouldBeCalledTimes(1)->willReturn('RayRutjes\\DomainFoundation\\Stub\\Serializer\\SerializableStub');
     $object = $this->deserialize('{"name":"test","surname":"test","firstname":"test"}', $contract);
     $this->serialize($object)->shouldEqual('{"name":"test","surname":"test"}');
 }