Permalink
Browse files

Change constructor signature for new ModelCriterion classes

Refs #41.
  • Loading branch information...
1 parent ee7d45f commit 56265974ef80c6acf1eaaf4d24304be4c36a8198 @fzaninotto fzaninotto committed Jul 28, 2012
@@ -24,12 +24,12 @@
/**
* Create a new instance.
*
- * @param Criteria $parent The outer class (this is an "inner" class).
+ * @param Criteria $outer The outer class (this is an "inner" class).
+ * @param string $clause A simple pseudo-SQL clause, e.g. 'foo.BAR LIKE ?'
* @param ColumnMap $column A Column object to help escaping the value
* @param mixed $value
- * @param string $clause A simple pseudo-SQL clause, e.g. 'foo.BAR LIKE ?'
*/
- public function __construct(Criteria $outer, $column, $value = null, $clause = null)
+ public function __construct(Criteria $outer, $clause, $column, $value = null)
{
$this->value = $value;
$this->setColumn($column);
@@ -33,7 +33,7 @@ class RawCriterion extends AbstractCriterion
* @param Criteria $parent The outer class (this is an "inner" class).
* @param string $column ignored
* @param string $value The condition to be added to the query string
- * @param string $typ A PDO type constant, e.g. PDO::PARAM_STR
+ * @param string $type A PDO type constant, e.g. PDO::PARAM_STR
*/
public function __construct(Criteria $outer, $column, $value, $type = PDO::PARAM_STR)
{
@@ -30,15 +30,16 @@ class RawModelCriterion extends AbstractModelCriterion
/**
* Create a new instance.
*
- * @param Criteria $parent The outer class (this is an "inner" class).
+ * @param Criteria $outer The outer class (this is an "inner" class).
+ * @param string $clause A simple pseudo-SQL clause, e.g. 'foo.BAR LIKE ?'
* @param ColumnMap $column A Column object to help escaping the value
* @param mixed $value
- * @param string $clause A simple pseudo-SQL clause, e.g. 'foo.BAR LIKE ?'
+ * @param string $type A PDO type constant, e.g. PDO::PARAM_STR
*/
- public function __construct(Criteria $outer, $column, $value = null, $clause = null, $type = PDO::PARAM_STR)
+ public function __construct(Criteria $outer, $clause, $column, $value = null, $type = PDO::PARAM_STR)
{
$this->type = $type;
- parent::__construct($outer, $column, $value, $clause);
+ parent::__construct($outer, $clause, $column, $value);
}
/**
@@ -1859,15 +1859,15 @@ protected function getCriterionForClause($clause, $value, $bindingType = null)
$value = $this->convertValueForColumn($value, $colMap);
$clauseLen = strlen($clause);
if (null !== $bindingType) {
- $criterion = new RawModelCriterion($this, $colMap, $value, $clause, $bindingType);
+ $criterion = new RawModelCriterion($this, $clause, $colMap, $value, $bindingType);
} elseif (stripos($clause, 'IN ?') == $clauseLen - 4) {
- $criterion = new InModelCriterion($this, $colMap, $value, $clause, $bindingType);
+ $criterion = new InModelCriterion($this, $clause, $colMap, $value);
} elseif (stripos($clause, 'LIKE ?') == $clauseLen - 6) {
- $criterion = new LikeModelCriterion($this, $colMap, $value, $clause, $bindingType);
+ $criterion = new LikeModelCriterion($this, $clause, $colMap, $value);
} elseif (substr_count($clause, '?') > 1) {
- $criterion = new SeveralModelCriterion($this, $colMap, $value, $clause, $bindingType);
+ $criterion = new SeveralModelCriterion($this, $clause, $colMap, $value);
} else {
- $criterion = new BasicModelCriterion($this, $colMap, $value, $clause, $bindingType);
+ $criterion = new BasicModelCriterion($this, $clause, $colMap, $value);
}
if (!empty($this->currentAlias)) {
@@ -24,7 +24,7 @@ class BasicModelCriterionTest extends BaseTestCase
{
public function testAppendPsToAddsBindingInfoForNotNullValues()
{
- $cton = new BasicModelCriterion(new Criteria(), 'A.COL', 'foo', 'A.COL = ?');
+ $cton = new BasicModelCriterion(new Criteria(), 'A.COL = ?', 'A.COL', 'foo');
$params = array();
$ps = '';
@@ -42,7 +42,7 @@ public function testAppendPsToAddsBindingInfoForNotNullValues()
*/
public function testAppendPsToThrowsExceptionWhenBindingAValueToAClauseWithNoQuestionMark()
{
- $cton = new BasicModelCriterion(new Criteria(), 'A.COL', 'foo', 'A.COL = B.COL');
+ $cton = new BasicModelCriterion(new Criteria(), 'A.COL = B.COL', 'A.COL', 'foo');
$params = array();
$ps = '';
@@ -51,7 +51,7 @@ public function testAppendPsToThrowsExceptionWhenBindingAValueToAClauseWithNoQue
public function testAppendPsToAddsClauseWithoutBindingForNullValues()
{
- $cton = new BasicModelCriterion(new Criteria(), 'A.COL', null, 'A.COL IS NULL');
+ $cton = new BasicModelCriterion(new Criteria(), 'A.COL IS NULL', 'A.COL', null);
$params = array();
$ps = '';
@@ -24,7 +24,7 @@ class InModelCriterionTest extends BaseTestCase
{
public function testAppendPsToCreatesAnInConditionByDefault()
{
- $cton = new InModelCriterion(new Criteria(), 'A.COL', array('foo'), 'A.COL IN ?');
+ $cton = new InModelCriterion(new Criteria(), 'A.COL IN ?', 'A.COL', array('foo'));
$params = array();
$ps = '';
@@ -39,7 +39,7 @@ public function testAppendPsToCreatesAnInConditionByDefault()
public function testAppendPsToCreatesANotInConditionWhenSpecified()
{
- $cton = new InModelCriterion(new Criteria(), 'A.COL', array('foo'), 'A.COL NOT IN ?');
+ $cton = new InModelCriterion(new Criteria(), 'A.COL NOT IN ?', 'A.COL', array('foo'));
$params = array();
$ps = '';
@@ -54,7 +54,7 @@ public function testAppendPsToCreatesANotInConditionWhenSpecified()
public function testAppendPsToWithArrayValueCreatesAnInCondition()
{
- $cton = new InModelCriterion(new Criteria(), 'A.COL', array('foo', 'bar'), 'A.COL IN ?');
+ $cton = new InModelCriterion(new Criteria(), 'A.COL IN ?', 'A.COL', array('foo', 'bar'));
$params = array();
$ps = '';
@@ -70,7 +70,7 @@ public function testAppendPsToWithArrayValueCreatesAnInCondition()
public function testAppendPsToWithScalarValueCreatesAnInCondition()
{
- $cton = new InModelCriterion(new Criteria(), 'A.COL', 'foo', 'A.COL IN ?');
+ $cton = new InModelCriterion(new Criteria(), 'A.COL IN ?', 'A.COL', 'foo');
$params = array();
$ps = '';
@@ -98,7 +98,7 @@ public static function providerForNotEmptyValues()
*/
public function testAppendPsToWithNotEmptyValueCreatesAnInCondition($notEmptyValue)
{
- $cton = new InModelCriterion(new Criteria(), 'A.COL', $notEmptyValue, 'A.COL IN ?');
+ $cton = new InModelCriterion(new Criteria(), 'A.COL IN ?', 'A.COL', $notEmptyValue);
$params = array();
$ps = '';
@@ -124,7 +124,7 @@ public static function providerForEmptyValues()
*/
public function testAppendPsToWithInAndEmptyValueCreatesAnAlwaysFalseCondition($emptyValue)
{
- $cton = new InModelCriterion(new Criteria(), 'A.COL', $emptyValue, 'A.COL IN ?');
+ $cton = new InModelCriterion(new Criteria(), 'A.COL IN ?', 'A.COL', $emptyValue);
$params = array();
$ps = '';
@@ -140,7 +140,7 @@ public function testAppendPsToWithInAndEmptyValueCreatesAnAlwaysFalseCondition($
*/
public function testAppendPsToWithNotInAndEmptyValueCreatesAnAlwaysTrueCondition($emptyValue)
{
- $cton = new InModelCriterion(new Criteria(), 'A.COL', $emptyValue, 'A.COL NOT IN ?');
+ $cton = new InModelCriterion(new Criteria(), 'A.COL NOT IN ?', 'A.COL', $emptyValue);
$params = array();
$ps = '';
@@ -156,7 +156,7 @@ public function testAppendPsToWithNotInAndEmptyValueCreatesAnAlwaysTrueCondition
*/
public function testAppendPsToWithNotInAndEmptyValueIsCaseInsensitive($emptyValue)
{
- $cton = new InModelCriterion(new Criteria(), 'A.COL', $emptyValue, 'A.COL not in ?');
+ $cton = new InModelCriterion(new Criteria(), 'A.COL not in ?', 'A.COL', $emptyValue);
$params = array();
$ps = '';
@@ -26,7 +26,7 @@ class LikeModelCriterionTest extends BaseTestCase
{
public function testAppendPsToCreatesALikeConditionByDefault()
{
- $cton = new LikeModelCriterion(new Criteria(), 'A.COL', 'foo%', 'A.COL LIKE ?');
+ $cton = new LikeModelCriterion(new Criteria(), 'A.COL LIKE ?', 'A.COL', 'foo%');
$params = array();
$ps = '';
@@ -41,7 +41,7 @@ public function testAppendPsToCreatesALikeConditionByDefault()
public function testAppendPsToCreatesANotLikeConditionIfSpecified()
{
- $cton = new LikeModelCriterion(new Criteria(), 'A.COL', 'foo%', 'A.COL NOT LIKE ?');
+ $cton = new LikeModelCriterion(new Criteria(), 'A.COL NOT LIKE ?', 'A.COL', 'foo%');
$params = array();
$ps = '';
@@ -59,7 +59,7 @@ public function testAppendPsToCreatesANotLikeConditionIfSpecified()
*/
public function testAppendPsToWithACaseInsensitiveLikeConditionThrowsAnException()
{
- $cton = new LikeModelCriterion(new Criteria(), 'A.COL', 'foo%', 'A.COL LIKE ?');
+ $cton = new LikeModelCriterion(new Criteria(), 'A.COL LIKE ?', 'A.COL', 'foo%');
$cton->setAdapter(new SqliteAdapter());
$cton->setIgnoreCase(true);
$params = array();
@@ -69,7 +69,7 @@ public function testAppendPsToWithACaseInsensitiveLikeConditionThrowsAnException
public function testAppendPsToCreatesACaseInsensitiveLikeConditionIfSpecifiedOnPgSQL()
{
- $cton = new LikeModelCriterion(new Criteria(), 'A.COL', 'foo%', 'A.COL LIKE ?');
+ $cton = new LikeModelCriterion(new Criteria(), 'A.COL LIKE ?', 'A.COL', 'foo%');
$cton->setAdapter(new PgsqlAdapter());
$cton->setIgnoreCase(true);
$params = array();
@@ -85,7 +85,7 @@ public function testAppendPsToCreatesACaseInsensitiveLikeConditionIfSpecifiedOnP
public function testAppendPsToWithCaseInsensitiveAndPostgreSQLUsesNOTILIKE()
{
- $cton = new LikeModelCriterion(new Criteria(), 'A.COL', 'foo%', 'A.COL NOT LIKE ?');
+ $cton = new LikeModelCriterion(new Criteria(), 'A.COL NOT LIKE ?', 'A.COL', 'foo%');
$cton->setAdapter(new PgsqlAdapter());
$cton->setIgnoreCase(true);
$params = array();
@@ -29,16 +29,16 @@ class RawModelCriterionTest extends BaseTestCase
*/
public function testAppendPsToThrowsExceptionWhenClauseHasNoQuestionMark()
{
- $cton = new RawModelCriterion(new Criteria(), 'A.COL', 1, 'A.COL = BAR', PDO::PARAM_INT);
+ $cton = new RawModelCriterion(new Criteria(), 'A.COL = BAR', 'A.COL', 1, PDO::PARAM_INT);
$params = array();
$ps = '';
$cton->appendPsTo($ps, $params);
}
- public function testAppendPsToCreatesAPDOClauseyDefault()
+ public function testAppendPsToCreatesAPDOClauseByDefault()
{
- $cton = new RawModelCriterion(new Criteria(), 'A.COL', 1, 'A.COL = ?', PDO::PARAM_INT);
+ $cton = new RawModelCriterion(new Criteria(), 'A.COL = ?', 'A.COL', 1, PDO::PARAM_INT);
$params = array();
$ps = '';
@@ -53,7 +53,7 @@ public function testAppendPsToCreatesAPDOClauseyDefault()
public function testAppendPsToUsesParamStrByDefault()
{
- $cton = new RawModelCriterion(new Criteria(), 'A.COL', 1, 'A.COL = ?');
+ $cton = new RawModelCriterion(new Criteria(), 'A.COL = ?', 'A.COL', 1);
$params = array();
$ps = '';
@@ -24,7 +24,7 @@ class SeveralModelCriterionTest extends BaseTestCase
{
public function testAppendPsToAddsBindingInfoForNotNullValues()
{
- $cton = new SeveralModelCriterion(new Criteria(), 'A.COL', array('foo', 'bar'), 'A.COL BETWEEN ? AND ?');
+ $cton = new SeveralModelCriterion(new Criteria(), 'A.COL BETWEEN ? AND ?', 'A.COL', array('foo', 'bar'));
$params = array();
$ps = '';
@@ -43,7 +43,7 @@ public function testAppendPsToAddsBindingInfoForNotNullValues()
*/
public function testAppendPsToThrowsExceptionWhenOneOfTheValuesIsNull()
{
- $cton = new SeveralModelCriterion(new Criteria(), 'A.COL', array('foo', null), 'A.COL BETWEEN ? AND ?');
+ $cton = new SeveralModelCriterion(new Criteria(), 'A.COL BETWEEN ? AND ?', 'A.COL', array('foo', null));
$params = array();
$ps = '';
@@ -55,7 +55,7 @@ public function testAppendPsToThrowsExceptionWhenOneOfTheValuesIsNull()
*/
public function testAppendPsToThrowsExceptionWhenTheValueIsNull()
{
- $cton = new SeveralModelCriterion(new Criteria(), 'A.COL', null, 'A.COL BETWEEN ? AND ?');
+ $cton = new SeveralModelCriterion(new Criteria(), 'A.COL BETWEEN ? AND ?', 'A.COL', null);
$params = array();
$ps = '';

0 comments on commit 5626597

Please sign in to comment.