From ece0e3ad881fae4b0cb434aaa6257cdc5da6f5fc Mon Sep 17 00:00:00 2001 From: David Abdemoulaie Date: Tue, 25 May 2010 15:10:59 -0500 Subject: [PATCH 1/2] Third parameter to Expr::substring is now optional --- lib/Doctrine/ORM/Query/Expr.php | 8 ++++++-- tests/Doctrine/Tests/ORM/Query/ExprTest.php | 9 +++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Query/Expr.php b/lib/Doctrine/ORM/Query/Expr.php index 35130fd89..e071d325e 100644 --- a/lib/Doctrine/ORM/Query/Expr.php +++ b/lib/Doctrine/ORM/Query/Expr.php @@ -470,9 +470,13 @@ class Expr * @param integer $len Length of crop. May accept negative values. * @return Expr\Func */ - public function substring($x, $from, $len) + public function substring($x, $from, $len = null) { - return new Expr\Func('SUBSTRING', array($x, $from, $len)); + $args = array($x, $from); + if (null !== $len) { + $args[] = $len; + } + return new Expr\Func('SUBSTRING', $args); } /** diff --git a/tests/Doctrine/Tests/ORM/Query/ExprTest.php b/tests/Doctrine/Tests/ORM/Query/ExprTest.php index 60449e5b9..5bf5b06b5 100644 --- a/tests/Doctrine/Tests/ORM/Query/ExprTest.php +++ b/tests/Doctrine/Tests/ORM/Query/ExprTest.php @@ -185,6 +185,15 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals('SUBSTRING(a.title, 0, 25)', (string) $this->_expr->substring('a.title', 0, 25)); } + /** + * @group regression + * @group DDC-612 + */ + public function testSubstringExprAcceptsTwoArguments() + { + $this->assertEquals('SUBSTRING(a.title, 0)', (string) $this->_expr->substring('a.title', 5)); + } + public function testLowerExpr() { $this->assertEquals('LOWER(u.first_name)', (string) $this->_expr->lower('u.first_name')); From 93701e6736408e7743c74c4a3db78c29de34f4c9 Mon Sep 17 00:00:00 2001 From: David Abdemoulaie Date: Tue, 25 May 2010 15:13:01 -0500 Subject: [PATCH 2/2] Updating gitignore to properly ignore Common and DBAL --- .gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index a98d881c8..04f63f22d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,5 @@ reports/ dist/ download/ lib/api/ -lib/Doctrine/Common/ -lib/Doctrine/DBAL/ +lib/Doctrine/Common +lib/Doctrine/DBAL