Skip to content

Commit

Permalink
Added notEqualTo function to Predicate class
Browse files Browse the repository at this point in the history
Added test to check proper functionality of notEqualTo function
  • Loading branch information
postalservice14 committed Jul 26, 2012
1 parent 40d6d43 commit 5f916c3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
22 changes: 22 additions & 0 deletions library/Zend/Db/Sql/Predicate/Predicate.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,28 @@ public function equalTo($left, $right, $leftType = self::TYPE_IDENTIFIER, $right
return $this;
}

/**
* Create "Not Equal To" predicate
*
* Utilizes Operator predicate
*
* @param scalar $left
* @param scalar $right
* @param TYPE_IDENTIFIER|TYPE_VALUE $leftType
* @param TYPE_IDENTIFIER|TYPE_VALUE $rightType
* @return Predicate
*/
public function notEqualTo($left, $right, $leftType = self::TYPE_IDENTIFIER, $rightType = self::TYPE_VALUE)
{
$this->addPredicate(
new Operator($left, Operator::OPERATOR_NOT_EQUAL_TO, $right, $leftType, $rightType),
($this->nextPredicateCombineOperator) ?: $this->defaultCombination
);
$this->nextPredicateCombineOperator = null;

return $this;
}

/**
* Create "Less Than" predicate
*
Expand Down
11 changes: 11 additions & 0 deletions tests/Zend/Db/Sql/Predicate/PredicateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ public function testEqualToCreatesOperatorPredicate()
$this->assertContains(array('foo.bar', 'bar'), $parts[0]);
}

public function testNotEqualToCreatesOperatorPredicate()
{
$predicate = new Predicate();
$predicate->notEqualTo('foo.bar', 'bar');
$parts = $predicate->getExpressionData();
$this->assertEquals(1, count($parts));
$this->assertContains('%s != %s', $parts[0]);
$this->assertContains(array('foo.bar', 'bar'), $parts[0]);
}


public function testLessThanCreatesOperatorPredicate()
{
$predicate = new Predicate();
Expand Down

0 comments on commit 5f916c3

Please sign in to comment.