Permalink
Browse files

unit test: Test where() will accept any array with string key (withou…

…t ?) with Predicate object as-is
  • Loading branch information...
1 parent 9d5624c commit b33846b6448d8551d2b871417e41e3b658641555 @moura137 committed Feb 8, 2013
Showing with 29 additions and 1 deletion.
  1. +29 −1 tests/ZendTest/Db/Sql/SelectTest.php
@@ -239,7 +239,35 @@ public function testWhereArgument1IsAssociativeArrayNotContainingReplacementChar
$predicates = $where->getPredicates();
$this->assertInstanceOf('Zend\Db\Sql\Predicate\Literal', $predicates[0][1]);
}
-
+
+ /**
+ * @testdox unit test: Test where() will accept any array with string key (without ?) with Predicate object as-is
+ * @covers Zend\Db\Sql\Select::where
+ */
+ public function testWhereArgument1IsAssociativeArrayIsPredicate()
+ {
+ $select = new Select;
+ $where = array(
+ 'name' => new Predicate\Literal("name = 'Ralph'"),
+ 'age' => new Predicate\Expression('age = ?', 33),
+ );
+ $select->where($where);
+
+ /** @var $where Where */
+ $where = $select->getRawState('where');
+ $predicates = $where->getPredicates();
+ $this->assertEquals(2, count($predicates));
+
+ $this->assertInstanceOf('Zend\Db\Sql\Predicate\Literal', $predicates[0][1]);
+ $this->assertEquals(Where::OP_AND, $predicates[0][0]);
+ $this->assertEquals("name = 'Ralph'", $predicates[0][1]->getLiteral());
+
+ $this->assertInstanceOf('Zend\Db\Sql\Predicate\Expression', $predicates[1][1]);
+ $this->assertEquals(Where::OP_AND, $predicates[1][0]);
+ $this->assertEquals('age = ?', $predicates[1][1]->getExpression());
+ $this->assertEquals(array(33), $predicates[1][1]->getParameters());
+ }
+
/**
* @testdox unit test: Test where() will accept an indexed array to be used by joining string expressions
* @covers Zend\Db\Sql\Select::where

0 comments on commit b33846b

Please sign in to comment.