Beispiel #1
0
 public function it_gets_origin($manager, RepositoryInterface $repository, OriginAwareInterface $originAware, FakeEntity $entity)
 {
     $originAware->getOriginId()->willReturn(5);
     $originAware->getOriginType()->willReturn('Sylius\\Component\\Originator\\Model\\FakeEntity');
     $manager->getRepository('Sylius\\Component\\Originator\\Model\\FakeEntity')->willReturn($repository);
     $repository->findOneBy(array('id' => 5))->willReturn($entity);
     $this->getOrigin($originAware)->shouldReturn($entity);
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function setOrigin(OriginAwareInterface $originAware, $origin)
 {
     if (!is_object($origin)) {
         throw new UnexpectedTypeException($origin, 'object');
     }
     if (null === ($id = $this->accessor->getValue($origin, $this->identifier))) {
         throw new \InvalidArgumentException(sprintf('Origin %s is not set.', $this->identifier));
     }
     $originAware->setOriginId($id)->setOriginType(get_class($origin));
 }
 /**
  * {@inheritdoc}
  */
 public function setOrigin(OriginAwareInterface $originAware, $origin)
 {
     if (!is_object($origin)) {
         throw new UnexpectedTypeException($origin, 'object');
     }
     /** @var \DoS\ResourceBundle\Model\OriginAwareInterface $originAware */
     if ($origin instanceof OriginContextInterface) {
         $originAware->setOriginAlias($origin->getOriginalAlias());
         $originAware->setOriginType($origin->getOriginalType());
         $originAware->setOriginId($origin->getId());
         return;
     }
     if (null === ($id = $this->accessor->getValue($origin, $this->identifier))) {
         throw new \InvalidArgumentException(sprintf('Origin %s is not set.', $this->identifier));
     }
     $originAware->setOriginId($id);
     $originAware->setOriginType(get_class($origin));
 }