예제 #1
0
 public function testVisit_WhenFilterByTypeThatIsNotSupported()
 {
     $queryBuilder = 'can be anything';
     $entityFieldNames = ['id', 'title', 'price'];
     $criteriaMock = $this->getMockBuilder(Criteria::class)->disableOriginalConstructor()->getMock();
     $criteriaMock->expects($this->exactly(2))->method('getType')->willReturn('notSupportedType');
     $criteriaMock->expects($this->once())->method('getKey')->willReturn('title');
     $this->queryFilterMock->expects($this->once())->method('getCriteria')->willReturn([$criteriaMock]);
     $this->commandCollectionMock->expects($this->once())->method('offsetGet')->with('notSupportedType')->willReturn(null);
     $this->setExpectedException('BusinessLogicLibrary\\QueryFilter\\Exception\\UnsupportedTypeException', 'Tried to filter by field "notSupportedType" that is not supported');
     $result = $this->testedObject->visit($queryBuilder, $entityFieldNames);
     $this->assertSame($queryBuilder, $result);
 }
예제 #2
0
 /**
  * @param mixed $queryBuilder
  * @param array $entityFieldNames
  * @return mixed
  * @throws Exception\UnsupportedTypeException
  */
 public function visit($queryBuilder, array $entityFieldNames)
 {
     /** @var $criteria Criteria */
     foreach ($this->queryFilter->getCriteria() as $criteria) {
         $this->checkCriteriaKey($criteria->getKey(), $entityFieldNames);
         /** @var CommandInterface $command */
         if (!($command = $this->commandCollection->offsetGet($criteria->getType()))) {
             throw new Exception\UnsupportedTypeException(sprintf('Tried to filter by field "%s" that is not supported', $criteria->getType()));
         }
         $command->execute($queryBuilder, $criteria);
     }
     return $queryBuilder;
 }