<commit_before><commit_msg>tests for midgard_query_constraint family of classes<commit_after>--TEST--
tests for midgard_query_constraint classes
--SKIPIF--
<?php if (!extension_loaded("midgard2")) print "skip"; ?>
--INI--
midgard.engine = On
midgard.http = On
midgard.memory_debug = Off
midgard.configuration_file=[[CFG_FILE]]
report_memleaks = Off
--ENV--
MIDGARD_ENV_GLOBAL_SHAREDIR=[[SHARE_PATH]]
--FILE--
<?php
$storage = new midgard_query_storage('atype');
$property = new midgard_query_property('a', $storage);
$value = new midgard_query_value('abc');

$constraint = new midgard_query_constraint($property, '=', $value, $storage);

var_dump($constraint->property instanceof midgard_query_property);
var_dump($constraint->operator === '=');
var_dump($constraint->holder instanceof midgard_query_value);
var_dump($constraint->storage instanceof midgard_query_storage);

unset($storage, $property, $value);

var_dump($constraint->property instanceof midgard_query_property);
var_dump($constraint->operator === '=');
var_dump($constraint->holder instanceof midgard_query_value);
var_dump($constraint->storage instanceof midgard_query_storage);


echo "==group==\n";

$group = new midgard_query_constraint_group();
$list = $group->list_constraints();

var_dump(is_array($list));
var_dump(count($list) == 0);

$group->add_constraint($constraint);
$group->add_constraint($constraint);
$list = $group->list_constraints();

var_dump(is_array($list));
var_dump(count($list) == 2);

unset($constraint);

$list = $group->list_constraints();

var_dump(is_array($list));
var_dump(count($list) == 2);

foreach ($list as $constraint) {
    if (!($constraint instanceof midgard_query_constraint)) {
        echo 'wrong type: '.var_export($constraint, true)."\n";
    }
}

?>
===DONE===
--EXPECTF--
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
==group==
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
===DONE===
{'fraction_non_alphanumeric': 0.1728709841917389, 'fraction_numerical': 0.002039775624681285, 'mean_word_length': 7.758928571428571, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5038251', 'n_tokens_mistral': 674, 'n_tokens_neox': 652, 'n_words': 122}