/** * @covers Braincrafted\ArrayQuery\WhereEvaluation::addFilter() * @covers Braincrafted\ArrayQuery\WhereEvaluation::evaluate() * @covers Braincrafted\ArrayQuery\WhereEvaluation::evaluateFilter() * @covers Braincrafted\ArrayQuery\Evaluation::evaluateFilter() */ public function testEvaluateFilterWithArgs() { $operator = m::mock('Braincrafted\\ArrayQuery\\Operator\\OperatorInterface'); $operator->shouldReceive('getName')->andReturn('.'); $operator->shouldReceive('evaluate')->with('y', 'x')->andReturn(true); $this->where->addOperator($operator); $filter = m::mock('Braincrafted\\ArrayQuery\\Filter\\FilterInterface'); $filter->shouldReceive('getName')->andReturn('test'); $filter->shouldReceive('evaluate')->with('x', ['a'])->andReturn('y'); $this->where->addFilter($filter); $this->assertTrue($this->where->evaluate(['a' => 'x'], ['key' => 'a', 'value' => 'x', 'operator' => '.', 'filters' => 'test a'])); }
/** * @param WhereEvaluation $whereEvaluation * * @return WhereEvaluation */ protected function getWhereEvaluation($whereEvaluation = null) { if (null !== $whereEvaluation && false === $whereEvaluation instanceof WhereEvaluation) { throw new \InvalidArgumentException('Argument "whereEvaluation" must be an instance of WhereEvaluation.'); } if (null === $whereEvaluation) { $whereEvaluation = new WhereEvaluation(); } foreach (OperatorFactory::getOperators() as $operator) { $whereEvaluation->addOperator($operator); } foreach (FilterFactory::getFilters() as $filter) { $whereEvaluation->addFilter($filter); } return $whereEvaluation; }
/** * initialize evaluation */ protected function initializeEvaluation() { $whereEvaluation = new WhereEvaluation(); $whereEvaluation->addOperator(new EqualOperator())->addOperator(new NotEqualOperator())->addOperator(new GreaterOperator())->addOperator(new GreaterOrEqualOperator())->addOperator(new LikeOperator())->addOperator(new NotLikeOperator())->addOperator(new EqualOperator()); $this->whereEvaluation = $whereEvaluation; }