20250801-1
This commit is contained in:
parent
ccdcc3e047
commit
906ed15c58
1
.gitignore
vendored
1
.gitignore
vendored
@ -2219,3 +2219,4 @@ FodyWeavers.xsd
|
||||
/vendor/autoload.php
|
||||
/composer.lock
|
||||
/vendor/goodboyalex/php_components_pack/
|
||||
/.idea/php-test-framework.xml
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
use goodboyalex\php_components_pack\classes\Tuple;
|
||||
use goodboyalex\php_components_pack\interfaces\IArrayable;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Группа условий запроса выборки по условию.
|
||||
@ -71,7 +72,7 @@
|
||||
$resultString .= $result->Get(0);
|
||||
|
||||
// - записываем условие в массив
|
||||
$resultArray[] = array_merge($resultArray, $result->Get(1));
|
||||
$resultArray = array_merge($resultArray, $result->Get(1));
|
||||
|
||||
// - записываем логический оператор
|
||||
$resultString .= " $this->LogicOperator ";
|
||||
@ -87,7 +88,7 @@
|
||||
$resultString .= $result->Get(0);
|
||||
|
||||
// Записываем условие в массив
|
||||
$resultArray[] = array_merge($resultArray, $result->Get(1));
|
||||
$resultArray = array_merge($resultArray, $result->Get(1));
|
||||
|
||||
// Очищаем результирующую строку от лишних пробелов
|
||||
$resultString = '(' . trim($resultString) . ')';
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace goodboyalex\php_db_components_pack\tests\classes;
|
||||
|
||||
use goodboyalex\php_components_pack\extensions\StringExtension;
|
||||
use goodboyalex\php_db_components_pack\classes\Condition;
|
||||
use goodboyalex\php_db_components_pack\classes\ConditionBuilder;
|
||||
use goodboyalex\php_db_components_pack\classes\ConditionGroup;
|
||||
@ -13,7 +14,7 @@
|
||||
{
|
||||
// Требуемое условие
|
||||
$requireCondition =
|
||||
"`id` = 1 AND `age` >= 18 OR `profile` <= 12 AND (`Name` = 'Alex' AND (`Age` > 18 OR `FirstName` = 'Titanic'))";
|
||||
"`id` = 1 AND `age` >= 18 OR `profile` <= 12 AND (`Name` = Alex AND (`Age` > 18 OR `FirstName` = Titanic))";
|
||||
|
||||
// Создаем условие методом цепочек
|
||||
$condition = new ConditionBuilder()->WhereEquals('id', 1)->And()->WhereGreaterThanEqual('age', 18)->Or()
|
||||
@ -26,8 +27,8 @@
|
||||
]),
|
||||
])->Build();
|
||||
|
||||
var_dump($condition->Get(0));
|
||||
var_dump($condition->Get(1));
|
||||
// Эмулирую подготовку условий
|
||||
$condition = StringExtension::ReplaceAll($condition->Get(1), $condition->Get(0));
|
||||
|
||||
// Проверяем его
|
||||
$this->assertEquals($requireCondition, $condition);
|
||||
@ -42,7 +43,13 @@
|
||||
// Создаем ConditionBuilder
|
||||
$builder = ConditionBuilder::Parse($conditionArray);
|
||||
|
||||
// Получаем условие
|
||||
$condition = $builder->Build();
|
||||
|
||||
// Эмулирую подготовку условий
|
||||
$condition = StringExtension::ReplaceAll($condition->Get(1), $condition->Get(0));
|
||||
|
||||
// Проверяем его
|
||||
$this->assertEquals($requireCondition, $builder->Build());
|
||||
$this->assertEquals($requireCondition, $condition);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user