Exemplo n.º 1
0
 public function testfindOrCreateComponentWithExistingComponent()
 {
     $resolve = new ResolveComponentModelIdentifier('user', 1);
     $resolvedComponentData = new ResolvedComponentData('user', 1);
     $this->and($this->mockGenerator->orphanize('__construct'))->and($this->mockGenerator->shuntParentClassCalls())->and($entityRepository = new \mock\Doctrine\ORM\EntityRepository())->and($objectManager = new \mock\Doctrine\Common\Persistence\ObjectManager())->and($resultBuilder = new \mock\Spy\Timeline\ResultBuilder\ResultBuilderInterface())->and($componentDataResolver = new \mock\Spy\Timeline\ResolveComponent\ComponentDataResolverInterface())->and($queryBuilder = new \mock\Doctrine\Orm\QueryBuilder())->and($this->mockGenerator->orphanize('__construct'))->and($this->mockGenerator->shuntParentClassCalls())->and($query = new \mock\Doctrine\ORM\AbstractQuery())->and($component = new \mock\Spy\Timeline\Model\Component())->and($this->calling($componentDataResolver)->resolveComponentData = function () use($resolvedComponentData) {
         return $resolvedComponentData;
     })->and($this->calling($objectManager)->getRepository = function () use($entityRepository) {
         return $entityRepository;
     })->and($this->calling($entityRepository)->createQueryBuilder = function () use($queryBuilder) {
         return $queryBuilder;
     })->and($this->calling($query)->getOneOrNullResult = function () use($component) {
         return $component;
     })->and($this->calling($queryBuilder)->where = function () use($queryBuilder) {
         return $queryBuilder;
     })->and($this->calling($queryBuilder)->andWhere = function () use($queryBuilder) {
         return $queryBuilder;
     })->and($this->calling($queryBuilder)->setParameter = function () use($queryBuilder) {
         return $queryBuilder;
     })->and($this->calling($queryBuilder)->getQuery = function () use($query) {
         return $query;
     })->and($actionClass = 'Spy\\Timeline\\Model\\Action')->and($componentClass = 'Spy\\Timeline\\Model\\Component')->and($actionComponentClass = 'Spy\\Timeline\\Model\\ActionComponent')->and($actionManager = new TestedModel($objectManager, $resultBuilder, $actionClass, $componentClass, $actionComponentClass))->and($actionManager->setComponentDataResolver($componentDataResolver))->and($this->calling($componentDataResolver)->resolveComponentData = function () {
         return new ResolvedComponentData('user', '1');
     })->when($result = $actionManager->findOrCreateComponent('user', 1))->mock($componentDataResolver)->call('resolveComponentData')->withArguments($resolve)->exactly(1)->mock($queryBuilder)->call('where')->withArguments('c.model = :model')->exactly(1)->mock($queryBuilder)->call('andWhere')->withArguments('c.identifier = :identifier')->exactly(1)->mock($queryBuilder)->call('setParameter')->withArguments('model', $resolvedComponentData->getModel())->exactly(1)->mock($queryBuilder)->call('setParameter')->withArguments('identifier', serialize($resolvedComponentData->getIdentifier()))->exactly(1)->object($result)->isEqualTo($component);
 }
 /**
  * Creates a new component object from the resolved data.
  *
  * @param ResolvedComponentData $resolved The resolved component data
  *
  * @return ComponentInterface The newly created and populated component
  */
 protected function getComponentFromResolvedComponentData(ResolvedComponentData $resolved)
 {
     /** @var $component ComponentInterface */
     $component = new $this->componentClass();
     $component->setModel($resolved->getModel());
     $component->setData($resolved->getData());
     $component->setIdentifier($resolved->getIdentifier());
     return $component;
 }
 public function testIdentifierCanBeZero()
 {
     $this->if($action = new TestedModel('user', '0'))->string($action->getIdentifier())->isEqualTo('0');
 }