Add in/inArray; expand Field ctr func names

This commit is contained in:
Daniel J. Summers 2024-09-20 20:29:47 -04:00
parent 0a188a80c2
commit e830b1ac3e
28 changed files with 466 additions and 299 deletions

98
composer.lock generated
View File

@ -53,16 +53,16 @@
}, },
{ {
"name": "netresearch/jsonmapper", "name": "netresearch/jsonmapper",
"version": "v4.4.1", "version": "v4.5.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/cweiske/jsonmapper.git", "url": "https://github.com/cweiske/jsonmapper.git",
"reference": "132c75c7dd83e45353ebb9c6c9f591952995bbf0" "reference": "8e76efb98ee8b6afc54687045e1b8dba55ac76e5"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/cweiske/jsonmapper/zipball/132c75c7dd83e45353ebb9c6c9f591952995bbf0", "url": "https://api.github.com/repos/cweiske/jsonmapper/zipball/8e76efb98ee8b6afc54687045e1b8dba55ac76e5",
"reference": "132c75c7dd83e45353ebb9c6c9f591952995bbf0", "reference": "8e76efb98ee8b6afc54687045e1b8dba55ac76e5",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -98,9 +98,9 @@
"support": { "support": {
"email": "cweiske@cweiske.de", "email": "cweiske@cweiske.de",
"issues": "https://github.com/cweiske/jsonmapper/issues", "issues": "https://github.com/cweiske/jsonmapper/issues",
"source": "https://github.com/cweiske/jsonmapper/tree/v4.4.1" "source": "https://github.com/cweiske/jsonmapper/tree/v4.5.0"
}, },
"time": "2024-01-31T06:18:54+00:00" "time": "2024-09-08T10:13:13+00:00"
} }
], ],
"packages-dev": [ "packages-dev": [
@ -342,16 +342,16 @@
}, },
{ {
"name": "phpstan/phpstan", "name": "phpstan/phpstan",
"version": "1.12.0", "version": "1.12.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpstan/phpstan.git", "url": "https://github.com/phpstan/phpstan.git",
"reference": "384af967d35b2162f69526c7276acadce534d0e1" "reference": "0ca1c7bb55fca8fe6448f16fff0f311ccec960a1"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/384af967d35b2162f69526c7276acadce534d0e1", "url": "https://api.github.com/repos/phpstan/phpstan/zipball/0ca1c7bb55fca8fe6448f16fff0f311ccec960a1",
"reference": "384af967d35b2162f69526c7276acadce534d0e1", "reference": "0ca1c7bb55fca8fe6448f16fff0f311ccec960a1",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -396,36 +396,36 @@
"type": "github" "type": "github"
} }
], ],
"time": "2024-08-27T09:18:05+00:00" "time": "2024-09-05T16:09:28+00:00"
}, },
{ {
"name": "phpunit/php-code-coverage", "name": "phpunit/php-code-coverage",
"version": "11.0.5", "version": "11.0.6",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git",
"reference": "19b6365ab8b59a64438c0c3f4241feeb480c9861" "reference": "ebdffc9e09585dafa71b9bffcdb0a229d4704c45"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/19b6365ab8b59a64438c0c3f4241feeb480c9861", "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/ebdffc9e09585dafa71b9bffcdb0a229d4704c45",
"reference": "19b6365ab8b59a64438c0c3f4241feeb480c9861", "reference": "ebdffc9e09585dafa71b9bffcdb0a229d4704c45",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"ext-dom": "*", "ext-dom": "*",
"ext-libxml": "*", "ext-libxml": "*",
"ext-xmlwriter": "*", "ext-xmlwriter": "*",
"nikic/php-parser": "^5.0", "nikic/php-parser": "^5.1.0",
"php": ">=8.2", "php": ">=8.2",
"phpunit/php-file-iterator": "^5.0", "phpunit/php-file-iterator": "^5.0.1",
"phpunit/php-text-template": "^4.0", "phpunit/php-text-template": "^4.0.1",
"sebastian/code-unit-reverse-lookup": "^4.0", "sebastian/code-unit-reverse-lookup": "^4.0.1",
"sebastian/complexity": "^4.0", "sebastian/complexity": "^4.0.1",
"sebastian/environment": "^7.0", "sebastian/environment": "^7.2.0",
"sebastian/lines-of-code": "^3.0", "sebastian/lines-of-code": "^3.0.1",
"sebastian/version": "^5.0", "sebastian/version": "^5.0.1",
"theseer/tokenizer": "^1.2.0" "theseer/tokenizer": "^1.2.3"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^11.0" "phpunit/phpunit": "^11.0"
@ -437,7 +437,7 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-main": "11.0-dev" "dev-main": "11.0.x-dev"
} }
}, },
"autoload": { "autoload": {
@ -466,7 +466,7 @@
"support": { "support": {
"issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues",
"security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy",
"source": "https://github.com/sebastianbergmann/php-code-coverage/tree/11.0.5" "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/11.0.6"
}, },
"funding": [ "funding": [
{ {
@ -474,20 +474,20 @@
"type": "github" "type": "github"
} }
], ],
"time": "2024-07-03T05:05:37+00:00" "time": "2024-08-22T04:37:56+00:00"
}, },
{ {
"name": "phpunit/php-file-iterator", "name": "phpunit/php-file-iterator",
"version": "5.0.1", "version": "5.1.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/php-file-iterator.git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git",
"reference": "6ed896bf50bbbfe4d504a33ed5886278c78e4a26" "reference": "118cfaaa8bc5aef3287bf315b6060b1174754af6"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/6ed896bf50bbbfe4d504a33ed5886278c78e4a26", "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/118cfaaa8bc5aef3287bf315b6060b1174754af6",
"reference": "6ed896bf50bbbfe4d504a33ed5886278c78e4a26", "reference": "118cfaaa8bc5aef3287bf315b6060b1174754af6",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -527,7 +527,7 @@
"support": { "support": {
"issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues",
"security": "https://github.com/sebastianbergmann/php-file-iterator/security/policy", "security": "https://github.com/sebastianbergmann/php-file-iterator/security/policy",
"source": "https://github.com/sebastianbergmann/php-file-iterator/tree/5.0.1" "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/5.1.0"
}, },
"funding": [ "funding": [
{ {
@ -535,7 +535,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2024-07-03T05:06:37+00:00" "time": "2024-08-27T05:02:59+00:00"
}, },
{ {
"name": "phpunit/php-invoker", "name": "phpunit/php-invoker",
@ -723,16 +723,16 @@
}, },
{ {
"name": "phpunit/phpunit", "name": "phpunit/phpunit",
"version": "11.2.8", "version": "11.3.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git", "url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "a7a29e8d3113806f18f99d670f580a30e8ffff39" "reference": "8ed08766d9a2ed979a2f5fdbb95a0671523419c1"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a7a29e8d3113806f18f99d670f580a30e8ffff39", "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/8ed08766d9a2ed979a2f5fdbb95a0671523419c1",
"reference": "a7a29e8d3113806f18f99d670f580a30e8ffff39", "reference": "8ed08766d9a2ed979a2f5fdbb95a0671523419c1",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -746,14 +746,14 @@
"phar-io/manifest": "^2.0.4", "phar-io/manifest": "^2.0.4",
"phar-io/version": "^3.2.1", "phar-io/version": "^3.2.1",
"php": ">=8.2", "php": ">=8.2",
"phpunit/php-code-coverage": "^11.0.5", "phpunit/php-code-coverage": "^11.0.6",
"phpunit/php-file-iterator": "^5.0.1", "phpunit/php-file-iterator": "^5.1.0",
"phpunit/php-invoker": "^5.0.1", "phpunit/php-invoker": "^5.0.1",
"phpunit/php-text-template": "^4.0.1", "phpunit/php-text-template": "^4.0.1",
"phpunit/php-timer": "^7.0.1", "phpunit/php-timer": "^7.0.1",
"sebastian/cli-parser": "^3.0.2", "sebastian/cli-parser": "^3.0.2",
"sebastian/code-unit": "^3.0.1", "sebastian/code-unit": "^3.0.1",
"sebastian/comparator": "^6.0.1", "sebastian/comparator": "^6.0.2",
"sebastian/diff": "^6.0.2", "sebastian/diff": "^6.0.2",
"sebastian/environment": "^7.2.0", "sebastian/environment": "^7.2.0",
"sebastian/exporter": "^6.1.3", "sebastian/exporter": "^6.1.3",
@ -771,7 +771,7 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-main": "11.2-dev" "dev-main": "11.3-dev"
} }
}, },
"autoload": { "autoload": {
@ -803,7 +803,7 @@
"support": { "support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues", "issues": "https://github.com/sebastianbergmann/phpunit/issues",
"security": "https://github.com/sebastianbergmann/phpunit/security/policy", "security": "https://github.com/sebastianbergmann/phpunit/security/policy",
"source": "https://github.com/sebastianbergmann/phpunit/tree/11.2.8" "source": "https://github.com/sebastianbergmann/phpunit/tree/11.3.3"
}, },
"funding": [ "funding": [
{ {
@ -819,7 +819,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2024-07-18T14:56:37+00:00" "time": "2024-09-04T13:34:52+00:00"
}, },
{ {
"name": "sebastian/cli-parser", "name": "sebastian/cli-parser",
@ -993,16 +993,16 @@
}, },
{ {
"name": "sebastian/comparator", "name": "sebastian/comparator",
"version": "6.0.1", "version": "6.0.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/comparator.git", "url": "https://github.com/sebastianbergmann/comparator.git",
"reference": "131942b86d3587291067a94f295498ab6ac79c20" "reference": "450d8f237bd611c45b5acf0733ce43e6bb280f81"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/131942b86d3587291067a94f295498ab6ac79c20", "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/450d8f237bd611c45b5acf0733ce43e6bb280f81",
"reference": "131942b86d3587291067a94f295498ab6ac79c20", "reference": "450d8f237bd611c45b5acf0733ce43e6bb280f81",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1058,7 +1058,7 @@
"support": { "support": {
"issues": "https://github.com/sebastianbergmann/comparator/issues", "issues": "https://github.com/sebastianbergmann/comparator/issues",
"security": "https://github.com/sebastianbergmann/comparator/security/policy", "security": "https://github.com/sebastianbergmann/comparator/security/policy",
"source": "https://github.com/sebastianbergmann/comparator/tree/6.0.1" "source": "https://github.com/sebastianbergmann/comparator/tree/6.0.2"
}, },
"funding": [ "funding": [
{ {
@ -1066,7 +1066,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2024-07-03T04:48:07+00:00" "time": "2024-08-12T06:07:25+00:00"
}, },
{ {
"name": "sebastian/complexity", "name": "sebastian/complexity",

View File

@ -27,7 +27,7 @@ class Field
* @param string $paramName The name of the parameter to which this should be bound * @param string $paramName The name of the parameter to which this should be bound
* @param string $qualifier A table qualifier for the `data` column * @param string $qualifier A table qualifier for the `data` column
*/ */
public function __construct(public string $fieldName = '', public Op $op = Op::EQ, public mixed $value = '', public function __construct(public string $fieldName = '', public Op $op = Op::Equal, public mixed $value = '',
public string $paramName = '', public string $qualifier = '') { } public string $paramName = '', public string $qualifier = '') { }
/** /**
@ -39,10 +39,10 @@ class Field
public function appendParameter(array $existing): array public function appendParameter(array $existing): array
{ {
switch ($this->op) { switch ($this->op) {
case Op::EX: case Op::Exists:
case Op::NEX: case Op::NotExists:
break; break;
case Op::BT: case Op::Between:
$existing["{$this->paramName}min"] = $this->value[0]; $existing["{$this->paramName}min"] = $this->value[0];
$existing["{$this->paramName}max"] = $this->value[1]; $existing["{$this->paramName}max"] = $this->value[1];
break; break;
@ -68,15 +68,16 @@ class Field
}; };
$fieldPath = match ($mode) { $fieldPath = match ($mode) {
Mode::PgSQL => match (true) { Mode::PgSQL => match (true) {
$this->op === Op::BT => is_numeric($this->value[0]) ? "($fieldName)::numeric" : $fieldName, $this->op === Op::Between => is_numeric($this->value[0]) ? "($fieldName)::numeric" : $fieldName,
is_numeric($this->value) => "($fieldName)::numeric", is_numeric($this->value) => "($fieldName)::numeric",
default => $fieldName, default => $fieldName,
}, },
default => $fieldName, default => $fieldName,
}; };
$criteria = match ($this->op) { $criteria = match ($this->op) {
Op::EX, Op::NEX => '', Op::Exists, Op::NotExists => '',
Op::BT => " {$this->paramName}min AND {$this->paramName}max", Op::Between => " {$this->paramName}min AND {$this->paramName}max",
Op::In => "TODO",
default => " $this->paramName", default => " $this->paramName",
}; };
return $fieldPath . ' ' . $this->op->toSQL() . $criteria; return $fieldPath . ' ' . $this->op->toSQL() . $criteria;
@ -90,9 +91,22 @@ class Field
* @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank) * @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank)
* @return self The field with the requested criterion * @return self The field with the requested criterion
*/ */
public static function equal(string $fieldName, mixed $value, string $paramName = ''): self
{
return new self($fieldName, Op::Equal, $value, $paramName);
}
/**
* Create an equals (=) field criterion _(alias for `Field.equal`)_
*
* @param string $fieldName The name of the field against which the value will be compared
* @param mixed $value The value for which equality will be checked
* @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank)
* @return self The field with the requested criterion
*/
public static function EQ(string $fieldName, mixed $value, string $paramName = ''): self public static function EQ(string $fieldName, mixed $value, string $paramName = ''): self
{ {
return new self($fieldName, Op::EQ, $value, $paramName); return self::equal($fieldName, $value, $paramName);
} }
/** /**
@ -103,9 +117,22 @@ class Field
* @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank) * @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank)
* @return self The field with the requested criterion * @return self The field with the requested criterion
*/ */
public static function greater(string $fieldName, mixed $value, string $paramName = ''): self
{
return new self($fieldName, Op::Greater, $value, $paramName);
}
/**
* Create a greater than (>) field criterion _(alias for `Field.greater`)_
*
* @param string $fieldName The name of the field against which the value will be compared
* @param mixed $value The value for the greater than comparison
* @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank)
* @return self The field with the requested criterion
*/
public static function GT(string $fieldName, mixed $value, string $paramName = ''): self public static function GT(string $fieldName, mixed $value, string $paramName = ''): self
{ {
return new self($fieldName, Op::GT, $value, $paramName); return self::greater($fieldName, $value, $paramName);
} }
/** /**
@ -116,9 +143,22 @@ class Field
* @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank) * @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank)
* @return self The field with the requested criterion * @return self The field with the requested criterion
*/ */
public static function greaterOrEqual(string $fieldName, mixed $value, string $paramName = ''): self
{
return new self($fieldName, Op::GreaterOrEqual, $value, $paramName);
}
/**
* Create a greater than or equal to (>=) field criterion _(alias for `Field.greaterOrEqual`)_
*
* @param string $fieldName The name of the field against which the value will be compared
* @param mixed $value The value for the greater than or equal to comparison
* @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank)
* @return self The field with the requested criterion
*/
public static function GE(string $fieldName, mixed $value, string $paramName = ''): self public static function GE(string $fieldName, mixed $value, string $paramName = ''): self
{ {
return new self($fieldName, Op::GE, $value, $paramName); return self::greaterOrEqual($fieldName, $value, $paramName);
} }
/** /**
@ -129,9 +169,22 @@ class Field
* @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank) * @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank)
* @return self The field with the requested criterion * @return self The field with the requested criterion
*/ */
public static function less(string $fieldName, mixed $value, string $paramName = ''): self
{
return new self($fieldName, Op::Less, $value, $paramName);
}
/**
* Create a less than (<) field criterion _(alias for `Field.less`)_
*
* @param string $fieldName The name of the field against which the value will be compared
* @param mixed $value The value for the less than comparison
* @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank)
* @return self The field with the requested criterion
*/
public static function LT(string $fieldName, mixed $value, string $paramName = ''): self public static function LT(string $fieldName, mixed $value, string $paramName = ''): self
{ {
return new self($fieldName, Op::LT, $value, $paramName); return self::less($fieldName, $value, $paramName);
} }
/** /**
@ -142,9 +195,22 @@ class Field
* @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank) * @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank)
* @return self The field with the requested criterion * @return self The field with the requested criterion
*/ */
public static function lessOrEqual(string $fieldName, mixed $value, string $paramName = ''): self
{
return new self($fieldName, Op::LessOrEqual, $value, $paramName);
}
/**
* Create a less than or equal to (<=) field criterion _(alias for `Field.lessOrEqual`)_
*
* @param string $fieldName The name of the field against which the value will be compared
* @param mixed $value The value for the less than or equal to comparison
* @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank)
* @return self The field with the requested criterion
*/
public static function LE(string $fieldName, mixed $value, string $paramName = ''): self public static function LE(string $fieldName, mixed $value, string $paramName = ''): self
{ {
return new self($fieldName, Op::LE, $value, $paramName); return self::lessOrEqual($fieldName, $value, $paramName);
} }
/** /**
@ -155,9 +221,22 @@ class Field
* @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank) * @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank)
* @return self The field with the requested criterion * @return self The field with the requested criterion
*/ */
public static function notEqual(string $fieldName, mixed $value, string $paramName = ''): self
{
return new self($fieldName, Op::NotEqual, $value, $paramName);
}
/**
* Create a not equals (<>) field criterion _(alias for `Field.notEqual`)_
*
* @param string $fieldName The name of the field against which the value will be compared
* @param mixed $value The value for the not equals comparison
* @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank)
* @return self The field with the requested criterion
*/
public static function NE(string $fieldName, mixed $value, string $paramName = ''): self public static function NE(string $fieldName, mixed $value, string $paramName = ''): self
{ {
return new self($fieldName, Op::NE, $value, $paramName); return self::notEqual($fieldName, $value, $paramName);
} }
/** /**
@ -169,9 +248,49 @@ class Field
* @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank) * @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank)
* @return self The field with the requested criterion * @return self The field with the requested criterion
*/ */
public static function between(string $fieldName, mixed $minValue, mixed $maxValue, string $paramName = ''): self
{
return new self($fieldName, Op::Between, [$minValue, $maxValue], $paramName);
}
/**
* Create a BETWEEN field criterion _(alias for `Field.between`)_
*
* @param string $fieldName The name of the field against which the value will be compared
* @param mixed $minValue The lower value for range
* @param mixed $maxValue The upper value for the range
* @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank)
* @return self The field with the requested criterion
*/
public static function BT(string $fieldName, mixed $minValue, mixed $maxValue, string $paramName = ''): self public static function BT(string $fieldName, mixed $minValue, mixed $maxValue, string $paramName = ''): self
{ {
return new self($fieldName, Op::BT, [$minValue, $maxValue], $paramName); return self::between($fieldName, $minValue, $maxValue, $paramName);
}
/**
* Create an IN field criterion
*
* @param string $fieldName The name of the field against which the values will be compared
* @param mixed[] $values The potential matching values for the field
* @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank)
* @return self The field with the requested criterion
*/
public static function in(string $fieldName, array $values, string $paramName = ''): self
{
return new self($fieldName, Op::In, $values, $paramName);
}
/**
* Create an IN ARRAY field criterion
*
* @param string $fieldName The name of the field against which the values will be compared
* @param mixed[] $values The potential matching values for the field
* @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank)
* @return self The field with the requested criterion
*/
public static function inArray(string $fieldName, array $values, string $paramName = ''): self
{
return new self($fieldName, Op::InArray, $values, $paramName);
} }
/** /**
@ -180,9 +299,20 @@ class Field
* @param string $fieldName The name of the field for which existence will be checked * @param string $fieldName The name of the field for which existence will be checked
* @return self The field with the requested criterion * @return self The field with the requested criterion
*/ */
public static function exists(string $fieldName): self
{
return new self($fieldName, Op::Exists, '', '');
}
/**
* Create an exists (IS NOT NULL) field criterion _(alias for `Field.exists`)_
*
* @param string $fieldName The name of the field for which existence will be checked
* @return self The field with the requested criterion
*/
public static function EX(string $fieldName): self public static function EX(string $fieldName): self
{ {
return new self($fieldName, Op::EX, '', ''); return self::exists($fieldName);
} }
/** /**
@ -191,8 +321,19 @@ class Field
* @param string $fieldName The name of the field for which non-existence will be checked * @param string $fieldName The name of the field for which non-existence will be checked
* @return self The field with the requested criterion * @return self The field with the requested criterion
*/ */
public static function notExists(string $fieldName): self
{
return new self($fieldName, Op::NotExists, '', '');
}
/**
* Create a not exists (IS NULL) field criterion _(alias for `Field.notExists`)_
*
* @param string $fieldName The name of the field for which non-existence will be checked
* @return self The field with the requested criterion
*/
public static function NEX(string $fieldName): self public static function NEX(string $fieldName): self
{ {
return new self($fieldName, Op::NEX, '', ''); return self::notExists($fieldName);
} }
} }

View File

@ -9,28 +9,32 @@ declare(strict_types=1);
namespace BitBadger\PDODocument; namespace BitBadger\PDODocument;
/** /**
* The types of logical operations allowed for JSON fields * The types of comparison operators allowed for JSON fields
*/ */
enum Op enum Op
{ {
/** Equals (=) */ /** Equals (=) */
case EQ; case Equal;
/** Greater Than (>) */ /** Greater Than (>) */
case GT; case Greater;
/** Greater Than or Equal To (>=) */ /** Greater Than or Equal To (>=) */
case GE; case GreaterOrEqual;
/** Less Than (<) */ /** Less Than (<) */
case LT; case Less;
/** Less Than or Equal To (<=) */ /** Less Than or Equal To (<=) */
case LE; case LessOrEqual;
/** Not Equal to (<>) */ /** Not Equal to (<>) */
case NE; case NotEqual;
/** Between (BETWEEN) */ /** Between (BETWEEN) */
case BT; case Between;
/** In (IN) */
case In;
/** In Array (PostgreSQL - ?|, SQLite - EXISTS / json_each / IN) */
case InArray;
/** Exists (IS NOT NULL) */ /** Exists (IS NOT NULL) */
case EX; case Exists;
/** Does Not Exist (IS NULL) */ /** Does Not Exist (IS NULL) */
case NEX; case NotExists;
/** /**
* Get the SQL representation of this operator * Get the SQL representation of this operator
@ -40,15 +44,17 @@ enum Op
public function toSQL(): string public function toSQL(): string
{ {
return match ($this) { return match ($this) {
Op::EQ => "=", Op::Equal => "=",
Op::GT => ">", Op::Greater => ">",
Op::GE => ">=", Op::GreaterOrEqual => ">=",
Op::LT => "<", Op::Less => "<",
Op::LE => "<=", Op::LessOrEqual => "<=",
Op::NE => "<>", Op::NotEqual => "<>",
Op::BT => "BETWEEN", Op::Between => "BETWEEN",
Op::EX => "IS NOT NULL", Op::In => "IN",
Op::NEX => "IS NULL", Op::InArray => "?|",
Op::Exists => "IS NOT NULL",
Op::NotExists => "IS NULL",
}; };
} }
} }

View File

@ -51,7 +51,7 @@ class Query
*/ */
public static function whereById(string $paramName = ':id', mixed $docId = null): string public static function whereById(string $paramName = ':id', mixed $docId = null): string
{ {
return self::whereByFields([Field::EQ(Configuration::$idField, $docId ?? '', $paramName)]); return self::whereByFields([Field::equal(Configuration::$idField, $docId ?? '', $paramName)]);
} }
/** /**

View File

@ -41,13 +41,13 @@ class CountTest extends TestCase
public function testByFieldsSucceedsForANumericRange(): void public function testByFieldsSucceedsForANumericRange(): void
{ {
$count = Count::byFields(ThrowawayDb::TABLE, [Field::BT('num_value', 10, 20)]); $count = Count::byFields(ThrowawayDb::TABLE, [Field::between('num_value', 10, 20)]);
$this->assertEquals(3, $count, 'There should have been 3 matching documents'); $this->assertEquals(3, $count, 'There should have been 3 matching documents');
} }
public function testByFieldsSucceedsForANonNumericRange(): void public function testByFieldsSucceedsForANonNumericRange(): void
{ {
$count = Count::byFields(ThrowawayDb::TABLE, [Field::BT('value', 'aardvark', 'apple')]); $count = Count::byFields(ThrowawayDb::TABLE, [Field::between('value', 'aardvark', 'apple')]);
$this->assertEquals(1, $count, 'There should have been 1 matching document'); $this->assertEquals(1, $count, 'There should have been 1 matching document');
} }

View File

@ -52,14 +52,14 @@ class DeleteTest extends TestCase
public function testByFieldsSucceedsWhenDocumentsAreDeleted(): void public function testByFieldsSucceedsWhenDocumentsAreDeleted(): void
{ {
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start'); $this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
Delete::byFields(ThrowawayDb::TABLE, [Field::NE('value', 'purple')]); Delete::byFields(ThrowawayDb::TABLE, [Field::notEqual('value', 'purple')]);
$this->assertEquals(2, Count::all(ThrowawayDb::TABLE), 'There should have been 2 documents remaining'); $this->assertEquals(2, Count::all(ThrowawayDb::TABLE), 'There should have been 2 documents remaining');
} }
public function testByFieldsSucceedsWhenDocumentsAreNotDeleted(): void public function testByFieldsSucceedsWhenDocumentsAreNotDeleted(): void
{ {
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start'); $this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
Delete::byFields(ThrowawayDb::TABLE, [Field::EQ('value', 'crimson')]); Delete::byFields(ThrowawayDb::TABLE, [Field::equal('value', 'crimson')]);
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents remaining'); $this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents remaining');
} }

View File

@ -97,7 +97,7 @@ class DocumentTest extends TestCase
try { try {
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
Document::insert(ThrowawayDb::TABLE, ['id' => '', 'num_value' => 5]); Document::insert(ThrowawayDb::TABLE, ['id' => '', 'num_value' => 5]);
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 5)], TestDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 5)], TestDocument::class);
$this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertTrue($doc->isSome(), 'There should have been a document returned');
$this->assertNotEmpty($doc->get()->id, 'The ID should have been auto-generated'); $this->assertNotEmpty($doc->get()->id, 'The ID should have been auto-generated');
} finally { } finally {
@ -113,7 +113,7 @@ class DocumentTest extends TestCase
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
$uuid = AutoId::generateUUID(); $uuid = AutoId::generateUUID();
Document::insert(ThrowawayDb::TABLE, ['id' => $uuid, 'value' => 'uuid', 'num_value' => 12]); Document::insert(ThrowawayDb::TABLE, ['id' => $uuid, 'value' => 'uuid', 'num_value' => 12]);
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 12)], TestDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 12)], TestDocument::class);
$this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertTrue($doc->isSome(), 'There should have been a document returned');
$this->assertEquals($uuid, $doc->get()->id, 'The ID should not have been changed'); $this->assertEquals($uuid, $doc->get()->id, 'The ID should not have been changed');
} finally { } finally {
@ -129,7 +129,7 @@ class DocumentTest extends TestCase
try { try {
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
Document::insert(ThrowawayDb::TABLE, ['id' => '', 'value' => 'new', 'num_value' => 8]); Document::insert(ThrowawayDb::TABLE, ['id' => '', 'value' => 'new', 'num_value' => 8]);
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 8)], TestDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 8)], TestDocument::class);
$this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertTrue($doc->isSome(), 'There should have been a document returned');
$this->assertEquals(6, strlen($doc->get()->id), $this->assertEquals(6, strlen($doc->get()->id),
'The ID should have been auto-generated and had 6 characters'); 'The ID should have been auto-generated and had 6 characters');
@ -146,7 +146,7 @@ class DocumentTest extends TestCase
try { try {
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
Document::insert(ThrowawayDb::TABLE, ['id' => 'my-key', 'value' => 'old', 'num_value' => 3]); Document::insert(ThrowawayDb::TABLE, ['id' => 'my-key', 'value' => 'old', 'num_value' => 3]);
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 3)], TestDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 3)], TestDocument::class);
$this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertTrue($doc->isSome(), 'There should have been a document returned');
$this->assertEquals('my-key', $doc->get()->id, 'The ID should not have been changed'); $this->assertEquals('my-key', $doc->get()->id, 'The ID should not have been changed');
} finally { } finally {
@ -177,12 +177,12 @@ class DocumentTest extends TestCase
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
Document::insert(ThrowawayDb::TABLE, new NumDocument(value: 'taco')); Document::insert(ThrowawayDb::TABLE, new NumDocument(value: 'taco'));
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'taco')], NumDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'taco')], NumDocument::class);
$this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertTrue($doc->isSome(), 'There should have been a document returned');
$this->assertEquals(1, $doc->get()->id, 'The ID 1 should have been auto-generated'); $this->assertEquals(1, $doc->get()->id, 'The ID 1 should have been auto-generated');
Document::insert(ThrowawayDb::TABLE, new NumDocument(value: 'burrito')); Document::insert(ThrowawayDb::TABLE, new NumDocument(value: 'burrito'));
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'burrito')], NumDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'burrito')], NumDocument::class);
$this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertTrue($doc->isSome(), 'There should have been a document returned');
$this->assertEquals(2, $doc->get()->id, 'The ID 2 should have been auto-generated'); $this->assertEquals(2, $doc->get()->id, 'The ID 2 should have been auto-generated');
} finally { } finally {
@ -197,7 +197,7 @@ class DocumentTest extends TestCase
try { try {
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
Document::insert(ThrowawayDb::TABLE, new NumDocument(64, 'large')); Document::insert(ThrowawayDb::TABLE, new NumDocument(64, 'large'));
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'large')], NumDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'large')], NumDocument::class);
$this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertTrue($doc->isSome(), 'There should have been a document returned');
$this->assertEquals(64, $doc->get()->id, 'The ID 64 should have been stored'); $this->assertEquals(64, $doc->get()->id, 'The ID 64 should have been stored');
} finally { } finally {
@ -212,7 +212,7 @@ class DocumentTest extends TestCase
try { try {
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
Document::insert(ThrowawayDb::TABLE, new TestDocument(value: 'something', num_value: 9)); Document::insert(ThrowawayDb::TABLE, new TestDocument(value: 'something', num_value: 9));
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EX('value')], TestDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::exists('value')], TestDocument::class);
$this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertTrue($doc->isSome(), 'There should have been a document returned');
$this->assertNotEmpty($doc->get()->id, 'The ID should have been auto-generated'); $this->assertNotEmpty($doc->get()->id, 'The ID should have been auto-generated');
} finally { } finally {
@ -228,7 +228,7 @@ class DocumentTest extends TestCase
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
$uuid = AutoId::generateUUID(); $uuid = AutoId::generateUUID();
Document::insert(ThrowawayDb::TABLE, new TestDocument($uuid, num_value: 14)); Document::insert(ThrowawayDb::TABLE, new TestDocument($uuid, num_value: 14));
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 14)], TestDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 14)], TestDocument::class);
$this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertTrue($doc->isSome(), 'There should have been a document returned');
$this->assertEquals($uuid, $doc->get()->id, 'The ID should not have been changed'); $this->assertEquals($uuid, $doc->get()->id, 'The ID should not have been changed');
} finally { } finally {
@ -244,7 +244,7 @@ class DocumentTest extends TestCase
try { try {
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
Document::insert(ThrowawayDb::TABLE, new TestDocument(num_value: 55)); Document::insert(ThrowawayDb::TABLE, new TestDocument(num_value: 55));
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 55)], TestDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 55)], TestDocument::class);
$this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertTrue($doc->isSome(), 'There should have been a document returned');
$this->assertEquals(40, strlen($doc->get()->id), $this->assertEquals(40, strlen($doc->get()->id),
'The ID should have been auto-generated and had 40 characters'); 'The ID should have been auto-generated and had 40 characters');
@ -261,7 +261,7 @@ class DocumentTest extends TestCase
try { try {
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
Document::insert(ThrowawayDb::TABLE, new TestDocument('my-key', num_value: 3)); Document::insert(ThrowawayDb::TABLE, new TestDocument('my-key', num_value: 3));
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 3)], TestDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 3)], TestDocument::class);
$this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertTrue($doc->isSome(), 'There should have been a document returned');
$this->assertEquals('my-key', $doc->get()->id, 'The ID should not have been changed'); $this->assertEquals('my-key', $doc->get()->id, 'The ID should not have been changed');
} finally { } finally {

View File

@ -48,13 +48,13 @@ class ExistsTest extends TestCase
public function testByFieldsSucceedsWhenDocumentsExist(): void public function testByFieldsSucceedsWhenDocumentsExist(): void
{ {
$this->assertTrue(Exists::byFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 10)]), $this->assertTrue(Exists::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 10)]),
'There should have been existing documents'); 'There should have been existing documents');
} }
public function testByFieldsSucceedsWhenNoMatchingDocumentsExist(): void public function testByFieldsSucceedsWhenNoMatchingDocumentsExist(): void
{ {
$this->assertFalse(Exists::byFields(ThrowawayDb::TABLE, [Field::LT('nothing', 'none')]), $this->assertFalse(Exists::byFields(ThrowawayDb::TABLE, [Field::less('nothing', 'none')]),
'There should not have been any existing documents'); 'There should not have been any existing documents');
} }

View File

@ -62,7 +62,7 @@ class FindTest extends TestCase
#[TestDox('By ID succeeds when a document is found with numeric ID')] #[TestDox('By ID succeeds when a document is found with numeric ID')]
public function testByIdSucceedsWhenADocumentIsFoundWithNumericId(): void public function testByIdSucceedsWhenADocumentIsFoundWithNumericId(): void
{ {
Delete::byFields(ThrowawayDb::TABLE, [Field::NEX('absent')]); Delete::byFields(ThrowawayDb::TABLE, [Field::notExists('absent')]);
Document::insert(ThrowawayDb::TABLE, ['id' => 18, 'value' => 'howdy']); Document::insert(ThrowawayDb::TABLE, ['id' => 18, 'value' => 'howdy']);
$doc = Find::byId(ThrowawayDb::TABLE, 18, NumDocument::class); $doc = Find::byId(ThrowawayDb::TABLE, 18, NumDocument::class);
$this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertTrue($doc->isSome(), 'There should have been a document returned');
@ -78,7 +78,7 @@ class FindTest extends TestCase
public function testByFieldsSucceedsWhenDocumentsAreFound(): void public function testByFieldsSucceedsWhenDocumentsAreFound(): void
{ {
$docs = Find::byFields(ThrowawayDb::TABLE, [Field::GT('num_value', 15)], TestDocument::class); $docs = Find::byFields(ThrowawayDb::TABLE, [Field::greater('num_value', 15)], TestDocument::class);
$this->assertNotNull($docs, 'There should have been a document list returned'); $this->assertNotNull($docs, 'There should have been a document list returned');
$count = 0; $count = 0;
foreach ($docs->items() as $ignored) $count++; foreach ($docs->items() as $ignored) $count++;
@ -87,7 +87,7 @@ class FindTest extends TestCase
public function testByFieldsSucceedsWhenNoDocumentsAreFound(): void public function testByFieldsSucceedsWhenNoDocumentsAreFound(): void
{ {
$docs = Find::byFields(ThrowawayDb::TABLE, [Field::GT('num_value', 100)], TestDocument::class); $docs = Find::byFields(ThrowawayDb::TABLE, [Field::greater('num_value', 100)], TestDocument::class);
$this->assertNotNull($docs, 'There should have been a document list returned'); $this->assertNotNull($docs, 'There should have been a document list returned');
$this->assertFalse($docs->hasItems(), 'There should have been no documents in the list'); $this->assertFalse($docs->hasItems(), 'There should have been no documents in the list');
} }
@ -128,21 +128,21 @@ class FindTest extends TestCase
public function testFirstByFieldsSucceedsWhenADocumentIsFound(): void public function testFirstByFieldsSucceedsWhenADocumentIsFound(): void
{ {
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'another')], TestDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'another')], TestDocument::class);
$this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertTrue($doc->isSome(), 'There should have been a document returned');
$this->assertEquals('two', $doc->get()->id, 'The incorrect document was returned'); $this->assertEquals('two', $doc->get()->id, 'The incorrect document was returned');
} }
public function testFirstByFieldsSucceedsWhenMultipleDocumentsAreFound(): void public function testFirstByFieldsSucceedsWhenMultipleDocumentsAreFound(): void
{ {
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('sub.foo', 'green')], TestDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('sub.foo', 'green')], TestDocument::class);
$this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertTrue($doc->isSome(), 'There should have been a document returned');
$this->assertContains($doc->get()->id, ['two', 'four'], 'An incorrect document was returned'); $this->assertContains($doc->get()->id, ['two', 'four'], 'An incorrect document was returned');
} }
public function testFirstByFieldsSucceedsWhenADocumentIsNotFound(): void public function testFirstByFieldsSucceedsWhenADocumentIsNotFound(): void
{ {
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'absent')], TestDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'absent')], TestDocument::class);
$this->assertTrue($doc->isNone(), 'There should not have been a document returned'); $this->assertTrue($doc->isNone(), 'There should not have been a document returned');
} }

View File

@ -54,14 +54,14 @@ class PatchTest extends TestCase
public function testByFieldsSucceedsWhenADocumentIsUpdated(): void public function testByFieldsSucceedsWhenADocumentIsUpdated(): void
{ {
Patch::byFields(ThrowawayDb::TABLE, [Field::EQ('value', 'purple')], ['num_value' => 77]); Patch::byFields(ThrowawayDb::TABLE, [Field::equal('value', 'purple')], ['num_value' => 77]);
$after = Count::byFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 77)]); $after = Count::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 77)]);
$this->assertEquals(2, $after, 'There should have been 2 documents updated'); $this->assertEquals(2, $after, 'There should have been 2 documents updated');
} }
public function testByFieldsSucceedsWhenNoDocumentIsUpdated(): void public function testByFieldsSucceedsWhenNoDocumentIsUpdated(): void
{ {
$fields = [Field::EQ('value', 'burgundy')]; $fields = [Field::equal('value', 'burgundy')];
$this->assertEquals(0, Count::byFields(ThrowawayDb::TABLE, $fields), 'There should be no matching documents'); $this->assertEquals(0, Count::byFields(ThrowawayDb::TABLE, $fields), 'There should be no matching documents');
Patch::byFields(ThrowawayDb::TABLE, $fields, ['foo' => 'green']); Patch::byFields(ThrowawayDb::TABLE, $fields, ['foo' => 'green']);
$this->assertTrue(true, 'The above not throwing an exception is the test'); $this->assertTrue(true, 'The above not throwing an exception is the test');

View File

@ -61,21 +61,21 @@ class RemoveFieldsTest extends TestCase
public function testByFieldsSucceedsWhenAFieldIsRemoved(): void public function testByFieldsSucceedsWhenAFieldIsRemoved(): void
{ {
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 17)], ['sub']); RemoveFields::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 17)], ['sub']);
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 17)], TestDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 17)], TestDocument::class);
$this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertTrue($doc->isSome(), 'There should have been a document returned');
$this->assertNull($doc->get()->sub, 'Sub-document should have been null'); $this->assertNull($doc->get()->sub, 'Sub-document should have been null');
} }
public function testByFieldsSucceedsWhenAFieldIsNotRemoved(): void public function testByFieldsSucceedsWhenAFieldIsNotRemoved(): void
{ {
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 17)], ['nada']); RemoveFields::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 17)], ['nada']);
$this->assertTrue(true, 'The above not throwing an exception is the test'); $this->assertTrue(true, 'The above not throwing an exception is the test');
} }
public function testByFieldsSucceedsWhenNoDocumentIsMatched(): void public function testByFieldsSucceedsWhenNoDocumentIsMatched(): void
{ {
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::NE('missing', 'nope')], ['value']); RemoveFields::byFields(ThrowawayDb::TABLE, [Field::notEqual('missing', 'nope')], ['value']);
$this->assertTrue(true, 'The above not throwing an exception is the test'); $this->assertTrue(true, 'The above not throwing an exception is the test');
} }

View File

@ -41,13 +41,13 @@ class CountTest extends TestCase
public function testByFieldsSucceedsForANumericRange(): void public function testByFieldsSucceedsForANumericRange(): void
{ {
$count = Count::byFields(ThrowawayDb::TABLE, [Field::BT('num_value', 10, 20)]); $count = Count::byFields(ThrowawayDb::TABLE, [Field::between('num_value', 10, 20)]);
$this->assertEquals(3, $count, 'There should have been 3 matching documents'); $this->assertEquals(3, $count, 'There should have been 3 matching documents');
} }
public function testByFieldsSucceedsForANonNumericRange(): void public function testByFieldsSucceedsForANonNumericRange(): void
{ {
$count = Count::byFields(ThrowawayDb::TABLE, [Field::BT('value', 'aardvark', 'apple')]); $count = Count::byFields(ThrowawayDb::TABLE, [Field::between('value', 'aardvark', 'apple')]);
$this->assertEquals(1, $count, 'There should have been 1 matching document'); $this->assertEquals(1, $count, 'There should have been 1 matching document');
} }

View File

@ -52,14 +52,14 @@ class DeleteTest extends TestCase
public function testByFieldsSucceedsWhenDocumentsAreDeleted(): void public function testByFieldsSucceedsWhenDocumentsAreDeleted(): void
{ {
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start'); $this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
Delete::byFields(ThrowawayDb::TABLE, [Field::NE('value', 'purple')]); Delete::byFields(ThrowawayDb::TABLE, [Field::notEqual('value', 'purple')]);
$this->assertEquals(2, Count::all(ThrowawayDb::TABLE), 'There should have been 2 documents remaining'); $this->assertEquals(2, Count::all(ThrowawayDb::TABLE), 'There should have been 2 documents remaining');
} }
public function testByFieldsSucceedsWhenDocumentsAreNotDeleted(): void public function testByFieldsSucceedsWhenDocumentsAreNotDeleted(): void
{ {
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start'); $this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
Delete::byFields(ThrowawayDb::TABLE, [Field::EQ('value', 'crimson')]); Delete::byFields(ThrowawayDb::TABLE, [Field::equal('value', 'crimson')]);
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents remaining'); $this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents remaining');
} }

View File

@ -97,7 +97,7 @@ class DocumentTest extends TestCase
try { try {
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
Document::insert(ThrowawayDb::TABLE, ['id' => '', 'num_value' => 5]); Document::insert(ThrowawayDb::TABLE, ['id' => '', 'num_value' => 5]);
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 5)], TestDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 5)], TestDocument::class);
$this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertTrue($doc->isSome(), 'There should have been a document returned');
$this->assertNotEmpty($doc->get()->id, 'The ID should have been auto-generated'); $this->assertNotEmpty($doc->get()->id, 'The ID should have been auto-generated');
} finally { } finally {
@ -113,7 +113,7 @@ class DocumentTest extends TestCase
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
$uuid = AutoId::generateUUID(); $uuid = AutoId::generateUUID();
Document::insert(ThrowawayDb::TABLE, ['id' => $uuid, 'value' => 'uuid', 'num_value' => 12]); Document::insert(ThrowawayDb::TABLE, ['id' => $uuid, 'value' => 'uuid', 'num_value' => 12]);
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 12)], TestDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 12)], TestDocument::class);
$this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertTrue($doc->isSome(), 'There should have been a document returned');
$this->assertEquals($uuid, $doc->get()->id, 'The ID should not have been changed'); $this->assertEquals($uuid, $doc->get()->id, 'The ID should not have been changed');
} finally { } finally {
@ -129,7 +129,7 @@ class DocumentTest extends TestCase
try { try {
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
Document::insert(ThrowawayDb::TABLE, ['id' => '', 'value' => 'new', 'num_value' => 8]); Document::insert(ThrowawayDb::TABLE, ['id' => '', 'value' => 'new', 'num_value' => 8]);
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 8)], TestDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 8)], TestDocument::class);
$this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertTrue($doc->isSome(), 'There should have been a document returned');
$this->assertEquals(6, strlen($doc->get()->id), $this->assertEquals(6, strlen($doc->get()->id),
'The ID should have been auto-generated and had 6 characters'); 'The ID should have been auto-generated and had 6 characters');
@ -146,7 +146,7 @@ class DocumentTest extends TestCase
try { try {
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
Document::insert(ThrowawayDb::TABLE, ['id' => 'my-key', 'value' => 'old', 'num_value' => 3]); Document::insert(ThrowawayDb::TABLE, ['id' => 'my-key', 'value' => 'old', 'num_value' => 3]);
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 3)], TestDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 3)], TestDocument::class);
$this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertTrue($doc->isSome(), 'There should have been a document returned');
$this->assertEquals('my-key', $doc->get()->id, 'The ID should not have been changed'); $this->assertEquals('my-key', $doc->get()->id, 'The ID should not have been changed');
} finally { } finally {
@ -177,12 +177,12 @@ class DocumentTest extends TestCase
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
Document::insert(ThrowawayDb::TABLE, new NumDocument(value: 'taco')); Document::insert(ThrowawayDb::TABLE, new NumDocument(value: 'taco'));
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'taco')], NumDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'taco')], NumDocument::class);
$this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertTrue($doc->isSome(), 'There should have been a document returned');
$this->assertEquals(1, $doc->get()->id, 'The ID 1 should have been auto-generated'); $this->assertEquals(1, $doc->get()->id, 'The ID 1 should have been auto-generated');
Document::insert(ThrowawayDb::TABLE, new NumDocument(value: 'burrito')); Document::insert(ThrowawayDb::TABLE, new NumDocument(value: 'burrito'));
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'burrito')], NumDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'burrito')], NumDocument::class);
$this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertTrue($doc->isSome(), 'There should have been a document returned');
$this->assertEquals(2, $doc->get()->id, 'The ID 2 should have been auto-generated'); $this->assertEquals(2, $doc->get()->id, 'The ID 2 should have been auto-generated');
} finally { } finally {
@ -197,7 +197,7 @@ class DocumentTest extends TestCase
try { try {
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
Document::insert(ThrowawayDb::TABLE, new NumDocument(64, 'large')); Document::insert(ThrowawayDb::TABLE, new NumDocument(64, 'large'));
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'large')], NumDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'large')], NumDocument::class);
$this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertTrue($doc->isSome(), 'There should have been a document returned');
$this->assertEquals(64, $doc->get()->id, 'The ID 64 should have been stored'); $this->assertEquals(64, $doc->get()->id, 'The ID 64 should have been stored');
} finally { } finally {
@ -212,7 +212,7 @@ class DocumentTest extends TestCase
try { try {
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
Document::insert(ThrowawayDb::TABLE, new TestDocument(value: 'something', num_value: 9)); Document::insert(ThrowawayDb::TABLE, new TestDocument(value: 'something', num_value: 9));
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EX('value')], TestDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::exists('value')], TestDocument::class);
$this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertTrue($doc->isSome(), 'There should have been a document returned');
$this->assertNotEmpty($doc->get()->id, 'The ID should have been auto-generated'); $this->assertNotEmpty($doc->get()->id, 'The ID should have been auto-generated');
} finally { } finally {
@ -228,7 +228,7 @@ class DocumentTest extends TestCase
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
$uuid = AutoId::generateUUID(); $uuid = AutoId::generateUUID();
Document::insert(ThrowawayDb::TABLE, new TestDocument($uuid, num_value: 14)); Document::insert(ThrowawayDb::TABLE, new TestDocument($uuid, num_value: 14));
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 14)], TestDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 14)], TestDocument::class);
$this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertTrue($doc->isSome(), 'There should have been a document returned');
$this->assertEquals($uuid, $doc->get()->id, 'The ID should not have been changed'); $this->assertEquals($uuid, $doc->get()->id, 'The ID should not have been changed');
} finally { } finally {
@ -244,7 +244,7 @@ class DocumentTest extends TestCase
try { try {
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
Document::insert(ThrowawayDb::TABLE, new TestDocument(num_value: 55)); Document::insert(ThrowawayDb::TABLE, new TestDocument(num_value: 55));
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 55)], TestDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 55)], TestDocument::class);
$this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertTrue($doc->isSome(), 'There should have been a document returned');
$this->assertEquals(40, strlen($doc->get()->id), $this->assertEquals(40, strlen($doc->get()->id),
'The ID should have been auto-generated and had 40 characters'); 'The ID should have been auto-generated and had 40 characters');
@ -261,7 +261,7 @@ class DocumentTest extends TestCase
try { try {
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
Document::insert(ThrowawayDb::TABLE, new TestDocument('my-key', num_value: 3)); Document::insert(ThrowawayDb::TABLE, new TestDocument('my-key', num_value: 3));
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 3)], TestDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 3)], TestDocument::class);
$this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertTrue($doc->isSome(), 'There should have been a document returned');
$this->assertEquals('my-key', $doc->get()->id, 'The ID should not have been changed'); $this->assertEquals('my-key', $doc->get()->id, 'The ID should not have been changed');
} finally { } finally {

View File

@ -48,13 +48,13 @@ class ExistsTest extends TestCase
public function testByFieldsSucceedsWhenDocumentsExist(): void public function testByFieldsSucceedsWhenDocumentsExist(): void
{ {
$this->assertTrue(Exists::byFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 10)]), $this->assertTrue(Exists::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 10)]),
'There should have been existing documents'); 'There should have been existing documents');
} }
public function testByFieldsSucceedsWhenNoMatchingDocumentsExist(): void public function testByFieldsSucceedsWhenNoMatchingDocumentsExist(): void
{ {
$this->assertFalse(Exists::byFields(ThrowawayDb::TABLE, [Field::LT('nothing', 'none')]), $this->assertFalse(Exists::byFields(ThrowawayDb::TABLE, [Field::less('nothing', 'none')]),
'There should not have been any existing documents'); 'There should not have been any existing documents');
} }

View File

@ -77,7 +77,7 @@ class FindTest extends TestCase
public function testByFieldsSucceedsWhenDocumentsAreFound(): void public function testByFieldsSucceedsWhenDocumentsAreFound(): void
{ {
$docs = Find::byFields(ThrowawayDb::TABLE, [Field::GT('num_value', 15)], TestDocument::class); $docs = Find::byFields(ThrowawayDb::TABLE, [Field::greater('num_value', 15)], TestDocument::class);
$this->assertNotNull($docs, 'There should have been a document list returned'); $this->assertNotNull($docs, 'There should have been a document list returned');
$count = 0; $count = 0;
foreach ($docs->items() as $ignored) $count++; foreach ($docs->items() as $ignored) $count++;
@ -86,7 +86,7 @@ class FindTest extends TestCase
public function testByFieldsSucceedsWhenNoDocumentsAreFound(): void public function testByFieldsSucceedsWhenNoDocumentsAreFound(): void
{ {
$docs = Find::byFields(ThrowawayDb::TABLE, [Field::GT('num_value', 100)], TestDocument::class); $docs = Find::byFields(ThrowawayDb::TABLE, [Field::greater('num_value', 100)], TestDocument::class);
$this->assertNotNull($docs, 'There should have been a document list returned'); $this->assertNotNull($docs, 'There should have been a document list returned');
$this->assertFalse($docs->hasItems(), 'There should have been no documents in the list'); $this->assertFalse($docs->hasItems(), 'There should have been no documents in the list');
} }
@ -106,21 +106,21 @@ class FindTest extends TestCase
public function testFirstByFieldsSucceedsWhenADocumentIsFound(): void public function testFirstByFieldsSucceedsWhenADocumentIsFound(): void
{ {
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'another')], TestDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'another')], TestDocument::class);
$this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertTrue($doc->isSome(), 'There should have been a document returned');
$this->assertEquals('two', $doc->get()->id, 'The incorrect document was returned'); $this->assertEquals('two', $doc->get()->id, 'The incorrect document was returned');
} }
public function testFirstByFieldsSucceedsWhenMultipleDocumentsAreFound(): void public function testFirstByFieldsSucceedsWhenMultipleDocumentsAreFound(): void
{ {
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('sub.foo', 'green')], TestDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('sub.foo', 'green')], TestDocument::class);
$this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertTrue($doc->isSome(), 'There should have been a document returned');
$this->assertContains($doc->get()->id, ['two', 'four'], 'An incorrect document was returned'); $this->assertContains($doc->get()->id, ['two', 'four'], 'An incorrect document was returned');
} }
public function testFirstByFieldsSucceedsWhenADocumentIsNotFound(): void public function testFirstByFieldsSucceedsWhenADocumentIsNotFound(): void
{ {
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'absent')], TestDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'absent')], TestDocument::class);
$this->assertTrue($doc->isNone(), 'There should not have been a document returned'); $this->assertTrue($doc->isNone(), 'There should not have been a document returned');
} }

View File

@ -52,14 +52,14 @@ class PatchTest extends TestCase
public function testByFieldsSucceedsWhenADocumentIsUpdated(): void public function testByFieldsSucceedsWhenADocumentIsUpdated(): void
{ {
Patch::byFields(ThrowawayDb::TABLE, [Field::EQ('value', 'purple')], ['num_value' => 77]); Patch::byFields(ThrowawayDb::TABLE, [Field::equal('value', 'purple')], ['num_value' => 77]);
$after = Count::byFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 77)]); $after = Count::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 77)]);
$this->assertEquals(2, $after, 'There should have been 2 documents updated'); $this->assertEquals(2, $after, 'There should have been 2 documents updated');
} }
public function testByFieldsSucceedsWhenNoDocumentIsUpdated(): void public function testByFieldsSucceedsWhenNoDocumentIsUpdated(): void
{ {
Patch::byFields(ThrowawayDb::TABLE, [Field::EQ('value', 'burgundy')], ['foo' => 'green']); Patch::byFields(ThrowawayDb::TABLE, [Field::equal('value', 'burgundy')], ['foo' => 'green']);
$this->assertTrue(true, 'The above not throwing an exception is the test'); $this->assertTrue(true, 'The above not throwing an exception is the test');
} }

View File

@ -61,21 +61,21 @@ class RemoveFieldsTest extends TestCase
public function testByFieldsSucceedsWhenAFieldIsRemoved(): void public function testByFieldsSucceedsWhenAFieldIsRemoved(): void
{ {
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 17)], ['sub']); RemoveFields::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 17)], ['sub']);
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 17)], TestDocument::class); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 17)], TestDocument::class);
$this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertTrue($doc->isSome(), 'There should have been a document returned');
$this->assertNull($doc->get()->sub, 'Sub-document should have been null'); $this->assertNull($doc->get()->sub, 'Sub-document should have been null');
} }
public function testByFieldsSucceedsWhenAFieldIsNotRemoved(): void public function testByFieldsSucceedsWhenAFieldIsNotRemoved(): void
{ {
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 17)], ['nada']); RemoveFields::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 17)], ['nada']);
$this->assertTrue(true, 'The above not throwing an exception is the test'); $this->assertTrue(true, 'The above not throwing an exception is the test');
} }
public function testByFieldsSucceedsWhenNoDocumentIsMatched(): void public function testByFieldsSucceedsWhenNoDocumentIsMatched(): void
{ {
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::NE('missing', 'nope')], ['value']); RemoveFields::byFields(ThrowawayDb::TABLE, [Field::notEqual('missing', 'nope')], ['value']);
$this->assertTrue(true, 'The above not throwing an exception is the test'); $this->assertTrue(true, 'The above not throwing an exception is the test');
} }

View File

@ -18,121 +18,123 @@ use PHPUnit\Framework\TestCase;
#[TestDox('Field (Unit tests)')] #[TestDox('Field (Unit tests)')]
class FieldTest extends TestCase class FieldTest extends TestCase
{ {
#[TestDox('Append parameter succeeds for EX')] public function testAppendParameterSucceedsForExists(): void
public function testAppendParameterSucceedsForEX(): void
{ {
$this->assertEquals([], Field::EX('exists')->appendParameter([]), 'EX should not have appended a parameter'); $this->assertEquals([], Field::exists('exists')->appendParameter([]),
'exists should not have appended a parameter');
} }
#[TestDox('Append parameter succeeds for NEX')] #[TestDox('Append parameter succeeds for notExists')]
public function testAppendParameterSucceedsForNEX(): void public function testAppendParameterSucceedsForNotExists(): void
{ {
$this->assertEquals([], Field::NEX('absent')->appendParameter([]), 'NEX should not have appended a parameter'); $this->assertEquals([], Field::notExists('absent')->appendParameter([]),
'notExists should not have appended a parameter');
} }
#[TestDox('Append parameter succeeds for BT')] public function testAppendParameterSucceedsForBetween(): void
public function testAppendParameterSucceedsForBT(): void
{ {
$this->assertEquals(['@nummin' => 5, '@nummax' => 9], Field::BT('exists', 5, 9, '@num')->appendParameter([]), $this->assertEquals(['@nummin' => 5, '@nummax' => 9],
Field::between('exists', 5, 9, '@num')->appendParameter([]),
'BT should have appended min and max parameters'); 'BT should have appended min and max parameters');
} }
public function testAppendParameterSucceedsForOthers(): void public function testAppendParameterSucceedsForOthers(): void
{ {
$this->assertEquals(['@test' => 33], Field::EQ('the_field', 33, '@test')->appendParameter([]), $this->assertEquals(['@test' => 33], Field::equal('the_field', 33, '@test')->appendParameter([]),
'Field parameter not returned correctly'); 'Field parameter not returned correctly');
} }
#[TestDox('To where succeeds for EX without qualifier for PostgreSQL')] #[TestDox('To where succeeds for exists without qualifier for PostgreSQL')]
public function testToWhereSucceedsForEXWithoutQualifierForPostgreSQL(): void public function testToWhereSucceedsForExistsWithoutQualifierForPostgreSQL(): void
{ {
Configuration::overrideMode(Mode::PgSQL); Configuration::overrideMode(Mode::PgSQL);
try { try {
$this->assertEquals("data->>'that_field' IS NOT NULL", Field::EX('that_field')->toWhere(), $this->assertEquals("data->>'that_field' IS NOT NULL", Field::exists('that_field')->toWhere(),
'WHERE fragment not generated correctly'); 'WHERE fragment not generated correctly');
} finally { } finally {
Configuration::overrideMode(null); Configuration::overrideMode(null);
} }
} }
#[TestDox('To where succeeds for EX without qualifier for SQLite')] #[TestDox('To where succeeds for exists without qualifier for SQLite')]
public function testToWhereSucceedsForEXWithoutQualifierForSQLite(): void public function testToWhereSucceedsForExistsWithoutQualifierForSQLite(): void
{ {
Configuration::overrideMode(Mode::SQLite); Configuration::overrideMode(Mode::SQLite);
try { try {
$this->assertEquals("data->>'that_field' IS NOT NULL", Field::EX('that_field')->toWhere(), $this->assertEquals("data->>'that_field' IS NOT NULL", Field::exists('that_field')->toWhere(),
'WHERE fragment not generated correctly'); 'WHERE fragment not generated correctly');
} finally { } finally {
Configuration::overrideMode(null); Configuration::overrideMode(null);
} }
} }
#[TestDox('To where succeeds for NEX without qualifier for PostgreSQL')] #[TestDox('To where succeeds for notExists without qualifier for PostgreSQL')]
public function testToWhereSucceedsForNEXWithoutQualifierForPostgreSQL(): void public function testToWhereSucceedsForNotExistsWithoutQualifierForPostgreSQL(): void
{ {
Configuration::overrideMode(Mode::PgSQL); Configuration::overrideMode(Mode::PgSQL);
try { try {
$this->assertEquals("data->>'a_field' IS NULL", Field::NEX('a_field')->toWhere(), $this->assertEquals("data->>'a_field' IS NULL", Field::notExists('a_field')->toWhere(),
'WHERE fragment not generated correctly'); 'WHERE fragment not generated correctly');
} finally { } finally {
Configuration::overrideMode(null); Configuration::overrideMode(null);
} }
} }
#[TestDox('To where succeeds for NEX without qualifier for SQLite')] #[TestDox('To where succeeds for notExists without qualifier for SQLite')]
public function testToWhereSucceedsForNEXWithoutQualifierForSQLite(): void public function testToWhereSucceedsForNotExistsWithoutQualifierForSQLite(): void
{ {
Configuration::overrideMode(Mode::SQLite); Configuration::overrideMode(Mode::SQLite);
try { try {
$this->assertEquals("data->>'a_field' IS NULL", Field::NEX('a_field')->toWhere(), $this->assertEquals("data->>'a_field' IS NULL", Field::notExists('a_field')->toWhere(),
'WHERE fragment not generated correctly'); 'WHERE fragment not generated correctly');
} finally { } finally {
Configuration::overrideMode(null); Configuration::overrideMode(null);
} }
} }
#[TestDox('To where succeeds for BT without qualifier for SQLite')] #[TestDox('To where succeeds for between without qualifier for SQLite')]
public function testToWhereSucceedsForBTWithoutQualifierForSQLite(): void public function testToWhereSucceedsForBetweenWithoutQualifierForSQLite(): void
{ {
Configuration::overrideMode(Mode::SQLite); Configuration::overrideMode(Mode::SQLite);
try { try {
$this->assertEquals("data->>'age' BETWEEN @agemin AND @agemax", Field::BT('age', 13, 17, '@age')->toWhere(), $this->assertEquals("data->>'age' BETWEEN @agemin AND @agemax",
'WHERE fragment not generated correctly'); Field::between('age', 13, 17, '@age')->toWhere(), 'WHERE fragment not generated correctly');
} finally { } finally {
Configuration::overrideMode(null); Configuration::overrideMode(null);
} }
} }
#[TestDox('To where succeeds for BT without qualifier for PostgreSQL with numeric range')] #[TestDox('To where succeeds for between without qualifier for PostgreSQL with numeric range')]
public function testToWhereSucceedsForBTWithoutQualifierForPostgreSQLWithNumericRange(): void public function testToWhereSucceedsForBetweenWithoutQualifierForPostgreSQLWithNumericRange(): void
{ {
Configuration::overrideMode(Mode::PgSQL); Configuration::overrideMode(Mode::PgSQL);
try { try {
$this->assertEquals("(data->>'age')::numeric BETWEEN @agemin AND @agemax", $this->assertEquals("(data->>'age')::numeric BETWEEN @agemin AND @agemax",
Field::BT('age', 13, 17, '@age')->toWhere(), 'WHERE fragment not generated correctly'); Field::between('age', 13, 17, '@age')->toWhere(), 'WHERE fragment not generated correctly');
} finally { } finally {
Configuration::overrideMode(null); Configuration::overrideMode(null);
} }
} }
#[TestDox('To where succeeds for BT without qualifier for PostgreSQL with non-numeric range')] #[TestDox('To where succeeds for between without qualifier for PostgreSQL with non-numeric range')]
public function testToWhereSucceedsForBTWithoutQualifierForPostgreSQLWithNonNumericRange(): void public function testToWhereSucceedsForBetweenWithoutQualifierForPostgreSQLWithNonNumericRange(): void
{ {
Configuration::overrideMode(Mode::PgSQL); Configuration::overrideMode(Mode::PgSQL);
try { try {
$this->assertEquals("data->>'city' BETWEEN :citymin AND :citymax", $this->assertEquals("data->>'city' BETWEEN :citymin AND :citymax",
Field::BT('city', 'Atlanta', 'Chicago', ':city')->toWhere(), 'WHERE fragment not generated correctly'); Field::between('city', 'Atlanta', 'Chicago', ':city')->toWhere(),
'WHERE fragment not generated correctly');
} finally { } finally {
Configuration::overrideMode(null); Configuration::overrideMode(null);
} }
} }
#[TestDox('To where succeeds for BT with qualifier for SQLite')] #[TestDox('To where succeeds for between with qualifier for SQLite')]
public function testToWhereSucceedsForBTWithQualifierForSQLite(): void public function testToWhereSucceedsForBetweenWithQualifierForSQLite(): void
{ {
Configuration::overrideMode(Mode::SQLite); Configuration::overrideMode(Mode::SQLite);
try { try {
$field = Field::BT('age', 13, 17, '@age'); $field = Field::between('age', 13, 17, '@age');
$field->qualifier = 'me'; $field->qualifier = 'me';
$this->assertEquals("me.data->>'age' BETWEEN @agemin AND @agemax", $field->toWhere(), $this->assertEquals("me.data->>'age' BETWEEN @agemin AND @agemax", $field->toWhere(),
'WHERE fragment not generated correctly'); 'WHERE fragment not generated correctly');
@ -141,12 +143,12 @@ class FieldTest extends TestCase
} }
} }
#[TestDox('To where succeeds for BT with qualifier for PostgreSQL with numeric range')] #[TestDox('To where succeeds for between with qualifier for PostgreSQL with numeric range')]
public function testToWhereSucceedsForBTWithQualifierForPostgreSQLWithNumericRange(): void public function testToWhereSucceedsForBetweenWithQualifierForPostgreSQLWithNumericRange(): void
{ {
Configuration::overrideMode(Mode::PgSQL); Configuration::overrideMode(Mode::PgSQL);
try { try {
$field = Field::BT('age', 13, 17, '@age'); $field = Field::between('age', 13, 17, '@age');
$field->qualifier = 'me'; $field->qualifier = 'me';
$this->assertEquals("(me.data->>'age')::numeric BETWEEN @agemin AND @agemax", $field->toWhere(), $this->assertEquals("(me.data->>'age')::numeric BETWEEN @agemin AND @agemax", $field->toWhere(),
'WHERE fragment not generated correctly'); 'WHERE fragment not generated correctly');
@ -155,12 +157,12 @@ class FieldTest extends TestCase
} }
} }
#[TestDox('To where succeeds for BT with qualifier for PostgreSQL with non-numeric range')] #[TestDox('To where succeeds for between with qualifier for PostgreSQL with non-numeric range')]
public function testToWhereSucceedsForBTWithQualifierForPostgreSQLWithNonNumericRange(): void public function testToWhereSucceedsForBetweenWithQualifierForPostgreSQLWithNonNumericRange(): void
{ {
Configuration::overrideMode(Mode::PgSQL); Configuration::overrideMode(Mode::PgSQL);
try { try {
$field = Field::BT('city', 'Atlanta', 'Chicago', ':city'); $field = Field::between('city', 'Atlanta', 'Chicago', ':city');
$field->qualifier = 'me'; $field->qualifier = 'me';
$this->assertEquals("me.data->>'city' BETWEEN :citymin AND :citymax", $field->toWhere(), $this->assertEquals("me.data->>'city' BETWEEN :citymin AND :citymax", $field->toWhere(),
'WHERE fragment not generated correctly'); 'WHERE fragment not generated correctly');
@ -174,7 +176,7 @@ class FieldTest extends TestCase
{ {
Configuration::overrideMode(Mode::PgSQL); Configuration::overrideMode(Mode::PgSQL);
try { try {
$this->assertEquals("data->>'some_field' = @value", Field::EQ('some_field', '', '@value')->toWhere(), $this->assertEquals("data->>'some_field' = @value", Field::equal('some_field', '', '@value')->toWhere(),
'WHERE fragment not generated correctly'); 'WHERE fragment not generated correctly');
} finally { } finally {
Configuration::overrideMode(null); Configuration::overrideMode(null);
@ -186,7 +188,7 @@ class FieldTest extends TestCase
{ {
Configuration::overrideMode(Mode::SQLite); Configuration::overrideMode(Mode::SQLite);
try { try {
$this->assertEquals("data->>'some_field' = @value", Field::EQ('some_field', '', '@value')->toWhere(), $this->assertEquals("data->>'some_field' = @value", Field::equal('some_field', '', '@value')->toWhere(),
'WHERE fragment not generated correctly'); 'WHERE fragment not generated correctly');
} finally { } finally {
Configuration::overrideMode(null); Configuration::overrideMode(null);
@ -198,7 +200,7 @@ class FieldTest extends TestCase
{ {
Configuration::overrideMode(Mode::PgSQL); Configuration::overrideMode(Mode::PgSQL);
try { try {
$field = Field::EX('no_field'); $field = Field::exists('no_field');
$field->qualifier = 'test'; $field->qualifier = 'test';
$this->assertEquals("test.data->>'no_field' IS NOT NULL", $field->toWhere(), $this->assertEquals("test.data->>'no_field' IS NOT NULL", $field->toWhere(),
'WHERE fragment not generated correctly'); 'WHERE fragment not generated correctly');
@ -212,7 +214,7 @@ class FieldTest extends TestCase
{ {
Configuration::overrideMode(Mode::SQLite); Configuration::overrideMode(Mode::SQLite);
try { try {
$field = Field::EX('no_field'); $field = Field::exists('no_field');
$field->qualifier = 'test'; $field->qualifier = 'test';
$this->assertEquals("test.data->>'no_field' IS NOT NULL", $field->toWhere(), $this->assertEquals("test.data->>'no_field' IS NOT NULL", $field->toWhere(),
'WHERE fragment not generated correctly'); 'WHERE fragment not generated correctly');
@ -226,7 +228,7 @@ class FieldTest extends TestCase
{ {
Configuration::overrideMode(Mode::PgSQL); Configuration::overrideMode(Mode::PgSQL);
try { try {
$field = Field::LE('le_field', 18, '@it'); $field = Field::lessOrEqual('le_field', 18, '@it');
$field->qualifier = 'q'; $field->qualifier = 'q';
$this->assertEquals("(q.data->>'le_field')::numeric <= @it", $field->toWhere(), $this->assertEquals("(q.data->>'le_field')::numeric <= @it", $field->toWhere(),
'WHERE fragment not generated correctly'); 'WHERE fragment not generated correctly');
@ -240,7 +242,7 @@ class FieldTest extends TestCase
{ {
Configuration::overrideMode(Mode::SQLite); Configuration::overrideMode(Mode::SQLite);
try { try {
$field = Field::LE('le_field', 18, '@it'); $field = Field::lessOrEqual('le_field', 18, '@it');
$field->qualifier = 'q'; $field->qualifier = 'q';
$this->assertEquals("q.data->>'le_field' <= @it", $field->toWhere(), $this->assertEquals("q.data->>'le_field' <= @it", $field->toWhere(),
'WHERE fragment not generated correctly'); 'WHERE fragment not generated correctly');
@ -254,7 +256,7 @@ class FieldTest extends TestCase
{ {
Configuration::overrideMode(Mode::PgSQL); Configuration::overrideMode(Mode::PgSQL);
try { try {
$field = Field::EQ('sub.foo.bar', 22, '@it'); $field = Field::equal('sub.foo.bar', 22, '@it');
$this->assertEquals("(data#>>'{sub,foo,bar}')::numeric = @it", $field->toWhere(), $this->assertEquals("(data#>>'{sub,foo,bar}')::numeric = @it", $field->toWhere(),
'WHERE fragment not generated correctly'); 'WHERE fragment not generated correctly');
} finally { } finally {
@ -267,7 +269,7 @@ class FieldTest extends TestCase
{ {
Configuration::overrideMode(Mode::SQLite); Configuration::overrideMode(Mode::SQLite);
try { try {
$field = Field::EQ('sub.foo.bar', 22, '@it'); $field = Field::equal('sub.foo.bar', 22, '@it');
$this->assertEquals("data->>'sub'->>'foo'->>'bar' = @it", $field->toWhere(), $this->assertEquals("data->>'sub'->>'foo'->>'bar' = @it", $field->toWhere(),
'WHERE fragment not generated correctly'); 'WHERE fragment not generated correctly');
} finally { } finally {
@ -275,178 +277,178 @@ class FieldTest extends TestCase
} }
} }
#[TestDox('EQ succeeds without parameter')] #[TestDox('equal succeeds without parameter')]
public function testEQSucceedsWithoutParameter(): void public function testEqualSucceedsWithoutParameter(): void
{ {
$field = Field::EQ('my_test', 9); $field = Field::equal('my_test', 9);
$this->assertNotNull($field, 'The field should not have been null'); $this->assertNotNull($field, 'The field should not have been null');
$this->assertEquals('my_test', $field->fieldName, 'Field name not filled correctly'); $this->assertEquals('my_test', $field->fieldName, 'Field name not filled correctly');
$this->assertEquals(Op::EQ, $field->op, 'Operation not filled correctly'); $this->assertEquals(Op::Equal, $field->op, 'Operation not filled correctly');
$this->assertEquals(9, $field->value, 'Value not filled correctly'); $this->assertEquals(9, $field->value, 'Value not filled correctly');
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank'); $this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
} }
#[TestDox('EQ succeeds with parameter')] #[TestDox('equal succeeds with parameter')]
public function testEQSucceedsWithParameter(): void public function testEqualSucceedsWithParameter(): void
{ {
$field = Field::EQ('another_test', 'turkey', '@test'); $field = Field::equal('another_test', 'turkey', '@test');
$this->assertNotNull($field, 'The field should not have been null'); $this->assertNotNull($field, 'The field should not have been null');
$this->assertEquals('another_test', $field->fieldName, 'Field name not filled correctly'); $this->assertEquals('another_test', $field->fieldName, 'Field name not filled correctly');
$this->assertEquals(Op::EQ, $field->op, 'Operation not filled correctly'); $this->assertEquals(Op::Equal, $field->op, 'Operation not filled correctly');
$this->assertEquals('turkey', $field->value, 'Value not filled correctly'); $this->assertEquals('turkey', $field->value, 'Value not filled correctly');
$this->assertEquals('@test', $field->paramName, 'Parameter name not filled correctly'); $this->assertEquals('@test', $field->paramName, 'Parameter name not filled correctly');
} }
#[TestDox('GT succeeds without parameter')] #[TestDox('greater succeeds without parameter')]
public function testGTSucceedsWithoutParameter(): void public function testGreaterSucceedsWithoutParameter(): void
{ {
$field = Field::GT('your_test', 4); $field = Field::greater('your_test', 4);
$this->assertNotNull($field, 'The field should not have been null'); $this->assertNotNull($field, 'The field should not have been null');
$this->assertEquals('your_test', $field->fieldName, 'Field name not filled correctly'); $this->assertEquals('your_test', $field->fieldName, 'Field name not filled correctly');
$this->assertEquals(Op::GT, $field->op, 'Operation not filled correctly'); $this->assertEquals(Op::Greater, $field->op, 'Operation not filled correctly');
$this->assertEquals(4, $field->value, 'Value not filled correctly'); $this->assertEquals(4, $field->value, 'Value not filled correctly');
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank'); $this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
} }
#[TestDox('GT succeeds with parameter')] #[TestDox('greater succeeds with parameter')]
public function testGTSucceedsWithParameter(): void public function testGreaterSucceedsWithParameter(): void
{ {
$field = Field::GT('more_test', 'chicken', '@value'); $field = Field::greater('more_test', 'chicken', '@value');
$this->assertNotNull($field, 'The field should not have been null'); $this->assertNotNull($field, 'The field should not have been null');
$this->assertEquals('more_test', $field->fieldName, 'Field name not filled correctly'); $this->assertEquals('more_test', $field->fieldName, 'Field name not filled correctly');
$this->assertEquals(Op::GT, $field->op, 'Operation not filled correctly'); $this->assertEquals(Op::Greater, $field->op, 'Operation not filled correctly');
$this->assertEquals('chicken', $field->value, 'Value not filled correctly'); $this->assertEquals('chicken', $field->value, 'Value not filled correctly');
$this->assertEquals('@value', $field->paramName, 'Parameter name not filled correctly'); $this->assertEquals('@value', $field->paramName, 'Parameter name not filled correctly');
} }
#[TestDox('GE succeeds without parameter')] #[TestDox('greaterOrEqual succeeds without parameter')]
public function testGESucceedsWithoutParameter(): void public function testGreaterOrEqualSucceedsWithoutParameter(): void
{ {
$field = Field::GE('their_test', 6); $field = Field::greaterOrEqual('their_test', 6);
$this->assertNotNull($field, 'The field should not have been null'); $this->assertNotNull($field, 'The field should not have been null');
$this->assertEquals('their_test', $field->fieldName, 'Field name not filled correctly'); $this->assertEquals('their_test', $field->fieldName, 'Field name not filled correctly');
$this->assertEquals(Op::GE, $field->op, 'Operation not filled correctly'); $this->assertEquals(Op::GreaterOrEqual, $field->op, 'Operation not filled correctly');
$this->assertEquals(6, $field->value, 'Value not filled correctly'); $this->assertEquals(6, $field->value, 'Value not filled correctly');
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank'); $this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
} }
#[TestDox('GE succeeds with parameter')] #[TestDox('greaterOrEqual succeeds with parameter')]
public function testGESucceedsWithParameter(): void public function testGreaterOrEqualSucceedsWithParameter(): void
{ {
$field = Field::GE('greater_test', 'poultry', '@cluck'); $field = Field::greaterOrEqual('greater_test', 'poultry', '@cluck');
$this->assertNotNull($field, 'The field should not have been null'); $this->assertNotNull($field, 'The field should not have been null');
$this->assertEquals('greater_test', $field->fieldName, 'Field name not filled correctly'); $this->assertEquals('greater_test', $field->fieldName, 'Field name not filled correctly');
$this->assertEquals(Op::GE, $field->op, 'Operation not filled correctly'); $this->assertEquals(Op::GreaterOrEqual, $field->op, 'Operation not filled correctly');
$this->assertEquals('poultry', $field->value, 'Value not filled correctly'); $this->assertEquals('poultry', $field->value, 'Value not filled correctly');
$this->assertEquals('@cluck', $field->paramName, 'Parameter name not filled correctly'); $this->assertEquals('@cluck', $field->paramName, 'Parameter name not filled correctly');
} }
#[TestDox('LT succeeds without parameter')] #[TestDox('less succeeds without parameter')]
public function testLTSucceedsWithoutParameter(): void public function testLessSucceedsWithoutParameter(): void
{ {
$field = Field::LT('z', 32); $field = Field::less('z', 32);
$this->assertNotNull($field, 'The field should not have been null'); $this->assertNotNull($field, 'The field should not have been null');
$this->assertEquals('z', $field->fieldName, 'Field name not filled correctly'); $this->assertEquals('z', $field->fieldName, 'Field name not filled correctly');
$this->assertEquals(Op::LT, $field->op, 'Operation not filled correctly'); $this->assertEquals(Op::Less, $field->op, 'Operation not filled correctly');
$this->assertEquals(32, $field->value, 'Value not filled correctly'); $this->assertEquals(32, $field->value, 'Value not filled correctly');
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank'); $this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
} }
#[TestDox('LT succeeds with parameter')] #[TestDox('less succeeds with parameter')]
public function testLTSucceedsWithParameter(): void public function testLessSucceedsWithParameter(): void
{ {
$field = Field::LT('additional_test', 'fowl', '@boo'); $field = Field::less('additional_test', 'fowl', '@boo');
$this->assertNotNull($field, 'The field should not have been null'); $this->assertNotNull($field, 'The field should not have been null');
$this->assertEquals('additional_test', $field->fieldName, 'Field name not filled correctly'); $this->assertEquals('additional_test', $field->fieldName, 'Field name not filled correctly');
$this->assertEquals(Op::LT, $field->op, 'Operation not filled correctly'); $this->assertEquals(Op::Less, $field->op, 'Operation not filled correctly');
$this->assertEquals('fowl', $field->value, 'Value not filled correctly'); $this->assertEquals('fowl', $field->value, 'Value not filled correctly');
$this->assertEquals('@boo', $field->paramName, 'Parameter name not filled correctly'); $this->assertEquals('@boo', $field->paramName, 'Parameter name not filled correctly');
} }
#[TestDox('LE succeeds without parameter')] #[TestDox('lessOrEqual succeeds without parameter')]
public function testLESucceedsWithoutParameter(): void public function testLessOrEqualSucceedsWithoutParameter(): void
{ {
$field = Field::LE('g', 87); $field = Field::lessOrEqual('g', 87);
$this->assertNotNull($field, 'The field should not have been null'); $this->assertNotNull($field, 'The field should not have been null');
$this->assertEquals('g', $field->fieldName, 'Field name not filled correctly'); $this->assertEquals('g', $field->fieldName, 'Field name not filled correctly');
$this->assertEquals(Op::LE, $field->op, 'Operation not filled correctly'); $this->assertEquals(Op::LessOrEqual, $field->op, 'Operation not filled correctly');
$this->assertEquals(87, $field->value, 'Value not filled correctly'); $this->assertEquals(87, $field->value, 'Value not filled correctly');
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank'); $this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
} }
#[TestDox('LE succeeds with parameter')] #[TestDox('lessOrEqual succeeds with parameter')]
public function testLESucceedsWithParameter(): void public function testLessOrEqualSucceedsWithParameter(): void
{ {
$field = Field::LE('lesser_test', 'hen', '@woo'); $field = Field::lessOrEqual('lesser_test', 'hen', '@woo');
$this->assertNotNull($field, 'The field should not have been null'); $this->assertNotNull($field, 'The field should not have been null');
$this->assertEquals('lesser_test', $field->fieldName, 'Field name not filled correctly'); $this->assertEquals('lesser_test', $field->fieldName, 'Field name not filled correctly');
$this->assertEquals(Op::LE, $field->op, 'Operation not filled correctly'); $this->assertEquals(Op::LessOrEqual, $field->op, 'Operation not filled correctly');
$this->assertEquals('hen', $field->value, 'Value not filled correctly'); $this->assertEquals('hen', $field->value, 'Value not filled correctly');
$this->assertEquals('@woo', $field->paramName, 'Parameter name not filled correctly'); $this->assertEquals('@woo', $field->paramName, 'Parameter name not filled correctly');
} }
#[TestDox('NE succeeds without parameter')] #[TestDox('notEqual succeeds without parameter')]
public function testNESucceedsWithoutParameter(): void public function testNotEqualSucceedsWithoutParameter(): void
{ {
$field = Field::NE('j', 65); $field = Field::notEqual('j', 65);
$this->assertNotNull($field, 'The field should not have been null'); $this->assertNotNull($field, 'The field should not have been null');
$this->assertEquals('j', $field->fieldName, 'Field name not filled correctly'); $this->assertEquals('j', $field->fieldName, 'Field name not filled correctly');
$this->assertEquals(Op::NE, $field->op, 'Operation not filled correctly'); $this->assertEquals(Op::NotEqual, $field->op, 'Operation not filled correctly');
$this->assertEquals(65, $field->value, 'Value not filled correctly'); $this->assertEquals(65, $field->value, 'Value not filled correctly');
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank'); $this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
} }
#[TestDox('NE succeeds with parameter')] #[TestDox('notEqual succeeds with parameter')]
public function testNESucceedsWithParameter(): void public function testNotEqualSucceedsWithParameter(): void
{ {
$field = Field::NE('unequal_test', 'egg', '@zoo'); $field = Field::notEqual('unequal_test', 'egg', '@zoo');
$this->assertNotNull($field, 'The field should not have been null'); $this->assertNotNull($field, 'The field should not have been null');
$this->assertEquals('unequal_test', $field->fieldName, 'Field name not filled correctly'); $this->assertEquals('unequal_test', $field->fieldName, 'Field name not filled correctly');
$this->assertEquals(Op::NE, $field->op, 'Operation not filled correctly'); $this->assertEquals(Op::NotEqual, $field->op, 'Operation not filled correctly');
$this->assertEquals('egg', $field->value, 'Value not filled correctly'); $this->assertEquals('egg', $field->value, 'Value not filled correctly');
$this->assertEquals('@zoo', $field->paramName, 'Parameter name not filled correctly'); $this->assertEquals('@zoo', $field->paramName, 'Parameter name not filled correctly');
} }
#[TestDox('BT succeeds without parameter')] #[TestDox('between succeeds without parameter')]
public function testBTSucceedsWithoutParameter(): void public function testBetweenSucceedsWithoutParameter(): void
{ {
$field = Field::BT('k', 'alpha', 'zed'); $field = Field::between('k', 'alpha', 'zed');
$this->assertNotNull($field, 'The field should not have been null'); $this->assertNotNull($field, 'The field should not have been null');
$this->assertEquals('k', $field->fieldName, 'Field name not filled correctly'); $this->assertEquals('k', $field->fieldName, 'Field name not filled correctly');
$this->assertEquals(Op::BT, $field->op, 'Operation not filled correctly'); $this->assertEquals(Op::Between, $field->op, 'Operation not filled correctly');
$this->assertEquals(['alpha', 'zed'], $field->value, 'Value not filled correctly'); $this->assertEquals(['alpha', 'zed'], $field->value, 'Value not filled correctly');
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank'); $this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
} }
#[TestDox('BT succeeds with parameter')] #[TestDox('between succeeds with parameter')]
public function testBTSucceedsWithParameter(): void public function testBetweenSucceedsWithParameter(): void
{ {
$field = Field::BT('between_test', 18, 49, '@count'); $field = Field::between('between_test', 18, 49, '@count');
$this->assertNotNull($field, 'The field should not have been null'); $this->assertNotNull($field, 'The field should not have been null');
$this->assertEquals('between_test', $field->fieldName, 'Field name not filled correctly'); $this->assertEquals('between_test', $field->fieldName, 'Field name not filled correctly');
$this->assertEquals(Op::BT, $field->op, 'Operation not filled correctly'); $this->assertEquals(Op::Between, $field->op, 'Operation not filled correctly');
$this->assertEquals([18, 49], $field->value, 'Value not filled correctly'); $this->assertEquals([18, 49], $field->value, 'Value not filled correctly');
$this->assertEquals('@count', $field->paramName, 'Parameter name not filled correctly'); $this->assertEquals('@count', $field->paramName, 'Parameter name not filled correctly');
} }
#[TestDox('EX succeeds')] #[TestDox('exists succeeds')]
public function testEXSucceeds(): void public function testExistsSucceeds(): void
{ {
$field = Field::EX('be_there'); $field = Field::exists('be_there');
$this->assertNotNull($field, 'The field should not have been null'); $this->assertNotNull($field, 'The field should not have been null');
$this->assertEquals('be_there', $field->fieldName, 'Field name not filled correctly'); $this->assertEquals('be_there', $field->fieldName, 'Field name not filled correctly');
$this->assertEquals(Op::EX, $field->op, 'Operation not filled correctly'); $this->assertEquals(Op::Exists, $field->op, 'Operation not filled correctly');
$this->assertEquals('', $field->value, 'Value should have been blank'); $this->assertEquals('', $field->value, 'Value should have been blank');
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank'); $this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
} }
#[TestDox('NEX succeeds')] #[TestDox('notExists succeeds')]
public function testNEXSucceeds(): void public function testNotExistsSucceeds(): void
{ {
$field = Field::NEX('be_absent'); $field = Field::notExists('be_absent');
$this->assertNotNull($field, 'The field should not have been null'); $this->assertNotNull($field, 'The field should not have been null');
$this->assertEquals('be_absent', $field->fieldName, 'Field name not filled correctly'); $this->assertEquals('be_absent', $field->fieldName, 'Field name not filled correctly');
$this->assertEquals(Op::NEX, $field->op, 'Operation not filled correctly'); $this->assertEquals(Op::NotExists, $field->op, 'Operation not filled correctly');
$this->assertEquals('', $field->value, 'Value should have been blank'); $this->assertEquals('', $field->value, 'Value should have been blank');
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank'); $this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
} }

View File

@ -18,57 +18,69 @@ use PHPUnit\Framework\TestCase;
#[TestDox('Op (Unit tests)')] #[TestDox('Op (Unit tests)')]
class OpTest extends TestCase class OpTest extends TestCase
{ {
#[TestDox('To SQL succeeds for EQ')] #[TestDox('To SQL succeeds for Equal')]
public function testToSQLSucceedsForEQ(): void public function testToSQLSucceedsForEqual(): void
{ {
$this->assertEquals('=', Op::EQ->toSQL(), 'EQ operator incorrect'); $this->assertEquals('=', Op::Equal->toSQL(), 'Equal SQL operator incorrect');
} }
#[TestDox('To SQL succeeds for GT')] #[TestDox('To SQL succeeds for Greater')]
public function testToSQLSucceedsForGT(): void public function testToSQLSucceedsForGreater(): void
{ {
$this->assertEquals('>', Op::GT->toSQL(), 'GT operator incorrect'); $this->assertEquals('>', Op::Greater->toSQL(), 'Greater SQL operator incorrect');
} }
#[TestDox('To SQL succeeds for GE')] #[TestDox('To SQL succeeds for GreaterOrEqual')]
public function testToSQLSucceedsForGE(): void public function testToSQLSucceedsForGreaterOrEqual(): void
{ {
$this->assertEquals('>=', Op::GE->toSQL(), 'GE operator incorrect'); $this->assertEquals('>=', Op::GreaterOrEqual->toSQL(), 'GreaterOrEqual SQL operator incorrect');
} }
#[TestDox('To SQL succeeds for LT')] #[TestDox('To SQL succeeds for Less')]
public function testToSQLSucceedsForLT(): void public function testToSQLSucceedsForLess(): void
{ {
$this->assertEquals('<', Op::LT->toSQL(), 'LT operator incorrect'); $this->assertEquals('<', Op::Less->toSQL(), 'Less SQL operator incorrect');
} }
#[TestDox('To SQL succeeds for LE')] #[TestDox('To SQL succeeds for LessOrEqual')]
public function testToSQLSucceedsForLE(): void public function testToSQLSucceedsForLessOrEqual(): void
{ {
$this->assertEquals('<=', Op::LE->toSQL(), 'LE operator incorrect'); $this->assertEquals('<=', Op::LessOrEqual->toSQL(), 'LessOrEqual SQL operator incorrect');
} }
#[TestDox('To SQL succeeds for NE')] #[TestDox('To SQL succeeds for NotEqual')]
public function testToSQLSucceedsForNE(): void public function testToSQLSucceedsForNotEqual(): void
{ {
$this->assertEquals('<>', Op::NE->toSQL(), 'NE operator incorrect'); $this->assertEquals('<>', Op::NotEqual->toSQL(), 'NotEqual SQL operator incorrect');
} }
#[TestDox('To SQL succeeds for BT')] #[TestDox('To SQL succeeds for Between')]
public function testToSQLSucceedsForBT(): void public function testToSQLSucceedsForBetween(): void
{ {
$this->assertEquals('BETWEEN', Op::BT->toSQL(), 'BT operator incorrect'); $this->assertEquals('BETWEEN', Op::Between->toSQL(), 'Between SQL operator incorrect');
} }
#[TestDox('To SQL succeeds for EX')] #[TestDox('To SQL succeeds for In')]
public function testToSQLSucceedsForEX(): void public function testToSQLSucceedsForIn(): void
{ {
$this->assertEquals('IS NOT NULL', Op::EX->toSQL(), 'EX operator incorrect'); $this->assertEquals('IN', Op::In->toSQL(), 'In SQL operator incorrect');
} }
#[TestDox('To SQL succeeds for NEX')] #[TestDox('To SQL succeeds for InArray')]
public function testToSQLSucceedsForInArray(): void
{
$this->assertEquals('?|', Op::InArray->toSQL(), 'InArray SQL operator incorrect');
}
#[TestDox('To SQL succeeds for Exists')]
public function testToSQLSucceedsForExists(): void
{
$this->assertEquals('IS NOT NULL', Op::Exists->toSQL(), 'Exists SQL operator incorrect');
}
#[TestDox('To SQL succeeds for NotExists')]
public function testToSQLSucceedsForNEX(): void public function testToSQLSucceedsForNEX(): void
{ {
$this->assertEquals('IS NULL', Op::NEX->toSQL(), 'NEX operator incorrect'); $this->assertEquals('IS NULL', Op::NotExists->toSQL(), 'NotExists SQL operator incorrect');
} }
} }

View File

@ -79,7 +79,8 @@ class ParametersTest extends TestCase
public function testNameFieldsSucceeds(): void public function testNameFieldsSucceeds(): void
{ {
$named = Parameters::nameFields([Field::EQ('it', 17), Field::EQ('also', 22, ':also'), Field::EQ('other', 24)]); $named = Parameters::nameFields(
[Field::equal('it', 17), Field::equal('also', 22, ':also'), Field::equal('other', 24)]);
$this->assertCount(3, $named, 'There should be 3 parameters in the array'); $this->assertCount(3, $named, 'There should be 3 parameters in the array');
$this->assertEquals(':field0', $named[0]->paramName, 'Parameter 1 not named correctly'); $this->assertEquals(':field0', $named[0]->paramName, 'Parameter 1 not named correctly');
$this->assertEquals(':also', $named[1]->paramName, 'Parameter 2 not named correctly'); $this->assertEquals(':also', $named[1]->paramName, 'Parameter 2 not named correctly');
@ -89,7 +90,7 @@ class ParametersTest extends TestCase
public function testAddFieldsSucceeds(): void public function testAddFieldsSucceeds(): void
{ {
$this->assertEquals([':a' => 1, ':b' => 'two', ':z' => 18], $this->assertEquals([':a' => 1, ':b' => 'two', ':z' => 18],
Parameters::addFields([Field::EQ('b', 'two', ':b'), Field::EQ('z', 18, ':z')], [':a' => 1]), Parameters::addFields([Field::equal('b', 'two', ':b'), Field::equal('z', 18, ':z')], [':a' => 1]),
'Field parameters not added correctly'); 'Field parameters not added correctly');
} }

View File

@ -35,7 +35,7 @@ class CountTest extends TestCase
{ {
Configuration::overrideMode(Mode::SQLite); Configuration::overrideMode(Mode::SQLite);
$this->assertEquals("SELECT COUNT(*) FROM somewhere WHERE data->>'errors' > :errors", $this->assertEquals("SELECT COUNT(*) FROM somewhere WHERE data->>'errors' > :errors",
Count::byFields('somewhere', [Field::GT('errors', 10, ':errors')]), Count::byFields('somewhere', [Field::greater('errors', 10, ':errors')]),
'SELECT statement not generated correctly'); 'SELECT statement not generated correctly');
} }

View File

@ -36,7 +36,8 @@ class DeleteTest extends TestCase
{ {
Configuration::overrideMode(Mode::SQLite); Configuration::overrideMode(Mode::SQLite);
$this->assertEquals("DELETE FROM my_table WHERE data->>'value' < :max AND data->>'value' >= :min", $this->assertEquals("DELETE FROM my_table WHERE data->>'value' < :max AND data->>'value' >= :min",
Delete::byFields('my_table', [Field::LT('value', 99, ':max'), Field::GE('value', 18, ':min')]), Delete::byFields('my_table',
[Field::less('value', 99, ':max'), Field::greaterOrEqual('value', 18, ':min')]),
'DELETE statement not constructed correctly'); 'DELETE statement not constructed correctly');
} }

View File

@ -43,7 +43,7 @@ class ExistsTest extends TestCase
{ {
Configuration::overrideMode(Mode::SQLite); Configuration::overrideMode(Mode::SQLite);
$this->assertEquals("SELECT EXISTS (SELECT 1 FROM box WHERE data->>'status' <> :status)", $this->assertEquals("SELECT EXISTS (SELECT 1 FROM box WHERE data->>'status' <> :status)",
Exists::byFields('box', [Field::NE('status', 'occupied', ':status')]), Exists::byFields('box', [Field::notEqual('status', 'occupied', ':status')]),
'Existence query not generated correctly'); 'Existence query not generated correctly');
} }

View File

@ -36,7 +36,7 @@ class FindTest extends TestCase
{ {
Configuration::overrideMode(Mode::SQLite); Configuration::overrideMode(Mode::SQLite);
$this->assertEquals("SELECT data FROM there WHERE data->>'active' = :act OR data->>'locked' = :lock", $this->assertEquals("SELECT data FROM there WHERE data->>'active' = :act OR data->>'locked' = :lock",
Find::byFields('there', [Field::EQ('active', true, ':act'), Field::EQ('locked', true, ':lock')], Find::byFields('there', [Field::equal('active', true, ':act'), Field::equal('locked', true, ':lock')],
FieldMatch::Any), FieldMatch::Any),
'SELECT query not generated correctly'); 'SELECT query not generated correctly');
} }

View File

@ -52,7 +52,7 @@ class PatchTest extends TestCase
{ {
Configuration::overrideMode(Mode::PgSQL); Configuration::overrideMode(Mode::PgSQL);
$this->assertEquals("UPDATE that SET data = data || :data WHERE (data->>'something')::numeric < :some", $this->assertEquals("UPDATE that SET data = data || :data WHERE (data->>'something')::numeric < :some",
Patch::byFields('that', [Field::LT('something', 17, ':some')]), 'Patch UPDATE statement is not correct'); Patch::byFields('that', [Field::less('something', 17, ':some')]), 'Patch UPDATE statement is not correct');
} }
#[TestDox('By fields succeeds for SQLite')] #[TestDox('By fields succeeds for SQLite')]
@ -61,7 +61,8 @@ class PatchTest extends TestCase
Configuration::overrideMode(Mode::SQLite); Configuration::overrideMode(Mode::SQLite);
$this->assertEquals( $this->assertEquals(
"UPDATE a_table SET data = json_patch(data, json(:data)) WHERE data->>'something' > :it", "UPDATE a_table SET data = json_patch(data, json(:data)) WHERE data->>'something' > :it",
Patch::byFields('a_table', [Field::GT('something', 17, ':it')]), 'Patch UPDATE statement is not correct'); Patch::byFields('a_table', [Field::greater('something', 17, ':it')]),
'Patch UPDATE statement is not correct');
} }
public function testByFieldsFailsWhenModeNotSet(): void public function testByFieldsFailsWhenModeNotSet(): void

View File

@ -76,7 +76,7 @@ class RemoveFieldsTest extends TestCase
{ {
Configuration::overrideMode(Mode::PgSQL); Configuration::overrideMode(Mode::PgSQL);
$this->assertEquals("UPDATE enchilada SET data = data - :sauce::text[] WHERE data->>'cheese' = :queso", $this->assertEquals("UPDATE enchilada SET data = data - :sauce::text[] WHERE data->>'cheese' = :queso",
RemoveFields::byFields('enchilada', [Field::EQ('cheese', 'jack', ':queso')], RemoveFields::byFields('enchilada', [Field::equal('cheese', 'jack', ':queso')],
Parameters::fieldNames(':sauce', ['white'])), Parameters::fieldNames(':sauce', ['white'])),
'UPDATE statement not correct'); 'UPDATE statement not correct');
} }
@ -87,7 +87,7 @@ class RemoveFieldsTest extends TestCase
Configuration::overrideMode(Mode::SQLite); Configuration::overrideMode(Mode::SQLite);
$this->assertEquals( $this->assertEquals(
"UPDATE chimichanga SET data = json_remove(data, :filling0) WHERE data->>'side' = :rice", "UPDATE chimichanga SET data = json_remove(data, :filling0) WHERE data->>'side' = :rice",
RemoveFields::byFields('chimichanga', [Field::EQ('side', 'beans', ':rice')], RemoveFields::byFields('chimichanga', [Field::equal('side', 'beans', ':rice')],
Parameters::fieldNames(':filling', ['beef'])), Parameters::fieldNames(':filling', ['beef'])),
'UPDATE statement not correct'); 'UPDATE statement not correct');
} }

View File

@ -37,20 +37,23 @@ class QueryTest extends TestCase
public function testWhereByFieldsSucceedsForSingleField(): void public function testWhereByFieldsSucceedsForSingleField(): void
{ {
$this->assertEquals("data->>'test_field' <= :it", $this->assertEquals("data->>'test_field' <= :it",
Query::whereByFields([Field::LE('test_field', '', ':it')]), 'WHERE fragment not constructed correctly'); Query::whereByFields([Field::lessOrEqual('test_field', '', ':it')]),
'WHERE fragment not constructed correctly');
} }
public function testWhereByFieldsSucceedsForMultipleFieldsAll(): void public function testWhereByFieldsSucceedsForMultipleFieldsAll(): void
{ {
$this->assertEquals("data->>'test_field' <= :it AND data->>'other_field' = :other", $this->assertEquals("data->>'test_field' <= :it AND data->>'other_field' = :other",
Query::whereByFields([Field::LE('test_field', '', ':it'), Field::EQ('other_field', '', ':other')]), Query::whereByFields(
[Field::lessOrEqual('test_field', '', ':it'), Field::equal('other_field', '', ':other')]),
'WHERE fragment not constructed correctly'); 'WHERE fragment not constructed correctly');
} }
public function testWhereByFieldsSucceedsForMultipleFieldsAny(): void public function testWhereByFieldsSucceedsForMultipleFieldsAny(): void
{ {
$this->assertEquals("data->>'test_field' <= :it OR data->>'other_field' = :other", $this->assertEquals("data->>'test_field' <= :it OR data->>'other_field' = :other",
Query::whereByFields([Field::LE('test_field', '', ':it'), Field::EQ('other_field', '', ':other')], Query::whereByFields(
[Field::lessOrEqual('test_field', '', ':it'), Field::equal('other_field', '', ':other')],
FieldMatch::Any), FieldMatch::Any),
'WHERE fragment not constructed correctly'); 'WHERE fragment not constructed correctly');
} }