/**
  * {inheritdoc}
  */
 public function create(Specification $spec, QueryBuilder $qb)
 {
     if (!$spec instanceof Not) {
         throw new \InvalidArgumentException();
     }
     $factory = $this->registry->getFactory($spec->getWrappedSpecification());
     return $qb->expr()->not($factory->create($spec->getWrappedSpecification(), $qb));
 }
 /**
  * {inheritdoc}
  */
 public function create(Specification $spec, QueryBuilder $qb)
 {
     if (!$spec instanceof OrX) {
         throw new \InvalidArgumentException();
     }
     $firstPartFactory = $this->registry->getFactory($spec->getFirstPart());
     $secondPartFactory = $this->registry->getFactory($spec->getSecondPart());
     return $qb->expr()->orx($firstPartFactory->create($spec->getFirstPart(), $qb), $secondPartFactory->create($spec->getSecondPart(), $qb));
 }
 public function testGetFactoryReturnsAssociatedFactory()
 {
     $registry = new Registry();
     $factory = $this->getMock('GBprod\\DoctrineSpecification\\QueryFactory\\Factory');
     $registry->register(self::class, $factory);
     $this->assertEquals($factory, $registry->getFactory($this));
 }
 public function testBuildReturnsOrxExpressionWithBuildedParts()
 {
     $not = new Not($this->getMock(Specification::class));
     $registry = new Registry();
     $registry->register(get_class($not->getWrappedSpecification()), $this->getMock(Factory::class));
     $qb = $this->getQueryBuilder();
     $exprFirstPart = new Comparison('4', '=', '4');
     $registry->getFactory($not->getWrappedSpecification())->expects($this->any())->method('create')->with($not->getWrappedSpecification(), $qb)->willReturn($exprFirstPart);
     $factory = new NotFactory($registry);
     $expr = $factory->create($not, $qb);
     $this->assertEquals($exprFirstPart, $expr->getArguments()[0]);
 }
 /**
  * handle specification for queryfactory
  *
  * @param Specification $spec
  *
  * @return Base
  */
 public function handle(Specification $spec)
 {
     $factory = $this->registry->getFactory($spec);
     return $factory->create($spec, $this->qb);
 }