Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Forward #3733

Merge branch 'moura137-fix/SelectWhere' into develop
  • Loading branch information...
commit a5ff6079214287a3c0a07ce39032225ca13b8235 2 parents 438686c + 41702c9
@ralphschindler ralphschindler authored
View
8 library/Zend/Db/Sql/Select.php
@@ -260,6 +260,7 @@ public function join($name, $on, $columns = self::SQL_STAR, $type = self::JOIN_I
*
* @param Where|\Closure|string|array|Predicate\PredicateInterface $predicate
* @param string $combination One of the OP_* constants from Predicate\PredicateSet
+ * @throws Exception\InvalidArgumentException
* @return Select
*/
public function where($predicate, $combination = Predicate\PredicateSet::OP_AND)
@@ -295,12 +296,17 @@ public function where($predicate, $combination = Predicate\PredicateSet::OP_AND)
} elseif (is_array($pvalue)) {
// if the value is an array, assume IN() is desired
$predicate = new Predicate\In($pkey, $pvalue);
+ } elseif ($pvalue instanceof Predicate\PredicateInterface) {
+ //
+ throw new Exception\InvalidArgumentException(
+ 'Using Predicate must not use string keys'
+ );
} else {
// otherwise assume that array('foo' => 'bar') means "foo" = 'bar'
$predicate = new Predicate\Operator($pkey, Predicate\Operator::OP_EQ, $pvalue);
}
} elseif ($pvalue instanceof Predicate\PredicateInterface) {
- // Predicate type is ok
+ // Predicate type is ok
$predicate = $pvalue;
} else {
// must be an array of expressions (with int-indexed array)
View
21 tests/ZendTest/Db/Sql/SelectTest.php
@@ -44,7 +44,7 @@ public function testFrom()
}
/**
- * @testdox unit test: Test getRawState() returns infromation populated via from()
+ * @testdox unit test: Test getRawState() returns information populated via from()
* @covers Zend\Db\Sql\Select::getRawState
* @depends testFrom
*/
@@ -66,7 +66,7 @@ public function testQuantifier()
}
/**
- * @testdox unit test: Test getRawState() returns infromation populated via from()
+ * @testdox unit test: Test getRawState() returns information populated via from()
* @covers Zend\Db\Sql\Select::getRawState
* @depends testQuantifier
*/
@@ -239,7 +239,22 @@ 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 throw Exception
+ * @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),
+ );
+ $this->setExpectedException('Zend\Db\Sql\Exception\InvalidArgumentException', 'Using Predicate must not use string keys');
+ $select->where($where);
+ }
+
/**
* @testdox unit test: Test where() will accept an indexed array to be used by joining string expressions
* @covers Zend\Db\Sql\Select::where
Please sign in to comment.
Something went wrong with that request. Please try again.