/** * @covers WindowsAzure\Table\Models\Filters\Filter::applyNot * @covers WindowsAzure\Table\Models\Filters\Filter::applyConstant */ public function testApplyNot() { // Setup $operand = Filter::applyConstant('test', EdmType::STRING); // Test $actual = Filter::applyNot($operand); // Assert $this->assertEquals($operand, $actual->getOperand()); }
public function testCheckUnaryFilter() { $filter = new UnaryFilter(null, null); $this->assertNotNull($filter, 'Default $filter'); $this->assertNull($filter->getOperand(), 'Default UnaryFilter->getOperand'); $this->assertNull($filter->getOperator(), 'Default UnaryFilter->getOperator'); $operand = new BinaryFilter(null, null, null); $operator = 'foo'; $filter = new UnaryFilter($operator, $operand); $this->assertEquals($operand, $filter->getOperand(), 'Set UnaryFilter->getOperand'); $this->assertEquals($operator, $filter->getOperator(), 'Set UnaryFilter->getOperator'); // Now check the factory. $operand = new ConstantFilter(EdmType::STRING, null); $filter = Filter::applyNot($operand); $this->assertEquals($operand, $filter->getOperand(), 'Unary factory UnaryFilter->getOperand'); $this->assertEquals('not', $filter->getOperator(), 'Unary factory UnaryFilter->getOperator'); }
private static function generateFilterWithBooleanParameters($targetDepth, $depth) { // Use the filter grammar to construct a tree. // The random here is not to generate random values, but to // get a good mix of values in the table entities. // TODO: Treat raw string special if ($depth == $targetDepth) { switch (mt_rand(0, 2)) { case 0: return self::generateBinaryFilterWithAnyParameters(); case 1: return Filter::applyConstant(mt_rand(0, 1) == 1, EdmType::BOOLEAN); case 2: $e = self::getEntityFromTable(); $boolPropNames = array(); foreach ($e->getProperties() as $key => $p) { if ($p->getEdmType() == EdmType::BOOLEAN) { array_push($boolPropNames, $key); } } if (count($boolPropNames) == 0) { return Filter::applyConstant(mt_rand(0, 1) == 1, EdmType::BOOLEAN); } else { $key = $boolPropNames[mt_rand(0, count($boolPropNames) - 1)]; return Filter::applyPropertyName($key); } default: return null; } } else { switch (mt_rand(0, 8)) { case 0: case 1: case 2: case 3: return Filter::applyAnd(self::generateFilterWithBooleanParameters($targetDepth, $depth + 1), self::generateFilterWithBooleanParameters($targetDepth, $depth + 1)); case 4: case 5: case 6: case 7: return Filter::applyOr(self::generateFilterWithBooleanParameters($targetDepth, $depth + 1), self::generateFilterWithBooleanParameters($targetDepth, $depth + 1)); case 8: return Filter::applyNot(self::generateFilterWithBooleanParameters($targetDepth, $depth + 1)); default: return null; } } }