From 2b28edceb609132a47eb96be028e156edcbca13f Mon Sep 17 00:00:00 2001 From: Aziz Muzafarov Date: Tue, 21 Sep 2021 12:21:40 +0300 Subject: [PATCH 1/2] #15553 - Fix Query::getExpression() return type --- CHANGELOG-5.0.md | 3 +++ phalcon/Mvc/Model/Query.zep | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG-5.0.md b/CHANGELOG-5.0.md index af38638eecf..a146f410ceb 100644 --- a/CHANGELOG-5.0.md +++ b/CHANGELOG-5.0.md @@ -1,5 +1,8 @@ # [5.0.0alpha7](https://github.com/phalcon/cphalcon/releases/tag/v5.0.0alpha6) (xxxx-xx-xx) +## Fixed +- Fixed `Query::getExpression()` return type [#15553](https://github.com/phalcon/cphalcon/issues/15553) + # [5.0.0alpha6](https://github.com/phalcon/cphalcon/releases/tag/v5.0.0alpha6) (2021-09-16) ## Changed diff --git a/phalcon/Mvc/Model/Query.zep b/phalcon/Mvc/Model/Query.zep index 14a1d3a368a..a81e0f79c25 100644 --- a/phalcon/Mvc/Model/Query.zep +++ b/phalcon/Mvc/Model/Query.zep @@ -1542,9 +1542,9 @@ class Query implements QueryInterface, InjectionAwareInterface } /** - * Resolves an expression from its intermediate code into a string + * Resolves an expression from its intermediate code into an array */ - final protected function getExpression(array expr, bool quoting = true) -> string + final protected function getExpression(array expr, bool quoting = true) -> array { var exprType, exprLeft, exprRight, left = null, right = null, listItems, exprListItem, exprReturn, value, escapedValue, From ccedaff4e5e2ed76915544d38dcb0812d91affbf Mon Sep 17 00:00:00 2001 From: Aziz Muzafarov Date: Tue, 21 Sep 2021 12:45:07 +0300 Subject: [PATCH 2/2] #15553 - Added unit test --- .../Mvc/Model/Query/GetExpressionCest.php | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tests/unit/Mvc/Model/Query/GetExpressionCest.php diff --git a/tests/unit/Mvc/Model/Query/GetExpressionCest.php b/tests/unit/Mvc/Model/Query/GetExpressionCest.php new file mode 100644 index 00000000000..4771a0cbe0c --- /dev/null +++ b/tests/unit/Mvc/Model/Query/GetExpressionCest.php @@ -0,0 +1,64 @@ + + * + * For the full copyright and license information, please view the LICENSE.txt + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Phalcon\Test\Unit\Mvc\Model\Query; + +use Phalcon\Mvc\Model\Query; +use UnitTester; + +class GetExpressionCest +{ + private $PHQL_T_AND = 266; + private $PHQL_T_OR = 267; + + /** + * Tests Phalcon\Mvc\Model\Query :: getExpression() + * + * @author Phalcon Team + * @since 2021-09-21 + * @issue 15553 + */ + public function mvcModelQueryGetExpression(UnitTester $I) + { + $I->wantToTest('Phalcon\Mvc\Model\Query - getExpression()'); + + $valueOne = [ + 'type' => 'binary-op', + 'op' => 'AND', + 'left' => null, + 'right' => null, + ]; + $valueTwo = [ + 'type' => 'binary-op', + 'op' => 'OR', + 'left' => null, + 'right' => null, + ]; + + $oneExpr = [ + 'type' => $this->PHQL_T_AND, + ]; + + $twoExpr = [ + 'type' => $this->PHQL_T_OR, + ]; + + $query = new Query(); + $reflection = new \ReflectionClass(Query::class); + $getExpression = $reflection->getMethod('getExpression'); + $getExpression->setAccessible(true); + + $I->assertEquals($getExpression->invokeArgs($query, [$oneExpr, false]), $valueOne); + $I->assertEquals($getExpression->invokeArgs($query, [$twoExpr, false]), $valueTwo); + } +}