From 8032785f0d64357fb492518e75dbc0b0eca3438c Mon Sep 17 00:00:00 2001 From: Paul Klimov Date: Fri, 6 Dec 2013 11:38:00 +0200 Subject: [PATCH] Method "\yii\mogo\Collection::buildLikeCondition()" fixed to use \MongoRegex. --- extensions/mongo/Collection.php | 5 ++++- tests/unit/extensions/mongo/QueryRunTest.php | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/extensions/mongo/Collection.php b/extensions/mongo/Collection.php index 9b76b26..9bd8bcc 100644 --- a/extensions/mongo/Collection.php +++ b/extensions/mongo/Collection.php @@ -907,6 +907,9 @@ class Collection extends Object throw new InvalidParamException("Operator '$operator' requires two operands."); } list($column, $value) = $operands; - return [$column => '/' . $value . '/']; + if (!($value instanceof \MongoRegex)) { + $value = new \MongoRegex($value); + } + return [$column => $value]; } } \ No newline at end of file diff --git a/tests/unit/extensions/mongo/QueryRunTest.php b/tests/unit/extensions/mongo/QueryRunTest.php index 7fe4812..121e826 100644 --- a/tests/unit/extensions/mongo/QueryRunTest.php +++ b/tests/unit/extensions/mongo/QueryRunTest.php @@ -129,4 +129,16 @@ class QueryRunTest extends MongoTestCase ->all($connection); $this->assertEquals(1, count($rows)); } + + public function testLike() + { + $connection = $this->getConnection(); + $query = new Query; + $rows = $query->from('customer') + ->where(['LIKE', 'name', '/me1/']) + ->all($connection); + $this->assertEquals(2, count($rows)); + $this->assertEquals('name1', $rows[0]['name']); + $this->assertEquals('name10', $rows[1]['name']); + } } \ No newline at end of file