コード例 #1
0
 public function testGetFactoryReturnsAssociatedFactory()
 {
     $registry = new Registry();
     $factory = $this->getMock('GBprod\\DoctrineSpecification\\QueryFactory\\Factory');
     $registry->register(self::class, $factory);
     $this->assertEquals($factory, $registry->getFactory($this));
 }
コード例 #2
0
 /**
  * {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));
 }
コード例 #3
0
 /**
  * {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));
 }
コード例 #4
0
 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]);
 }
コード例 #5
0
 public function testBuildReturnsAndxExpressionWithBuildedParts()
 {
     $andx = $this->createAndX();
     $registry = new Registry();
     $qb = $this->getQueryBuilder();
     $exprFirstPart = new Comparison('4', '=', '4');
     $exprSecondPart = new Comparison('4', '=', '3');
     $factoryFirstPart = $this->prophesize(Factory::class);
     $factorySecondPart = $this->prophesize(Factory::class);
     $registry->register(get_class($andx->getFirstPart()), $factoryFirstPart->reveal());
     $registry->register(get_class($andx->getSecondPart()), $factorySecondPart->reveal());
     $factoryFirstPart->create($andx->getFirstPart(), $qb)->willReturn($exprFirstPart);
     $factorySecondPart->create($andx->getSecondPart(), $qb)->willReturn($exprSecondPart);
     $factory = new AndXFactory($registry);
     $expr = $factory->create($andx, $qb);
     $this->assertEquals($exprFirstPart, $expr->getParts()[0]);
     $this->assertEquals($exprSecondPart, $expr->getParts()[1]);
 }
コード例 #6
0
 /**
  * Register a factory for specification
  *
  * @param string  $classname specification fully qualified classname
  * @param Factory $factory
  */
 public function registerFactory($classname, Factory $factory)
 {
     $this->registry->register($classname, $factory);
 }