Compare commits
15 Commits
v1.0.0-bet
...
main
Author | SHA1 | Date | |
---|---|---|---|
9e0e663811 | |||
039283224a | |||
407441e857 | |||
3d2bc2a904 | |||
4d764cbb3f | |||
57d8f9ddc1 | |||
37fa200fa7 | |||
adbe4e6614 | |||
0659de3f99 | |||
d8330d828a | |||
1a37b009ea | |||
5201e564ca | |||
478684621c | |||
50854275a8 | |||
0c9490e394 |
|
@ -12,7 +12,7 @@ This library allows SQLite and PostgreSQL to be treated as document databases. I
|
||||||
|
|
||||||
### Connection Details
|
### Connection Details
|
||||||
|
|
||||||
The static variable `Configuration::$pdoDSN` must be set to the [PDO data source name](https://www.php.net/manual/en/pdo.construct.php#refsect1-pdo.construct-parameters) for your database. `Configuration` also has `$username`, `$password`, and `$options` variables that will be used to construct the PDO object it will use for data access.
|
The [PDO data source name](https://www.php.net/manual/en/pdo.construct.php#refsect1-pdo.construct-parameters) must be provided via `Configuration::useDSN()`. `Configuration` also has `$username`, `$password`, and `$options` variables that will be used to construct the PDO object it will use for data access.
|
||||||
|
|
||||||
### Document Identifiers
|
### Document Identifiers
|
||||||
|
|
||||||
|
@ -29,4 +29,4 @@ In all generated scenarios, if the ID value is not 0 or blank, that ID will be u
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Documentation for this library is not complete (writing it is one of the goals before the “beta” tag is dropped); however, its structure is very similar to the .NET version, so [its documentation will help](https://bitbadger.solutions/open-source/relational-documents/basic-usage.html) until its project specific documentation is developed. Things like `Count.All()` become `Count::all`, and all the `byField` operations are named `byFields` and take an array of fields.
|
Full documentation [is available on the project site](https://bitbadger.solutions/open-source/pdo-document/).
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "bit-badger/pdo-document",
|
"name": "bit-badger/pdo-document",
|
||||||
"description": "Treat SQLite (and soon PostgreSQL) as a document store",
|
"description": "Treat SQLite and PostgreSQL as document stores",
|
||||||
"keywords": ["database", "document", "sqlite", "pdo"],
|
"keywords": ["database", "document", "sqlite", "pdo", "postgresql"],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
@ -14,15 +14,19 @@
|
||||||
"support": {
|
"support": {
|
||||||
"email": "daniel@bitbadger.solutions",
|
"email": "daniel@bitbadger.solutions",
|
||||||
"source": "https://git.bitbadger.solutions/bit-badger/pdo-document",
|
"source": "https://git.bitbadger.solutions/bit-badger/pdo-document",
|
||||||
"rss": "https://git.bitbadger.solutions/bit-badger/pdo-document.rss"
|
"rss": "https://git.bitbadger.solutions/bit-badger/pdo-document.rss",
|
||||||
|
"docs": "https://bitbadger.solutions/open-source/pdo-document/"
|
||||||
},
|
},
|
||||||
|
"minimum-stability": "beta",
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=8.2",
|
"php": ">=8.2",
|
||||||
|
"bit-badger/inspired-by-fsharp": "^1",
|
||||||
"netresearch/jsonmapper": "^4",
|
"netresearch/jsonmapper": "^4",
|
||||||
"ext-pdo": "*"
|
"ext-pdo": "*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^11"
|
"phpunit/phpunit": "^11",
|
||||||
|
"square/pjson": "^0.5.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
@ -33,6 +37,7 @@
|
||||||
},
|
},
|
||||||
"autoload-dev": {
|
"autoload-dev": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
"Test\\": "./tests",
|
||||||
"Test\\Unit\\": "./tests/unit",
|
"Test\\Unit\\": "./tests/unit",
|
||||||
"Test\\Integration\\": "./tests/integration",
|
"Test\\Integration\\": "./tests/integration",
|
||||||
"Test\\Integration\\PostgreSQL\\": "./tests/integration/postgresql",
|
"Test\\Integration\\PostgreSQL\\": "./tests/integration/postgresql",
|
||||||
|
|
420
composer.lock
generated
420
composer.lock
generated
|
@ -4,8 +4,53 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "20bf0d96304e429b431535d05ff4585a",
|
"content-hash": "f3351c794dd1261ee4bf18380f58463d",
|
||||||
"packages": [
|
"packages": [
|
||||||
|
{
|
||||||
|
"name": "bit-badger/inspired-by-fsharp",
|
||||||
|
"version": "v1.0.0-beta2",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://git.bitbadger.solutions/bit-badger/inspired-by-fsharp",
|
||||||
|
"reference": "fad428a4e40b606987499b17bb2d5b7d4b04502d"
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": "^8.2"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpoption/phpoption": "^1",
|
||||||
|
"phpunit/phpunit": "^11"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"BitBadger\\InspiredByFSharp\\": "./src"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Daniel J. Summers",
|
||||||
|
"email": "daniel@bitbadger.solutions",
|
||||||
|
"homepage": "https://bitbadger.solutions",
|
||||||
|
"role": "Developer"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "PHP utility classes whose functionality is inspired by their F# counterparts",
|
||||||
|
"keywords": [
|
||||||
|
"option",
|
||||||
|
"result"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"email": "daniel@bitbadger.solutions",
|
||||||
|
"rss": "https://git.bitbadger.solutions/bit-badger/inspired-by-fsharp.rss",
|
||||||
|
"source": "https://git.bitbadger.solutions/bit-badger/inspired-by-fsharp"
|
||||||
|
},
|
||||||
|
"time": "2024-07-29T17:58:33+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "netresearch/jsonmapper",
|
"name": "netresearch/jsonmapper",
|
||||||
"version": "v4.4.1",
|
"version": "v4.4.1",
|
||||||
|
@ -61,16 +106,16 @@
|
||||||
"packages-dev": [
|
"packages-dev": [
|
||||||
{
|
{
|
||||||
"name": "myclabs/deep-copy",
|
"name": "myclabs/deep-copy",
|
||||||
"version": "1.11.1",
|
"version": "1.12.0",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/myclabs/DeepCopy.git",
|
"url": "https://github.com/myclabs/DeepCopy.git",
|
||||||
"reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c"
|
"reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/7284c22080590fb39f2ffa3e9057f10a4ddd0e0c",
|
"url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c",
|
||||||
"reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c",
|
"reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -78,11 +123,12 @@
|
||||||
},
|
},
|
||||||
"conflict": {
|
"conflict": {
|
||||||
"doctrine/collections": "<1.6.8",
|
"doctrine/collections": "<1.6.8",
|
||||||
"doctrine/common": "<2.13.3 || >=3,<3.2.2"
|
"doctrine/common": "<2.13.3 || >=3 <3.2.2"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"doctrine/collections": "^1.6.8",
|
"doctrine/collections": "^1.6.8",
|
||||||
"doctrine/common": "^2.13.3 || ^3.2.2",
|
"doctrine/common": "^2.13.3 || ^3.2.2",
|
||||||
|
"phpspec/prophecy": "^1.10",
|
||||||
"phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13"
|
"phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13"
|
||||||
},
|
},
|
||||||
"type": "library",
|
"type": "library",
|
||||||
|
@ -108,7 +154,7 @@
|
||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/myclabs/DeepCopy/issues",
|
"issues": "https://github.com/myclabs/DeepCopy/issues",
|
||||||
"source": "https://github.com/myclabs/DeepCopy/tree/1.11.1"
|
"source": "https://github.com/myclabs/DeepCopy/tree/1.12.0"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -116,20 +162,20 @@
|
||||||
"type": "tidelift"
|
"type": "tidelift"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2023-03-08T13:26:56+00:00"
|
"time": "2024-06-12T14:39:25+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "nikic/php-parser",
|
"name": "nikic/php-parser",
|
||||||
"version": "v5.0.2",
|
"version": "v5.1.0",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/nikic/PHP-Parser.git",
|
"url": "https://github.com/nikic/PHP-Parser.git",
|
||||||
"reference": "139676794dc1e9231bf7bcd123cfc0c99182cb13"
|
"reference": "683130c2ff8c2739f4822ff7ac5c873ec529abd1"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/139676794dc1e9231bf7bcd123cfc0c99182cb13",
|
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/683130c2ff8c2739f4822ff7ac5c873ec529abd1",
|
||||||
"reference": "139676794dc1e9231bf7bcd123cfc0c99182cb13",
|
"reference": "683130c2ff8c2739f4822ff7ac5c873ec529abd1",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -140,7 +186,7 @@
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"ircmaxell/php-yacc": "^0.0.7",
|
"ircmaxell/php-yacc": "^0.0.7",
|
||||||
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0"
|
"phpunit/phpunit": "^9.0"
|
||||||
},
|
},
|
||||||
"bin": [
|
"bin": [
|
||||||
"bin/php-parse"
|
"bin/php-parse"
|
||||||
|
@ -172,9 +218,9 @@
|
||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/nikic/PHP-Parser/issues",
|
"issues": "https://github.com/nikic/PHP-Parser/issues",
|
||||||
"source": "https://github.com/nikic/PHP-Parser/tree/v5.0.2"
|
"source": "https://github.com/nikic/PHP-Parser/tree/v5.1.0"
|
||||||
},
|
},
|
||||||
"time": "2024-03-05T20:51:40+00:00"
|
"time": "2024-07-01T20:03:41+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phar-io/manifest",
|
"name": "phar-io/manifest",
|
||||||
|
@ -296,16 +342,16 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpunit/php-code-coverage",
|
"name": "phpunit/php-code-coverage",
|
||||||
"version": "11.0.3",
|
"version": "11.0.5",
|
||||||
"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": "7e35a2cbcabac0e6865fd373742ea432a3c34f92"
|
"reference": "19b6365ab8b59a64438c0c3f4241feeb480c9861"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/7e35a2cbcabac0e6865fd373742ea432a3c34f92",
|
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/19b6365ab8b59a64438c0c3f4241feeb480c9861",
|
||||||
"reference": "7e35a2cbcabac0e6865fd373742ea432a3c34f92",
|
"reference": "19b6365ab8b59a64438c0c3f4241feeb480c9861",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -362,7 +408,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.3"
|
"source": "https://github.com/sebastianbergmann/php-code-coverage/tree/11.0.5"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -370,20 +416,20 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2024-03-12T15:35:40+00:00"
|
"time": "2024-07-03T05:05:37+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpunit/php-file-iterator",
|
"name": "phpunit/php-file-iterator",
|
||||||
"version": "5.0.0",
|
"version": "5.0.1",
|
||||||
"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": "99e95c94ad9500daca992354fa09d7b99abe2210"
|
"reference": "6ed896bf50bbbfe4d504a33ed5886278c78e4a26"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/99e95c94ad9500daca992354fa09d7b99abe2210",
|
"url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/6ed896bf50bbbfe4d504a33ed5886278c78e4a26",
|
||||||
"reference": "99e95c94ad9500daca992354fa09d7b99abe2210",
|
"reference": "6ed896bf50bbbfe4d504a33ed5886278c78e4a26",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -423,7 +469,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.0"
|
"source": "https://github.com/sebastianbergmann/php-file-iterator/tree/5.0.1"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -431,20 +477,20 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2024-02-02T06:05:04+00:00"
|
"time": "2024-07-03T05:06:37+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpunit/php-invoker",
|
"name": "phpunit/php-invoker",
|
||||||
"version": "5.0.0",
|
"version": "5.0.1",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/php-invoker.git",
|
"url": "https://github.com/sebastianbergmann/php-invoker.git",
|
||||||
"reference": "5d8d9355a16d8cc5a1305b0a85342cfa420612be"
|
"reference": "c1ca3814734c07492b3d4c5f794f4b0995333da2"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/5d8d9355a16d8cc5a1305b0a85342cfa420612be",
|
"url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/c1ca3814734c07492b3d4c5f794f4b0995333da2",
|
||||||
"reference": "5d8d9355a16d8cc5a1305b0a85342cfa420612be",
|
"reference": "c1ca3814734c07492b3d4c5f794f4b0995333da2",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -487,7 +533,7 @@
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/sebastianbergmann/php-invoker/issues",
|
"issues": "https://github.com/sebastianbergmann/php-invoker/issues",
|
||||||
"security": "https://github.com/sebastianbergmann/php-invoker/security/policy",
|
"security": "https://github.com/sebastianbergmann/php-invoker/security/policy",
|
||||||
"source": "https://github.com/sebastianbergmann/php-invoker/tree/5.0.0"
|
"source": "https://github.com/sebastianbergmann/php-invoker/tree/5.0.1"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -495,20 +541,20 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2024-02-02T06:05:50+00:00"
|
"time": "2024-07-03T05:07:44+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpunit/php-text-template",
|
"name": "phpunit/php-text-template",
|
||||||
"version": "4.0.0",
|
"version": "4.0.1",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/php-text-template.git",
|
"url": "https://github.com/sebastianbergmann/php-text-template.git",
|
||||||
"reference": "d38f6cbff1cdb6f40b03c9811421561668cc133e"
|
"reference": "3e0404dc6b300e6bf56415467ebcb3fe4f33e964"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/d38f6cbff1cdb6f40b03c9811421561668cc133e",
|
"url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/3e0404dc6b300e6bf56415467ebcb3fe4f33e964",
|
||||||
"reference": "d38f6cbff1cdb6f40b03c9811421561668cc133e",
|
"reference": "3e0404dc6b300e6bf56415467ebcb3fe4f33e964",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -547,7 +593,7 @@
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/sebastianbergmann/php-text-template/issues",
|
"issues": "https://github.com/sebastianbergmann/php-text-template/issues",
|
||||||
"security": "https://github.com/sebastianbergmann/php-text-template/security/policy",
|
"security": "https://github.com/sebastianbergmann/php-text-template/security/policy",
|
||||||
"source": "https://github.com/sebastianbergmann/php-text-template/tree/4.0.0"
|
"source": "https://github.com/sebastianbergmann/php-text-template/tree/4.0.1"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -555,20 +601,20 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2024-02-02T06:06:56+00:00"
|
"time": "2024-07-03T05:08:43+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpunit/php-timer",
|
"name": "phpunit/php-timer",
|
||||||
"version": "7.0.0",
|
"version": "7.0.1",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/php-timer.git",
|
"url": "https://github.com/sebastianbergmann/php-timer.git",
|
||||||
"reference": "8a59d9e25720482ee7fcdf296595e08795b84dc5"
|
"reference": "3b415def83fbcb41f991d9ebf16ae4ad8b7837b3"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/8a59d9e25720482ee7fcdf296595e08795b84dc5",
|
"url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3b415def83fbcb41f991d9ebf16ae4ad8b7837b3",
|
||||||
"reference": "8a59d9e25720482ee7fcdf296595e08795b84dc5",
|
"reference": "3b415def83fbcb41f991d9ebf16ae4ad8b7837b3",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -607,7 +653,7 @@
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/sebastianbergmann/php-timer/issues",
|
"issues": "https://github.com/sebastianbergmann/php-timer/issues",
|
||||||
"security": "https://github.com/sebastianbergmann/php-timer/security/policy",
|
"security": "https://github.com/sebastianbergmann/php-timer/security/policy",
|
||||||
"source": "https://github.com/sebastianbergmann/php-timer/tree/7.0.0"
|
"source": "https://github.com/sebastianbergmann/php-timer/tree/7.0.1"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -615,20 +661,20 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2024-02-02T06:08:01+00:00"
|
"time": "2024-07-03T05:09:35+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpunit/phpunit",
|
"name": "phpunit/phpunit",
|
||||||
"version": "11.2.1",
|
"version": "11.2.8",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/phpunit.git",
|
"url": "https://github.com/sebastianbergmann/phpunit.git",
|
||||||
"reference": "1b8775732e9c401bda32df3ffbdf90dec7533ceb"
|
"reference": "a7a29e8d3113806f18f99d670f580a30e8ffff39"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1b8775732e9c401bda32df3ffbdf90dec7533ceb",
|
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a7a29e8d3113806f18f99d670f580a30e8ffff39",
|
||||||
"reference": "1b8775732e9c401bda32df3ffbdf90dec7533ceb",
|
"reference": "a7a29e8d3113806f18f99d670f580a30e8ffff39",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -638,25 +684,25 @@
|
||||||
"ext-mbstring": "*",
|
"ext-mbstring": "*",
|
||||||
"ext-xml": "*",
|
"ext-xml": "*",
|
||||||
"ext-xmlwriter": "*",
|
"ext-xmlwriter": "*",
|
||||||
"myclabs/deep-copy": "^1.10.1",
|
"myclabs/deep-copy": "^1.12.0",
|
||||||
"phar-io/manifest": "^2.0.3",
|
"phar-io/manifest": "^2.0.4",
|
||||||
"phar-io/version": "^3.0.2",
|
"phar-io/version": "^3.2.1",
|
||||||
"php": ">=8.2",
|
"php": ">=8.2",
|
||||||
"phpunit/php-code-coverage": "^11.0",
|
"phpunit/php-code-coverage": "^11.0.5",
|
||||||
"phpunit/php-file-iterator": "^5.0",
|
"phpunit/php-file-iterator": "^5.0.1",
|
||||||
"phpunit/php-invoker": "^5.0",
|
"phpunit/php-invoker": "^5.0.1",
|
||||||
"phpunit/php-text-template": "^4.0",
|
"phpunit/php-text-template": "^4.0.1",
|
||||||
"phpunit/php-timer": "^7.0",
|
"phpunit/php-timer": "^7.0.1",
|
||||||
"sebastian/cli-parser": "^3.0",
|
"sebastian/cli-parser": "^3.0.2",
|
||||||
"sebastian/code-unit": "^3.0",
|
"sebastian/code-unit": "^3.0.1",
|
||||||
"sebastian/comparator": "^6.0",
|
"sebastian/comparator": "^6.0.1",
|
||||||
"sebastian/diff": "^6.0",
|
"sebastian/diff": "^6.0.2",
|
||||||
"sebastian/environment": "^7.0",
|
"sebastian/environment": "^7.2.0",
|
||||||
"sebastian/exporter": "^6.0",
|
"sebastian/exporter": "^6.1.3",
|
||||||
"sebastian/global-state": "^7.0",
|
"sebastian/global-state": "^7.0.2",
|
||||||
"sebastian/object-enumerator": "^6.0",
|
"sebastian/object-enumerator": "^6.0.1",
|
||||||
"sebastian/type": "^5.0",
|
"sebastian/type": "^5.0.1",
|
||||||
"sebastian/version": "^5.0"
|
"sebastian/version": "^5.0.1"
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
"ext-soap": "To be able to generate mocks based on WSDL files"
|
"ext-soap": "To be able to generate mocks based on WSDL files"
|
||||||
|
@ -699,7 +745,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.1"
|
"source": "https://github.com/sebastianbergmann/phpunit/tree/11.2.8"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -715,20 +761,20 @@
|
||||||
"type": "tidelift"
|
"type": "tidelift"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2024-06-11T07:30:35+00:00"
|
"time": "2024-07-18T14:56:37+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sebastian/cli-parser",
|
"name": "sebastian/cli-parser",
|
||||||
"version": "3.0.1",
|
"version": "3.0.2",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/cli-parser.git",
|
"url": "https://github.com/sebastianbergmann/cli-parser.git",
|
||||||
"reference": "00a74d5568694711f0222e54fb281e1d15fdf04a"
|
"reference": "15c5dd40dc4f38794d383bb95465193f5e0ae180"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/00a74d5568694711f0222e54fb281e1d15fdf04a",
|
"url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/15c5dd40dc4f38794d383bb95465193f5e0ae180",
|
||||||
"reference": "00a74d5568694711f0222e54fb281e1d15fdf04a",
|
"reference": "15c5dd40dc4f38794d383bb95465193f5e0ae180",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -764,7 +810,7 @@
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/sebastianbergmann/cli-parser/issues",
|
"issues": "https://github.com/sebastianbergmann/cli-parser/issues",
|
||||||
"security": "https://github.com/sebastianbergmann/cli-parser/security/policy",
|
"security": "https://github.com/sebastianbergmann/cli-parser/security/policy",
|
||||||
"source": "https://github.com/sebastianbergmann/cli-parser/tree/3.0.1"
|
"source": "https://github.com/sebastianbergmann/cli-parser/tree/3.0.2"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -772,20 +818,20 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2024-03-02T07:26:58+00:00"
|
"time": "2024-07-03T04:41:36+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sebastian/code-unit",
|
"name": "sebastian/code-unit",
|
||||||
"version": "3.0.0",
|
"version": "3.0.1",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/code-unit.git",
|
"url": "https://github.com/sebastianbergmann/code-unit.git",
|
||||||
"reference": "6634549cb8d702282a04a774e36a7477d2bd9015"
|
"reference": "6bb7d09d6623567178cf54126afa9c2310114268"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/6634549cb8d702282a04a774e36a7477d2bd9015",
|
"url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/6bb7d09d6623567178cf54126afa9c2310114268",
|
||||||
"reference": "6634549cb8d702282a04a774e36a7477d2bd9015",
|
"reference": "6bb7d09d6623567178cf54126afa9c2310114268",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -821,7 +867,7 @@
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/sebastianbergmann/code-unit/issues",
|
"issues": "https://github.com/sebastianbergmann/code-unit/issues",
|
||||||
"security": "https://github.com/sebastianbergmann/code-unit/security/policy",
|
"security": "https://github.com/sebastianbergmann/code-unit/security/policy",
|
||||||
"source": "https://github.com/sebastianbergmann/code-unit/tree/3.0.0"
|
"source": "https://github.com/sebastianbergmann/code-unit/tree/3.0.1"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -829,20 +875,20 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2024-02-02T05:50:41+00:00"
|
"time": "2024-07-03T04:44:28+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sebastian/code-unit-reverse-lookup",
|
"name": "sebastian/code-unit-reverse-lookup",
|
||||||
"version": "4.0.0",
|
"version": "4.0.1",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git",
|
"url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git",
|
||||||
"reference": "df80c875d3e459b45c6039e4d9b71d4fbccae25d"
|
"reference": "183a9b2632194febd219bb9246eee421dad8d45e"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/df80c875d3e459b45c6039e4d9b71d4fbccae25d",
|
"url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/183a9b2632194febd219bb9246eee421dad8d45e",
|
||||||
"reference": "df80c875d3e459b45c6039e4d9b71d4fbccae25d",
|
"reference": "183a9b2632194febd219bb9246eee421dad8d45e",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -877,7 +923,7 @@
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues",
|
"issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues",
|
||||||
"security": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/security/policy",
|
"security": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/security/policy",
|
||||||
"source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/4.0.0"
|
"source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/4.0.1"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -885,20 +931,20 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2024-02-02T05:52:17+00:00"
|
"time": "2024-07-03T04:45:54+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sebastian/comparator",
|
"name": "sebastian/comparator",
|
||||||
"version": "6.0.0",
|
"version": "6.0.1",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/comparator.git",
|
"url": "https://github.com/sebastianbergmann/comparator.git",
|
||||||
"reference": "bd0f2fa5b9257c69903537b266ccb80fcf940db8"
|
"reference": "131942b86d3587291067a94f295498ab6ac79c20"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/bd0f2fa5b9257c69903537b266ccb80fcf940db8",
|
"url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/131942b86d3587291067a94f295498ab6ac79c20",
|
||||||
"reference": "bd0f2fa5b9257c69903537b266ccb80fcf940db8",
|
"reference": "131942b86d3587291067a94f295498ab6ac79c20",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -954,7 +1000,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.0"
|
"source": "https://github.com/sebastianbergmann/comparator/tree/6.0.1"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -962,20 +1008,20 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2024-02-02T05:53:45+00:00"
|
"time": "2024-07-03T04:48:07+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sebastian/complexity",
|
"name": "sebastian/complexity",
|
||||||
"version": "4.0.0",
|
"version": "4.0.1",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/complexity.git",
|
"url": "https://github.com/sebastianbergmann/complexity.git",
|
||||||
"reference": "88a434ad86150e11a606ac4866b09130712671f0"
|
"reference": "ee41d384ab1906c68852636b6de493846e13e5a0"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/88a434ad86150e11a606ac4866b09130712671f0",
|
"url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/ee41d384ab1906c68852636b6de493846e13e5a0",
|
||||||
"reference": "88a434ad86150e11a606ac4866b09130712671f0",
|
"reference": "ee41d384ab1906c68852636b6de493846e13e5a0",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -1012,7 +1058,7 @@
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/sebastianbergmann/complexity/issues",
|
"issues": "https://github.com/sebastianbergmann/complexity/issues",
|
||||||
"security": "https://github.com/sebastianbergmann/complexity/security/policy",
|
"security": "https://github.com/sebastianbergmann/complexity/security/policy",
|
||||||
"source": "https://github.com/sebastianbergmann/complexity/tree/4.0.0"
|
"source": "https://github.com/sebastianbergmann/complexity/tree/4.0.1"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -1020,20 +1066,20 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2024-02-02T05:55:19+00:00"
|
"time": "2024-07-03T04:49:50+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sebastian/diff",
|
"name": "sebastian/diff",
|
||||||
"version": "6.0.1",
|
"version": "6.0.2",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/diff.git",
|
"url": "https://github.com/sebastianbergmann/diff.git",
|
||||||
"reference": "ab83243ecc233de5655b76f577711de9f842e712"
|
"reference": "b4ccd857127db5d41a5b676f24b51371d76d8544"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/ab83243ecc233de5655b76f577711de9f842e712",
|
"url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/b4ccd857127db5d41a5b676f24b51371d76d8544",
|
||||||
"reference": "ab83243ecc233de5655b76f577711de9f842e712",
|
"reference": "b4ccd857127db5d41a5b676f24b51371d76d8544",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -1079,7 +1125,7 @@
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/sebastianbergmann/diff/issues",
|
"issues": "https://github.com/sebastianbergmann/diff/issues",
|
||||||
"security": "https://github.com/sebastianbergmann/diff/security/policy",
|
"security": "https://github.com/sebastianbergmann/diff/security/policy",
|
||||||
"source": "https://github.com/sebastianbergmann/diff/tree/6.0.1"
|
"source": "https://github.com/sebastianbergmann/diff/tree/6.0.2"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -1087,20 +1133,20 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2024-03-02T07:30:33+00:00"
|
"time": "2024-07-03T04:53:05+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sebastian/environment",
|
"name": "sebastian/environment",
|
||||||
"version": "7.1.0",
|
"version": "7.2.0",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/environment.git",
|
"url": "https://github.com/sebastianbergmann/environment.git",
|
||||||
"reference": "4eb3a442574d0e9d141aab209cd4aaf25701b09a"
|
"reference": "855f3ae0ab316bbafe1ba4e16e9f3c078d24a0c5"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/4eb3a442574d0e9d141aab209cd4aaf25701b09a",
|
"url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/855f3ae0ab316bbafe1ba4e16e9f3c078d24a0c5",
|
||||||
"reference": "4eb3a442574d0e9d141aab209cd4aaf25701b09a",
|
"reference": "855f3ae0ab316bbafe1ba4e16e9f3c078d24a0c5",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -1115,7 +1161,7 @@
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"extra": {
|
"extra": {
|
||||||
"branch-alias": {
|
"branch-alias": {
|
||||||
"dev-main": "7.1-dev"
|
"dev-main": "7.2-dev"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
@ -1143,7 +1189,7 @@
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/sebastianbergmann/environment/issues",
|
"issues": "https://github.com/sebastianbergmann/environment/issues",
|
||||||
"security": "https://github.com/sebastianbergmann/environment/security/policy",
|
"security": "https://github.com/sebastianbergmann/environment/security/policy",
|
||||||
"source": "https://github.com/sebastianbergmann/environment/tree/7.1.0"
|
"source": "https://github.com/sebastianbergmann/environment/tree/7.2.0"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -1151,20 +1197,20 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2024-03-23T08:56:34+00:00"
|
"time": "2024-07-03T04:54:44+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sebastian/exporter",
|
"name": "sebastian/exporter",
|
||||||
"version": "6.0.1",
|
"version": "6.1.3",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/exporter.git",
|
"url": "https://github.com/sebastianbergmann/exporter.git",
|
||||||
"reference": "f291e5a317c321c0381fa9ecc796fa2d21b186da"
|
"reference": "c414673eee9a8f9d51bbf8d61fc9e3ef1e85b20e"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/f291e5a317c321c0381fa9ecc796fa2d21b186da",
|
"url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/c414673eee9a8f9d51bbf8d61fc9e3ef1e85b20e",
|
||||||
"reference": "f291e5a317c321c0381fa9ecc796fa2d21b186da",
|
"reference": "c414673eee9a8f9d51bbf8d61fc9e3ef1e85b20e",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -1173,12 +1219,12 @@
|
||||||
"sebastian/recursion-context": "^6.0"
|
"sebastian/recursion-context": "^6.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^11.0"
|
"phpunit/phpunit": "^11.2"
|
||||||
},
|
},
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"extra": {
|
"extra": {
|
||||||
"branch-alias": {
|
"branch-alias": {
|
||||||
"dev-main": "6.0-dev"
|
"dev-main": "6.1-dev"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
@ -1221,7 +1267,7 @@
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/sebastianbergmann/exporter/issues",
|
"issues": "https://github.com/sebastianbergmann/exporter/issues",
|
||||||
"security": "https://github.com/sebastianbergmann/exporter/security/policy",
|
"security": "https://github.com/sebastianbergmann/exporter/security/policy",
|
||||||
"source": "https://github.com/sebastianbergmann/exporter/tree/6.0.1"
|
"source": "https://github.com/sebastianbergmann/exporter/tree/6.1.3"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -1229,20 +1275,20 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2024-03-02T07:28:20+00:00"
|
"time": "2024-07-03T04:56:19+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sebastian/global-state",
|
"name": "sebastian/global-state",
|
||||||
"version": "7.0.1",
|
"version": "7.0.2",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/global-state.git",
|
"url": "https://github.com/sebastianbergmann/global-state.git",
|
||||||
"reference": "c3a307e832f2e69c7ef869e31fc644fde0e7cb3e"
|
"reference": "3be331570a721f9a4b5917f4209773de17f747d7"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/c3a307e832f2e69c7ef869e31fc644fde0e7cb3e",
|
"url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/3be331570a721f9a4b5917f4209773de17f747d7",
|
||||||
"reference": "c3a307e832f2e69c7ef869e31fc644fde0e7cb3e",
|
"reference": "3be331570a721f9a4b5917f4209773de17f747d7",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -1283,7 +1329,7 @@
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/sebastianbergmann/global-state/issues",
|
"issues": "https://github.com/sebastianbergmann/global-state/issues",
|
||||||
"security": "https://github.com/sebastianbergmann/global-state/security/policy",
|
"security": "https://github.com/sebastianbergmann/global-state/security/policy",
|
||||||
"source": "https://github.com/sebastianbergmann/global-state/tree/7.0.1"
|
"source": "https://github.com/sebastianbergmann/global-state/tree/7.0.2"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -1291,20 +1337,20 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2024-03-02T07:32:10+00:00"
|
"time": "2024-07-03T04:57:36+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sebastian/lines-of-code",
|
"name": "sebastian/lines-of-code",
|
||||||
"version": "3.0.0",
|
"version": "3.0.1",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/lines-of-code.git",
|
"url": "https://github.com/sebastianbergmann/lines-of-code.git",
|
||||||
"reference": "376c5b3f6b43c78fdc049740bca76a7c846706c0"
|
"reference": "d36ad0d782e5756913e42ad87cb2890f4ffe467a"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/376c5b3f6b43c78fdc049740bca76a7c846706c0",
|
"url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/d36ad0d782e5756913e42ad87cb2890f4ffe467a",
|
||||||
"reference": "376c5b3f6b43c78fdc049740bca76a7c846706c0",
|
"reference": "d36ad0d782e5756913e42ad87cb2890f4ffe467a",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -1341,7 +1387,7 @@
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/sebastianbergmann/lines-of-code/issues",
|
"issues": "https://github.com/sebastianbergmann/lines-of-code/issues",
|
||||||
"security": "https://github.com/sebastianbergmann/lines-of-code/security/policy",
|
"security": "https://github.com/sebastianbergmann/lines-of-code/security/policy",
|
||||||
"source": "https://github.com/sebastianbergmann/lines-of-code/tree/3.0.0"
|
"source": "https://github.com/sebastianbergmann/lines-of-code/tree/3.0.1"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -1349,20 +1395,20 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2024-02-02T06:00:36+00:00"
|
"time": "2024-07-03T04:58:38+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sebastian/object-enumerator",
|
"name": "sebastian/object-enumerator",
|
||||||
"version": "6.0.0",
|
"version": "6.0.1",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/object-enumerator.git",
|
"url": "https://github.com/sebastianbergmann/object-enumerator.git",
|
||||||
"reference": "f75f6c460da0bbd9668f43a3dde0ec0ba7faa678"
|
"reference": "f5b498e631a74204185071eb41f33f38d64608aa"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/f75f6c460da0bbd9668f43a3dde0ec0ba7faa678",
|
"url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/f5b498e631a74204185071eb41f33f38d64608aa",
|
||||||
"reference": "f75f6c460da0bbd9668f43a3dde0ec0ba7faa678",
|
"reference": "f5b498e631a74204185071eb41f33f38d64608aa",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -1399,7 +1445,7 @@
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/sebastianbergmann/object-enumerator/issues",
|
"issues": "https://github.com/sebastianbergmann/object-enumerator/issues",
|
||||||
"security": "https://github.com/sebastianbergmann/object-enumerator/security/policy",
|
"security": "https://github.com/sebastianbergmann/object-enumerator/security/policy",
|
||||||
"source": "https://github.com/sebastianbergmann/object-enumerator/tree/6.0.0"
|
"source": "https://github.com/sebastianbergmann/object-enumerator/tree/6.0.1"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -1407,20 +1453,20 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2024-02-02T06:01:29+00:00"
|
"time": "2024-07-03T05:00:13+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sebastian/object-reflector",
|
"name": "sebastian/object-reflector",
|
||||||
"version": "4.0.0",
|
"version": "4.0.1",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/object-reflector.git",
|
"url": "https://github.com/sebastianbergmann/object-reflector.git",
|
||||||
"reference": "bb2a6255d30853425fd38f032eb64ced9f7f132d"
|
"reference": "6e1a43b411b2ad34146dee7524cb13a068bb35f9"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/bb2a6255d30853425fd38f032eb64ced9f7f132d",
|
"url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/6e1a43b411b2ad34146dee7524cb13a068bb35f9",
|
||||||
"reference": "bb2a6255d30853425fd38f032eb64ced9f7f132d",
|
"reference": "6e1a43b411b2ad34146dee7524cb13a068bb35f9",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -1455,7 +1501,7 @@
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/sebastianbergmann/object-reflector/issues",
|
"issues": "https://github.com/sebastianbergmann/object-reflector/issues",
|
||||||
"security": "https://github.com/sebastianbergmann/object-reflector/security/policy",
|
"security": "https://github.com/sebastianbergmann/object-reflector/security/policy",
|
||||||
"source": "https://github.com/sebastianbergmann/object-reflector/tree/4.0.0"
|
"source": "https://github.com/sebastianbergmann/object-reflector/tree/4.0.1"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -1463,20 +1509,20 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2024-02-02T06:02:18+00:00"
|
"time": "2024-07-03T05:01:32+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sebastian/recursion-context",
|
"name": "sebastian/recursion-context",
|
||||||
"version": "6.0.0",
|
"version": "6.0.2",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/recursion-context.git",
|
"url": "https://github.com/sebastianbergmann/recursion-context.git",
|
||||||
"reference": "b75224967b5a466925c6d54e68edd0edf8dd4ed4"
|
"reference": "694d156164372abbd149a4b85ccda2e4670c0e16"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/b75224967b5a466925c6d54e68edd0edf8dd4ed4",
|
"url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/694d156164372abbd149a4b85ccda2e4670c0e16",
|
||||||
"reference": "b75224967b5a466925c6d54e68edd0edf8dd4ed4",
|
"reference": "694d156164372abbd149a4b85ccda2e4670c0e16",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -1519,7 +1565,7 @@
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/sebastianbergmann/recursion-context/issues",
|
"issues": "https://github.com/sebastianbergmann/recursion-context/issues",
|
||||||
"security": "https://github.com/sebastianbergmann/recursion-context/security/policy",
|
"security": "https://github.com/sebastianbergmann/recursion-context/security/policy",
|
||||||
"source": "https://github.com/sebastianbergmann/recursion-context/tree/6.0.0"
|
"source": "https://github.com/sebastianbergmann/recursion-context/tree/6.0.2"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -1527,20 +1573,20 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2024-02-02T06:08:48+00:00"
|
"time": "2024-07-03T05:10:34+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sebastian/type",
|
"name": "sebastian/type",
|
||||||
"version": "5.0.0",
|
"version": "5.0.1",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/type.git",
|
"url": "https://github.com/sebastianbergmann/type.git",
|
||||||
"reference": "b8502785eb3523ca0dd4afe9ca62235590020f3f"
|
"reference": "fb6a6566f9589e86661291d13eba708cce5eb4aa"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/type/zipball/b8502785eb3523ca0dd4afe9ca62235590020f3f",
|
"url": "https://api.github.com/repos/sebastianbergmann/type/zipball/fb6a6566f9589e86661291d13eba708cce5eb4aa",
|
||||||
"reference": "b8502785eb3523ca0dd4afe9ca62235590020f3f",
|
"reference": "fb6a6566f9589e86661291d13eba708cce5eb4aa",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -1576,7 +1622,7 @@
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/sebastianbergmann/type/issues",
|
"issues": "https://github.com/sebastianbergmann/type/issues",
|
||||||
"security": "https://github.com/sebastianbergmann/type/security/policy",
|
"security": "https://github.com/sebastianbergmann/type/security/policy",
|
||||||
"source": "https://github.com/sebastianbergmann/type/tree/5.0.0"
|
"source": "https://github.com/sebastianbergmann/type/tree/5.0.1"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -1584,20 +1630,20 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2024-02-02T06:09:34+00:00"
|
"time": "2024-07-03T05:11:49+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sebastian/version",
|
"name": "sebastian/version",
|
||||||
"version": "5.0.0",
|
"version": "5.0.1",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/version.git",
|
"url": "https://github.com/sebastianbergmann/version.git",
|
||||||
"reference": "13999475d2cb1ab33cb73403ba356a814fdbb001"
|
"reference": "45c9debb7d039ce9b97de2f749c2cf5832a06ac4"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/version/zipball/13999475d2cb1ab33cb73403ba356a814fdbb001",
|
"url": "https://api.github.com/repos/sebastianbergmann/version/zipball/45c9debb7d039ce9b97de2f749c2cf5832a06ac4",
|
||||||
"reference": "13999475d2cb1ab33cb73403ba356a814fdbb001",
|
"reference": "45c9debb7d039ce9b97de2f749c2cf5832a06ac4",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -1630,7 +1676,7 @@
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/sebastianbergmann/version/issues",
|
"issues": "https://github.com/sebastianbergmann/version/issues",
|
||||||
"security": "https://github.com/sebastianbergmann/version/security/policy",
|
"security": "https://github.com/sebastianbergmann/version/security/policy",
|
||||||
"source": "https://github.com/sebastianbergmann/version/tree/5.0.0"
|
"source": "https://github.com/sebastianbergmann/version/tree/5.0.1"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -1638,7 +1684,55 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2024-02-02T06:10:47+00:00"
|
"time": "2024-07-03T05:13:08+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "square/pjson",
|
||||||
|
"version": "v0.5.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/square/pjson.git",
|
||||||
|
"reference": "cf9f9a7810ad7287b30658f60c0bbbba80217319"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/square/pjson/zipball/cf9f9a7810ad7287b30658f60c0bbbba80217319",
|
||||||
|
"reference": "cf9f9a7810ad7287b30658f60c0bbbba80217319",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=8.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"orchestra/testbench": "^7.11",
|
||||||
|
"phpstan/phpstan": "^1.8",
|
||||||
|
"phpunit/phpunit": "^9.5",
|
||||||
|
"squizlabs/php_codesniffer": "^3.7",
|
||||||
|
"symfony/var-dumper": "^6.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Square\\Pjson\\": "src/",
|
||||||
|
"Square\\Pjson\\Tests\\": "tests/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"Apache-2.0"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Seb",
|
||||||
|
"email": "sebastien@squareup.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Library for JSON <=> PHP model serialization / deserialization. Deserialize JSON directly into your object model PHP classes.",
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/square/pjson/issues",
|
||||||
|
"source": "https://github.com/square/pjson/tree/v0.5.0"
|
||||||
|
},
|
||||||
|
"time": "2024-03-15T18:19:22+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "theseer/tokenizer",
|
"name": "theseer/tokenizer",
|
||||||
|
@ -1692,7 +1786,7 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"aliases": [],
|
"aliases": [],
|
||||||
"minimum-stability": "stable",
|
"minimum-stability": "beta",
|
||||||
"stability-flags": [],
|
"stability-flags": [],
|
||||||
"prefer-stable": false,
|
"prefer-stable": false,
|
||||||
"prefer-lowest": false,
|
"prefer-lowest": false,
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument;
|
namespace BitBadger\PDODocument;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,15 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument;
|
namespace BitBadger\PDODocument;
|
||||||
|
|
||||||
|
use BitBadger\InspiredByFSharp\Option;
|
||||||
|
use Exception;
|
||||||
use PDO;
|
use PDO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,9 +28,6 @@ class Configuration
|
||||||
*/
|
*/
|
||||||
public static int $idStringLength = 16;
|
public static int $idStringLength = 16;
|
||||||
|
|
||||||
/** @var string The data source name (DSN) of the connection string */
|
|
||||||
public static string $pdoDSN = '';
|
|
||||||
|
|
||||||
/** @var string|null The username to use to establish a data connection (use env PDO_DOC_USERNAME if possible) */
|
/** @var string|null The username to use to establish a data connection (use env PDO_DOC_USERNAME if possible) */
|
||||||
public static ?string $username = null;
|
public static ?string $username = null;
|
||||||
|
|
||||||
|
@ -32,39 +37,69 @@ class Configuration
|
||||||
/** @var array|null Options to use for connections (driver-specific) */
|
/** @var array|null Options to use for connections (driver-specific) */
|
||||||
public static ?array $options = null;
|
public static ?array $options = null;
|
||||||
|
|
||||||
/** @var Mode|null The mode in which the library is operating (filled after first connection if not configured) */
|
/** @var Option<Mode> The mode in which the library is operating */
|
||||||
public static ?Mode $mode = null;
|
public static Option $mode;
|
||||||
|
|
||||||
|
/** @var Option<string> The data source name (DSN) of the connection string */
|
||||||
|
private static Option $pdoDSN;
|
||||||
|
|
||||||
/** @var PDO|null The PDO instance to use for database commands */
|
/** @var PDO|null The PDO instance to use for database commands */
|
||||||
private static ?PDO $_pdo = null;
|
private static ?PDO $pdo = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use a Data Source Name (DSN)
|
||||||
|
*
|
||||||
|
* @param string $dsn The data source name to use (driver:[parameters])
|
||||||
|
* @throws DocumentException If a DSN does not start with `pgsql:` or `sqlite:`
|
||||||
|
*/
|
||||||
|
public static function useDSN(string $dsn): void
|
||||||
|
{
|
||||||
|
if (empty($dsn)) {
|
||||||
|
self::$mode = self::$pdoDSN = Option::None();
|
||||||
|
} else {
|
||||||
|
self::$mode = Option::Some(Mode::deriveFromDSN($dsn));
|
||||||
|
self::$pdoDSN = Option::Some($dsn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a new connection to the database
|
* Retrieve a new connection to the database
|
||||||
*
|
*
|
||||||
* @return PDO A new connection to the SQLite database with foreign key support enabled
|
* @return PDO A new connection to the SQLite database with foreign key support enabled
|
||||||
* @throws DocumentException If this is called before a connection string is set
|
* @throws Exception If this is called before a connection string is set
|
||||||
*/
|
*/
|
||||||
public static function dbConn(): PDO
|
public static function dbConn(): PDO
|
||||||
{
|
{
|
||||||
if (is_null(self::$_pdo)) {
|
if (is_null(self::$pdo)) {
|
||||||
if (empty(self::$pdoDSN)) {
|
$dsn = self::$pdoDSN->getOrThrow(fn()
|
||||||
throw new DocumentException('Please provide a data source name (DSN) before attempting data access');
|
=> new DocumentException('Please provide a data source name (DSN) before attempting data access'));
|
||||||
}
|
self::$pdo = new PDO($dsn, $_ENV['PDO_DOC_USERNAME'] ?? self::$username,
|
||||||
self::$_pdo = new PDO(self::$pdoDSN, $_ENV['PDO_DOC_USERNAME'] ?? self::$username,
|
|
||||||
$_ENV['PDO_DOC_PASSWORD'] ?? self::$password, self::$options);
|
$_ENV['PDO_DOC_PASSWORD'] ?? self::$password, self::$options);
|
||||||
|
|
||||||
if (is_null(self::$mode)) {
|
|
||||||
$driver = self::$_pdo->getAttribute(PDO::ATTR_DRIVER_NAME);
|
|
||||||
self::$mode = match ($driver) {
|
|
||||||
'pgsql' => Mode::PgSQL,
|
|
||||||
'sqlite' => Mode::SQLite,
|
|
||||||
default => throw new DocumentException(
|
|
||||||
"Unsupported driver $driver: this library currently supports PostgreSQL and SQLite")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::$_pdo;
|
return self::$pdo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the mode for the current database connection
|
||||||
|
*
|
||||||
|
* @return Mode The mode for the current database connection
|
||||||
|
* @throws Exception If the database mode has not been set
|
||||||
|
*/
|
||||||
|
public static function mode(?string $process = null): Mode
|
||||||
|
{
|
||||||
|
return self::$mode->getOrThrow(fn()
|
||||||
|
=> new DocumentException('Database mode not set' . (is_null($process) ? '' : "; cannot $process")));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* You probably don't mean to be calling this; it is here for testing only
|
||||||
|
*
|
||||||
|
* @param Mode|null $mode The mode to set
|
||||||
|
*/
|
||||||
|
public static function overrideMode(?Mode $mode): void
|
||||||
|
{
|
||||||
|
self::$mode = Option::of($mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,6 +107,6 @@ class Configuration
|
||||||
*/
|
*/
|
||||||
public static function resetPDO(): void
|
public static function resetPDO(): void
|
||||||
{
|
{
|
||||||
self::$_pdo = null;
|
self::$pdo = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument;
|
namespace BitBadger\PDODocument;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,14 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument;
|
namespace BitBadger\PDODocument;
|
||||||
|
|
||||||
|
use BitBadger\InspiredByFSharp\Option;
|
||||||
use BitBadger\PDODocument\Mapper\Mapper;
|
use BitBadger\PDODocument\Mapper\Mapper;
|
||||||
use PDO;
|
use PDO;
|
||||||
use PDOException;
|
use PDOException;
|
||||||
|
@ -38,7 +45,7 @@ class Custom
|
||||||
is_bool($value) => PDO::PARAM_BOOL,
|
is_bool($value) => PDO::PARAM_BOOL,
|
||||||
is_int($value) => PDO::PARAM_INT,
|
is_int($value) => PDO::PARAM_INT,
|
||||||
is_null($value) => PDO::PARAM_NULL,
|
is_null($value) => PDO::PARAM_NULL,
|
||||||
default => PDO::PARAM_STR
|
default => PDO::PARAM_STR,
|
||||||
};
|
};
|
||||||
$stmt->bindValue($key, $value, $dataType);
|
$stmt->bindValue($key, $value, $dataType);
|
||||||
}
|
}
|
||||||
|
@ -92,14 +99,14 @@ class Custom
|
||||||
* @param string $query The query to be executed (will have "LIMIT 1" appended)
|
* @param string $query The query to be executed (will have "LIMIT 1" appended)
|
||||||
* @param array $parameters Parameters to use in executing the query
|
* @param array $parameters Parameters to use in executing the query
|
||||||
* @param Mapper<TDoc> $mapper Mapper to deserialize the result
|
* @param Mapper<TDoc> $mapper Mapper to deserialize the result
|
||||||
* @return false|TDoc The item if it is found, false if not
|
* @return Option<TDoc> A `Some` instance if the item is found, `None` otherwise
|
||||||
* @throws DocumentException If any is encountered
|
* @throws DocumentException If any is encountered
|
||||||
*/
|
*/
|
||||||
public static function single(string $query, array $parameters, Mapper $mapper): mixed
|
public static function single(string $query, array $parameters, Mapper $mapper): Option
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$stmt = &self::runQuery("$query LIMIT 1", $parameters);
|
$stmt = &self::runQuery("$query LIMIT 1", $parameters);
|
||||||
return ($first = $stmt->fetch(PDO::FETCH_ASSOC)) ? $mapper->map($first) : false;
|
return ($first = $stmt->fetch(PDO::FETCH_ASSOC)) ? Option::Some($mapper->map($first)) : Option::None();
|
||||||
} finally {
|
} finally {
|
||||||
$stmt = null;
|
$stmt = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument;
|
namespace BitBadger\PDODocument;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument;
|
namespace BitBadger\PDODocument;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument;
|
namespace BitBadger\PDODocument;
|
||||||
|
|
||||||
|
@ -18,7 +24,7 @@ class Document
|
||||||
{
|
{
|
||||||
$doInsert = fn() => Custom::nonQuery(Query::insert($tableName), Parameters::json(':data', $document));
|
$doInsert = fn() => Custom::nonQuery(Query::insert($tableName), Parameters::json(':data', $document));
|
||||||
|
|
||||||
if (Configuration::$autoId == AutoId::None) {
|
if (Configuration::$autoId === AutoId::None) {
|
||||||
$doInsert();
|
$doInsert();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument;
|
namespace BitBadger\PDODocument;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument;
|
namespace BitBadger\PDODocument;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument;
|
namespace BitBadger\PDODocument;
|
||||||
|
|
||||||
|
@ -15,8 +21,11 @@ use PDOStatement;
|
||||||
*/
|
*/
|
||||||
class DocumentList
|
class DocumentList
|
||||||
{
|
{
|
||||||
/** @var TDoc|null $_first The first item from the results */
|
/** @var TDoc|null $first The first item from the results */
|
||||||
private mixed $_first = null;
|
private mixed $first = null;
|
||||||
|
|
||||||
|
/** @var bool $isConsumed This is set to true once the generator has been exhausted */
|
||||||
|
private bool $isConsumed = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
|
@ -27,12 +36,99 @@ class DocumentList
|
||||||
private function __construct(private ?PDOStatement &$result, private readonly Mapper $mapper)
|
private function __construct(private ?PDOStatement &$result, private readonly Mapper $mapper)
|
||||||
{
|
{
|
||||||
if ($row = $this->result->fetch(PDO::FETCH_ASSOC)) {
|
if ($row = $this->result->fetch(PDO::FETCH_ASSOC)) {
|
||||||
$this->_first = $this->mapper->map($row);
|
$this->first = $this->mapper->map($row);
|
||||||
} else {
|
} else {
|
||||||
$this->result = null;
|
$this->result = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does this list have items remaining?
|
||||||
|
*
|
||||||
|
* @return bool True if there are items still to be retrieved from the list, false if not
|
||||||
|
*/
|
||||||
|
public function hasItems(): bool
|
||||||
|
{
|
||||||
|
return !is_null($this->result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The items from the query result
|
||||||
|
*
|
||||||
|
* @return Generator<TDoc> The items from the document list
|
||||||
|
* @throws DocumentException If this is called once the generator has been consumed
|
||||||
|
*/
|
||||||
|
public function items(): Generator
|
||||||
|
{
|
||||||
|
if (!$this->result) {
|
||||||
|
if ($this->isConsumed) {
|
||||||
|
throw new DocumentException('Cannot call items() multiple times');
|
||||||
|
}
|
||||||
|
$this->isConsumed = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
yield $this->first;
|
||||||
|
while ($row = $this->result->fetch(PDO::FETCH_ASSOC)) {
|
||||||
|
yield $this->mapper->map($row);
|
||||||
|
}
|
||||||
|
$this->isConsumed = true;
|
||||||
|
$this->result = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map items by consuming the generator
|
||||||
|
*
|
||||||
|
* @template U The type to which each item should be mapped
|
||||||
|
* @param callable(TDoc): U $map The mapping function
|
||||||
|
* @return Generator<U> The result of the mapping function
|
||||||
|
* @throws DocumentException If this is called once the generator has been consumed
|
||||||
|
*/
|
||||||
|
public function map(callable $map): Generator
|
||||||
|
{
|
||||||
|
foreach ($this->items() as $item) {
|
||||||
|
yield $map($item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterate the generator, running the given function for each item
|
||||||
|
*
|
||||||
|
* @param callable(TDoc): void $f The function to run for each item
|
||||||
|
* @throws DocumentException If this is called once the generator has been consumed
|
||||||
|
*/
|
||||||
|
public function iter(callable $f): void
|
||||||
|
{
|
||||||
|
foreach ($this->items() as $item) {
|
||||||
|
$f($item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterate the generator, extracting key/value pairs returned as an associative array
|
||||||
|
*
|
||||||
|
* @template TValue The type for the mapped value
|
||||||
|
* @param callable(TDoc): (int|string) $keyFunc The function to extract a key from the document
|
||||||
|
* @param callable(TDoc): TValue $valueFunc The function to extract a value from the document
|
||||||
|
* @return TValue[] An associative array of values, keyed by the extracted keys
|
||||||
|
* @throws DocumentException If this is called once the generator has been consumed
|
||||||
|
*/
|
||||||
|
public function mapToArray(callable $keyFunc, callable $valueFunc): array
|
||||||
|
{
|
||||||
|
$results = [];
|
||||||
|
foreach ($this->items() as $item) {
|
||||||
|
$results[$keyFunc($item)] = $valueFunc($item);
|
||||||
|
}
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure the statement is destroyed if the generator is not exhausted
|
||||||
|
*/
|
||||||
|
public function __destruct()
|
||||||
|
{
|
||||||
|
if (!is_null($this->result)) $this->result = null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new document list
|
* Construct a new document list
|
||||||
*
|
*
|
||||||
|
@ -47,37 +143,4 @@ class DocumentList
|
||||||
$stmt = &Custom::runQuery($query, $parameters);
|
$stmt = &Custom::runQuery($query, $parameters);
|
||||||
return new static($stmt, $mapper);
|
return new static($stmt, $mapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The items from the query result
|
|
||||||
*
|
|
||||||
* @return Generator<TDoc> The items from the document list
|
|
||||||
*/
|
|
||||||
public function items(): Generator
|
|
||||||
{
|
|
||||||
if (!$this->result) return;
|
|
||||||
yield $this->_first;
|
|
||||||
while ($row = $this->result->fetch(PDO::FETCH_ASSOC)) {
|
|
||||||
yield $this->mapper->map($row);
|
|
||||||
}
|
|
||||||
$this->result = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Does this list have items remaining?
|
|
||||||
*
|
|
||||||
* @return bool True if there are items still to be retrieved from the list, false if not
|
|
||||||
*/
|
|
||||||
public function hasItems(): bool
|
|
||||||
{
|
|
||||||
return !is_null($this->result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ensure the statement is destroyed if the generator is not exhausted
|
|
||||||
*/
|
|
||||||
public function __destruct()
|
|
||||||
{
|
|
||||||
if (!is_null($this->result)) $this->result = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument;
|
namespace BitBadger\PDODocument;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,15 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument;
|
namespace BitBadger\PDODocument;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Criteria for a field WHERE clause
|
* Criteria for a field WHERE clause
|
||||||
*/
|
*/
|
||||||
|
@ -48,30 +56,30 @@ class Field
|
||||||
* Get the WHERE clause fragment for this parameter
|
* Get the WHERE clause fragment for this parameter
|
||||||
*
|
*
|
||||||
* @return string The WHERE clause fragment for this parameter
|
* @return string The WHERE clause fragment for this parameter
|
||||||
* @throws DocumentException If the database mode has not been set
|
* @throws Exception|DocumentException If the database mode has not been set
|
||||||
*/
|
*/
|
||||||
public function toWhere(): string
|
public function toWhere(): string
|
||||||
{
|
{
|
||||||
$fieldName = ($this->qualifier == '' ? '' : "$this->qualifier.") . 'data' . match (true) {
|
$mode = Configuration::mode('make field WHERE clause');
|
||||||
|
$fieldName = (empty($this->qualifier) ? '' : "$this->qualifier.") . 'data' . match (true) {
|
||||||
!str_contains($this->fieldName, '.') => "->>'$this->fieldName'",
|
!str_contains($this->fieldName, '.') => "->>'$this->fieldName'",
|
||||||
Configuration::$mode == Mode::PgSQL => "#>>'{" . implode(',', explode('.', $this->fieldName)) . "}'",
|
$mode === Mode::PgSQL => "#>>'{" . implode(',', explode('.', $this->fieldName)) . "}'",
|
||||||
Configuration::$mode == Mode::SQLite => "->>'" . implode("'->>'", explode('.', $this->fieldName)) . "'",
|
$mode === Mode::SQLite => "->>'" . implode("'->>'", explode('.', $this->fieldName)) . "'",
|
||||||
default => throw new DocumentException('Database mode not set; cannot make field WHERE clause')
|
|
||||||
};
|
};
|
||||||
$fieldPath = match (Configuration::$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::BT => 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::EX, Op::NEX => '',
|
||||||
Op::BT => " {$this->paramName}min AND {$this->paramName}max",
|
Op::BT => " {$this->paramName}min AND {$this->paramName}max",
|
||||||
default => " $this->paramName"
|
default => " $this->paramName",
|
||||||
};
|
};
|
||||||
return $fieldPath . ' ' . $this->op->toString() . $criteria;
|
return $fieldPath . ' ' . $this->op->toSQL() . $criteria;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument;
|
namespace BitBadger\PDODocument;
|
||||||
|
|
||||||
|
@ -18,11 +24,11 @@ enum FieldMatch
|
||||||
*
|
*
|
||||||
* @return string The SQL keyword for this enumeration value
|
* @return string The SQL keyword for this enumeration value
|
||||||
*/
|
*/
|
||||||
public function toString(): string
|
public function toSQL(): string
|
||||||
{
|
{
|
||||||
return match ($this) {
|
return match ($this) {
|
||||||
FieldMatch::All => 'AND',
|
FieldMatch::All => 'AND',
|
||||||
FieldMatch::Any => 'OR'
|
FieldMatch::Any => 'OR',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
25
src/Find.php
25
src/Find.php
|
@ -1,7 +1,14 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument;
|
namespace BitBadger\PDODocument;
|
||||||
|
|
||||||
|
use BitBadger\InspiredByFSharp\Option;
|
||||||
use BitBadger\PDODocument\Mapper\DocumentMapper;
|
use BitBadger\PDODocument\Mapper\DocumentMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,10 +37,10 @@ class Find
|
||||||
* @param string $tableName The table from which the document should be retrieved
|
* @param string $tableName The table from which the document should be retrieved
|
||||||
* @param mixed $docId The ID of the document to retrieve
|
* @param mixed $docId The ID of the document to retrieve
|
||||||
* @param class-string<TDoc> $className The name of the class to be retrieved
|
* @param class-string<TDoc> $className The name of the class to be retrieved
|
||||||
* @return false|TDoc The document if it exists, false if not
|
* @return Option<TDoc> A `Some` instance if the document is found, `None` otherwise
|
||||||
* @throws DocumentException If any is encountered
|
* @throws DocumentException If any is encountered
|
||||||
*/
|
*/
|
||||||
public static function byId(string $tableName, mixed $docId, string $className): mixed
|
public static function byId(string $tableName, mixed $docId, string $className): Option
|
||||||
{
|
{
|
||||||
return Custom::single(Query\Find::byId($tableName, $docId), Parameters::id($docId),
|
return Custom::single(Query\Find::byId($tableName, $docId), Parameters::id($docId),
|
||||||
new DocumentMapper($className));
|
new DocumentMapper($className));
|
||||||
|
@ -97,11 +104,11 @@ class Find
|
||||||
* @param array|Field[] $fields The field comparison to match
|
* @param array|Field[] $fields The field comparison to match
|
||||||
* @param class-string<TDoc> $className The name of the class to be retrieved
|
* @param class-string<TDoc> $className The name of the class to be retrieved
|
||||||
* @param FieldMatch|null $match How to handle multiple conditions (optional; defaults to All)
|
* @param FieldMatch|null $match How to handle multiple conditions (optional; defaults to All)
|
||||||
* @return false|TDoc The first document if any matches are found, false otherwise
|
* @return Option<TDoc> A `Some` instance with the first document if any matches are found, `None` otherwise
|
||||||
* @throws DocumentException If any is encountered
|
* @throws DocumentException If any is encountered
|
||||||
*/
|
*/
|
||||||
public static function firstByFields(string $tableName, array $fields, string $className,
|
public static function firstByFields(string $tableName, array $fields, string $className,
|
||||||
?FieldMatch $match = null): mixed
|
?FieldMatch $match = null): Option
|
||||||
{
|
{
|
||||||
$namedFields = Parameters::nameFields($fields);
|
$namedFields = Parameters::nameFields($fields);
|
||||||
return Custom::single(Query\Find::byFields($tableName, $namedFields, $match),
|
return Custom::single(Query\Find::byFields($tableName, $namedFields, $match),
|
||||||
|
@ -115,10 +122,10 @@ class Find
|
||||||
* @param string $tableName The name of the table from which documents should be retrieved
|
* @param string $tableName The name of the table from which documents should be retrieved
|
||||||
* @param array|object $criteria The criteria for the JSON containment query
|
* @param array|object $criteria The criteria for the JSON containment query
|
||||||
* @param class-string<TDoc> $className The name of the class to be retrieved
|
* @param class-string<TDoc> $className The name of the class to be retrieved
|
||||||
* @return false|TDoc The first document matching the JSON containment query if any is found, false otherwise
|
* @return Option<TDoc> A `Some` instance with the first document if any matches are found, `None` otherwise
|
||||||
* @throws DocumentException If the database mode is not PostgreSQL, or if an error occurs
|
* @throws DocumentException If the database mode is not PostgreSQL, or if an error occurs
|
||||||
*/
|
*/
|
||||||
public static function firstByContains(string $tableName, array|object $criteria, string $className): mixed
|
public static function firstByContains(string $tableName, array|object $criteria, string $className): Option
|
||||||
{
|
{
|
||||||
return Custom::single(Query\Find::byContains($tableName), Parameters::json(':criteria', $criteria),
|
return Custom::single(Query\Find::byContains($tableName), Parameters::json(':criteria', $criteria),
|
||||||
new DocumentMapper($className));
|
new DocumentMapper($className));
|
||||||
|
@ -131,10 +138,10 @@ class Find
|
||||||
* @param string $tableName The name of the table from which documents should be retrieved
|
* @param string $tableName The name of the table from which documents should be retrieved
|
||||||
* @param string $path The JSON Path match string
|
* @param string $path The JSON Path match string
|
||||||
* @param class-string<TDoc> $className The name of the class to be retrieved
|
* @param class-string<TDoc> $className The name of the class to be retrieved
|
||||||
* @return false|TDoc The first document matching the JSON Path if any is found, false otherwise
|
* @return Option<TDoc> A `Some` instance with the first document if any matches are found, `None` otherwise
|
||||||
* @throws DocumentException If the database mode is not PostgreSQL, or if an error occurs
|
* @throws DocumentException If the database mode is not PostgreSQL, or if an error occurs
|
||||||
*/
|
*/
|
||||||
public static function firstByJsonPath(string $tableName, string $path, string $className): mixed
|
public static function firstByJsonPath(string $tableName, string $path, string $className): Option
|
||||||
{
|
{
|
||||||
return Custom::single(Query\Find::byJsonPath($tableName), [':path' => $path], new DocumentMapper($className));
|
return Custom::single(Query\Find::byJsonPath($tableName), [':path' => $path], new DocumentMapper($className));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument\Mapper;
|
namespace BitBadger\PDODocument\Mapper;
|
||||||
|
|
||||||
|
@ -7,9 +13,7 @@ namespace BitBadger\PDODocument\Mapper;
|
||||||
*/
|
*/
|
||||||
class ArrayMapper implements Mapper
|
class ArrayMapper implements Mapper
|
||||||
{
|
{
|
||||||
/**
|
/** @inheritDoc */
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function map(array $result): array
|
public function map(array $result): array
|
||||||
{
|
{
|
||||||
return $result;
|
return $result;
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument\Mapper;
|
namespace BitBadger\PDODocument\Mapper;
|
||||||
|
|
||||||
|
@ -7,9 +13,7 @@ namespace BitBadger\PDODocument\Mapper;
|
||||||
*/
|
*/
|
||||||
class CountMapper implements Mapper
|
class CountMapper implements Mapper
|
||||||
{
|
{
|
||||||
/**
|
/** @inheritDoc */
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function map(array $result): int
|
public function map(array $result): int
|
||||||
{
|
{
|
||||||
return (int) $result[0];
|
return (int) $result[0];
|
||||||
|
|
|
@ -1,10 +1,16 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument\Mapper;
|
namespace BitBadger\PDODocument\Mapper;
|
||||||
|
|
||||||
use BitBadger\PDODocument\DocumentException;
|
use BitBadger\PDODocument\DocumentException;
|
||||||
|
use Exception;
|
||||||
use JsonMapper;
|
use JsonMapper;
|
||||||
use JsonMapper_Exception;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map domain class instances from JSON documents
|
* Map domain class instances from JSON documents
|
||||||
|
@ -20,7 +26,7 @@ class DocumentMapper implements Mapper
|
||||||
* @param class-string<TDoc> $className The type of class to be returned by this mapping
|
* @param class-string<TDoc> $className The type of class to be returned by this mapping
|
||||||
* @param string $fieldName The name of the field (optional; defaults to `data`)
|
* @param string $fieldName The name of the field (optional; defaults to `data`)
|
||||||
*/
|
*/
|
||||||
public function __construct(public string $className, public string $fieldName = 'data') { }
|
public function __construct(public string $className, public string $fieldName = 'data') {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map a result to a domain class instance
|
* Map a result to a domain class instance
|
||||||
|
@ -32,12 +38,15 @@ class DocumentMapper implements Mapper
|
||||||
public function map(array $result): mixed
|
public function map(array $result): mixed
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
if (method_exists($this->className, 'fromJsonString')) {
|
||||||
|
return $this->className::fromJsonString($result[$this->fieldName]);
|
||||||
|
}
|
||||||
$json = json_decode($result[$this->fieldName]);
|
$json = json_decode($result[$this->fieldName]);
|
||||||
if (is_null($json)) {
|
if (is_null($json)) {
|
||||||
throw new DocumentException("Could not map document for $this->className: " . json_last_error_msg());
|
throw new DocumentException("Could not map document for $this->className: " . json_last_error_msg());
|
||||||
}
|
}
|
||||||
return (new JsonMapper())->map($json, $this->className);
|
return (new JsonMapper())->map($json, $this->className);
|
||||||
} catch (JsonMapper_Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
throw new DocumentException("Could not map document for $this->className", previous: $ex);
|
throw new DocumentException("Could not map document for $this->className", previous: $ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument\Mapper;
|
namespace BitBadger\PDODocument\Mapper;
|
||||||
|
|
||||||
use BitBadger\PDODocument\{Configuration, DocumentException, Mode};
|
use BitBadger\PDODocument\{Configuration, Mode};
|
||||||
|
use Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map an EXISTS result to a boolean value
|
* Map an EXISTS result to a boolean value
|
||||||
|
@ -11,14 +18,13 @@ class ExistsMapper implements Mapper
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
* @throws DocumentException If the database mode has not been set
|
* @throws Exception If the database mode has not been set
|
||||||
*/
|
*/
|
||||||
public function map(array $result): bool
|
public function map(array $result): bool
|
||||||
{
|
{
|
||||||
return match (Configuration::$mode) {
|
return match (Configuration::mode('map existence result')) {
|
||||||
Mode::PgSQL => (bool)$result[0],
|
Mode::PgSQL => (bool)$result[0],
|
||||||
Mode::SQLite => (int)$result[0] > 0,
|
Mode::SQLite => (int)$result[0] > 0,
|
||||||
default => throw new DocumentException('Database mode not set; cannot map existence result'),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument\Mapper;
|
namespace BitBadger\PDODocument\Mapper;
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,15 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument\Mapper;
|
namespace BitBadger\PDODocument\Mapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map a string result from the
|
* Map a string result from the named field
|
||||||
*
|
*
|
||||||
* @implements Mapper<string>
|
* @implements Mapper<string>
|
||||||
*/
|
*/
|
||||||
|
@ -24,7 +30,7 @@ class StringMapper implements Mapper
|
||||||
return match (false) {
|
return match (false) {
|
||||||
key_exists($this->fieldName, $result) => null,
|
key_exists($this->fieldName, $result) => null,
|
||||||
is_string($result[$this->fieldName]) => "{$result[$this->fieldName]}",
|
is_string($result[$this->fieldName]) => "{$result[$this->fieldName]}",
|
||||||
default => $result[$this->fieldName]
|
default => $result[$this->fieldName],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
23
src/Mode.php
23
src/Mode.php
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument;
|
namespace BitBadger\PDODocument;
|
||||||
|
|
||||||
|
@ -12,4 +18,19 @@ enum Mode
|
||||||
|
|
||||||
/** Storing documents in a SQLite database */
|
/** Storing documents in a SQLite database */
|
||||||
case SQLite;
|
case SQLite;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Derive the mode from the Data Source Name (DSN)
|
||||||
|
*
|
||||||
|
* @return Mode The database mode based on the DSN
|
||||||
|
* @throws DocumentException If the DSN does not start with `pgsql:` or `sqlite:`
|
||||||
|
*/
|
||||||
|
public static function deriveFromDSN(string $dsn): Mode
|
||||||
|
{
|
||||||
|
return match (true) {
|
||||||
|
str_starts_with($dsn, 'pgsql:') => Mode::PgSQL,
|
||||||
|
str_starts_with($dsn, 'sqlite:') => Mode::SQLite,
|
||||||
|
default => throw new DocumentException('This library currently supports PostgreSQL and SQLite'),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
14
src/Op.php
14
src/Op.php
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument;
|
namespace BitBadger\PDODocument;
|
||||||
|
|
||||||
|
@ -27,11 +33,11 @@ enum Op
|
||||||
case NEX;
|
case NEX;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the string representation of this operator
|
* Get the SQL representation of this operator
|
||||||
*
|
*
|
||||||
* @return string The operator to use in SQL statements
|
* @return string The operator to use in SQL statements
|
||||||
*/
|
*/
|
||||||
public function toString(): string
|
public function toSQL(): string
|
||||||
{
|
{
|
||||||
return match ($this) {
|
return match ($this) {
|
||||||
Op::EQ => "=",
|
Op::EQ => "=",
|
||||||
|
@ -42,7 +48,7 @@ enum Op
|
||||||
Op::NE => "<>",
|
Op::NE => "<>",
|
||||||
Op::BT => "BETWEEN",
|
Op::BT => "BETWEEN",
|
||||||
Op::EX => "IS NOT NULL",
|
Op::EX => "IS NOT NULL",
|
||||||
Op::NEX => "IS NULL"
|
Op::NEX => "IS NULL",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,15 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument;
|
namespace BitBadger\PDODocument;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Functions to create parameters for queries
|
* Functions to create parameters for queries
|
||||||
*/
|
*/
|
||||||
|
@ -27,27 +35,45 @@ class Parameters
|
||||||
*/
|
*/
|
||||||
public static function json(string $name, object|array $document): array
|
public static function json(string $name, object|array $document): array
|
||||||
{
|
{
|
||||||
return [$name => json_encode($document, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)];
|
$flags = JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES;
|
||||||
|
|
||||||
|
if (is_object($document)) {
|
||||||
|
return [
|
||||||
|
$name => method_exists($document, 'toJson') ? $document->toJson($flags) : json_encode($document, $flags)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$key = array_key_first($document);
|
||||||
|
if (is_array($document[$key])) {
|
||||||
|
if (empty($document[$key])) return [$name => json_encode($document, $flags)];
|
||||||
|
if (method_exists($document[$key][array_key_first($document[$key])], 'toJson')) {
|
||||||
|
return [
|
||||||
|
$name => sprintf('{%s:[%s]}', json_encode($key, $flags),
|
||||||
|
implode(',', array_map(fn($it) => $it->toJson($flags), $document[$key])))
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [$name => json_encode($document, $flags)];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fill in parameter names for any fields missing one
|
* Fill in parameter names for any fields missing one
|
||||||
*
|
*
|
||||||
* @param array|Field[] $fields The fields for the query
|
* @param Field[] $fields The fields for the query
|
||||||
* @return array|Field[] The fields, all with non-blank parameter names
|
* @return Field[] The fields, all with non-blank parameter names
|
||||||
*/
|
*/
|
||||||
public static function nameFields(array $fields): array
|
public static function nameFields(array $fields): array
|
||||||
{
|
{
|
||||||
for ($idx = 0; $idx < sizeof($fields); $idx++) {
|
array_walk($fields, function (Field $field, int $idx) {
|
||||||
if ($fields[$idx]->paramName == '') $fields[$idx]->paramName = ":field$idx";
|
if (empty($field->paramName)) $field->paramName =":field$idx";
|
||||||
}
|
});
|
||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add field parameters to the given set of parameters
|
* Add field parameters to the given set of parameters
|
||||||
*
|
*
|
||||||
* @param array|Field[] $fields The fields being compared in the query
|
* @param Field[] $fields The fields being compared in the query
|
||||||
* @param array $parameters An associative array of parameters to which the fields should be added
|
* @param array $parameters An associative array of parameters to which the fields should be added
|
||||||
* @return array An associative array of parameter names and values with the fields added
|
* @return array An associative array of parameter names and values with the fields added
|
||||||
*/
|
*/
|
||||||
|
@ -60,22 +86,18 @@ class Parameters
|
||||||
* Create JSON field name parameters for the given field names to the given parameter
|
* Create JSON field name parameters for the given field names to the given parameter
|
||||||
*
|
*
|
||||||
* @param string $paramName The name of the parameter for the field names
|
* @param string $paramName The name of the parameter for the field names
|
||||||
* @param array|string[] $fieldNames The names of the fields for the parameter
|
* @param string[] $fieldNames The names of the fields for the parameter
|
||||||
* @return array An associative array of parameter/value pairs for the field names
|
* @return array An associative array of parameter/value pairs for the field names
|
||||||
* @throws DocumentException If the database mode has not been set
|
* @throws Exception If the database mode has not been set
|
||||||
*/
|
*/
|
||||||
public static function fieldNames(string $paramName, array $fieldNames): array
|
public static function fieldNames(string $paramName, array $fieldNames): array
|
||||||
{
|
{
|
||||||
switch (Configuration::$mode) {
|
$mode = Configuration::mode('generate field name parameters');
|
||||||
case Mode::PgSQL:
|
return match ($mode) {
|
||||||
return [$paramName => "{" . implode(",", $fieldNames) . "}"];
|
Mode::PgSQL => [$paramName => "{" . implode(",", $fieldNames) . "}"],
|
||||||
case Mode::SQLite:
|
Mode::SQLite => array_combine(array_map(fn($idx) => $paramName . $idx,
|
||||||
$it = [];
|
empty($fieldNames) ? [] : range(0, sizeof($fieldNames) - 1)),
|
||||||
$idx = 0;
|
array_map(fn($field) => "$.$field", $fieldNames))
|
||||||
foreach ($fieldNames as $field) $it[$paramName . $idx++] = "$.$field";
|
};
|
||||||
return $it;
|
|
||||||
default:
|
|
||||||
throw new DocumentException('Database mode not set; cannot generate field name parameters');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument;
|
namespace BitBadger\PDODocument;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,14 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument;
|
namespace BitBadger\PDODocument;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use Random\RandomException;
|
use Random\RandomException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,8 +37,7 @@ class Query
|
||||||
*/
|
*/
|
||||||
public static function whereByFields(array $fields, ?FieldMatch $match = null): string
|
public static function whereByFields(array $fields, ?FieldMatch $match = null): string
|
||||||
{
|
{
|
||||||
return implode(' ' . ($match ?? FieldMatch::All)->toString() . ' ',
|
return implode(' ' . ($match ?? FieldMatch::All)->toSQL() . ' ', array_map(fn($it) => $it->toWhere(), $fields));
|
||||||
array_map(fn($it) => $it->toWhere(), $fields));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,11 +59,11 @@ class Query
|
||||||
*
|
*
|
||||||
* @param string $paramName The name of the parameter (optional; defaults to `:criteria`)
|
* @param string $paramName The name of the parameter (optional; defaults to `:criteria`)
|
||||||
* @return string The WHERE clause fragment for a JSON containment query
|
* @return string The WHERE clause fragment for a JSON containment query
|
||||||
* @throws DocumentException If the database mode is not PostgreSQL
|
* @throws Exception|DocumentException If the database mode is not PostgreSQL
|
||||||
*/
|
*/
|
||||||
public static function whereDataContains(string $paramName = ':criteria'): string
|
public static function whereDataContains(string $paramName = ':criteria'): string
|
||||||
{
|
{
|
||||||
if (Configuration::$mode <> Mode::PgSQL) {
|
if (Configuration::mode() <> Mode::PgSQL) {
|
||||||
throw new DocumentException('JSON containment is only supported on PostgreSQL');
|
throw new DocumentException('JSON containment is only supported on PostgreSQL');
|
||||||
}
|
}
|
||||||
return "data @> $paramName";
|
return "data @> $paramName";
|
||||||
|
@ -68,11 +74,11 @@ class Query
|
||||||
*
|
*
|
||||||
* @param string $paramName The name of the parameter (optional; defaults to `:path`)
|
* @param string $paramName The name of the parameter (optional; defaults to `:path`)
|
||||||
* @return string The WHERE clause fragment for a JSON Path match query
|
* @return string The WHERE clause fragment for a JSON Path match query
|
||||||
* @throws DocumentException If the database mode is not PostgreSQL
|
* @throws Exception|DocumentException If the database mode is not PostgreSQL
|
||||||
*/
|
*/
|
||||||
public static function whereJsonPathMatches(string $paramName = ':path'): string
|
public static function whereJsonPathMatches(string $paramName = ':path'): string
|
||||||
{
|
{
|
||||||
if (Configuration::$mode <> Mode::PgSQL) {
|
if (Configuration::mode() <> Mode::PgSQL) {
|
||||||
throw new DocumentException('JSON Path matching is only supported on PostgreSQL');
|
throw new DocumentException('JSON Path matching is only supported on PostgreSQL');
|
||||||
}
|
}
|
||||||
return "jsonb_path_exists(data, $paramName::jsonpath)";
|
return "jsonb_path_exists(data, $paramName::jsonpath)";
|
||||||
|
@ -84,19 +90,19 @@ class Query
|
||||||
* @param string $tableName The name of the table into which the document will be inserted
|
* @param string $tableName The name of the table into which the document will be inserted
|
||||||
* @param AutoId|null $autoId The version of automatic ID query to generate (optional, defaults to None)
|
* @param AutoId|null $autoId The version of automatic ID query to generate (optional, defaults to None)
|
||||||
* @return string The `INSERT` statement to insert a document
|
* @return string The `INSERT` statement to insert a document
|
||||||
* @throws DocumentException If the database mode is not set
|
* @throws Exception|DocumentException If the database mode is not set
|
||||||
*/
|
*/
|
||||||
public static function insert(string $tableName, ?AutoId $autoId = null): string
|
public static function insert(string $tableName, ?AutoId $autoId = null): string
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$id = Configuration::$idField;
|
$id = Configuration::$idField;
|
||||||
$values = match (Configuration::$mode) {
|
$values = match (Configuration::mode('generate auto-ID INSERT statement')) {
|
||||||
Mode::SQLite => match ($autoId ?? AutoId::None) {
|
Mode::SQLite => match ($autoId ?? AutoId::None) {
|
||||||
AutoId::None => ':data',
|
AutoId::None => ':data',
|
||||||
AutoId::Number => "json_set(:data, '$.$id', "
|
AutoId::Number => "json_set(:data, '$.$id', "
|
||||||
. "(SELECT coalesce(max(data->>'$id'), 0) + 1 FROM $tableName))",
|
. "(SELECT coalesce(max(data->>'$id'), 0) + 1 FROM $tableName))",
|
||||||
AutoId::UUID => "json_set(:data, '$.$id', '" . AutoId::generateUUID() . "')",
|
AutoId::UUID => "json_set(:data, '$.$id', '" . AutoId::generateUUID() . "')",
|
||||||
AutoId::RandomString => "json_set(:data, '$.$id', '" . AutoId::generateRandom() ."')"
|
AutoId::RandomString => "json_set(:data, '$.$id', '" . AutoId::generateRandom() ."')",
|
||||||
},
|
},
|
||||||
Mode::PgSQL => match ($autoId ?? AutoId::None) {
|
Mode::PgSQL => match ($autoId ?? AutoId::None) {
|
||||||
AutoId::None => ':data',
|
AutoId::None => ':data',
|
||||||
|
@ -105,9 +111,7 @@ class Query
|
||||||
. "FROM $tableName) || '}')::jsonb",
|
. "FROM $tableName) || '}')::jsonb",
|
||||||
AutoId::UUID => ":data::jsonb || '{\"$id\":\"" . AutoId::generateUUID() . "\"}'",
|
AutoId::UUID => ":data::jsonb || '{\"$id\":\"" . AutoId::generateUUID() . "\"}'",
|
||||||
AutoId::RandomString => ":data::jsonb || '{\"$id\":\"" . AutoId::generateRandom() . "\"}'",
|
AutoId::RandomString => ":data::jsonb || '{\"$id\":\"" . AutoId::generateRandom() . "\"}'",
|
||||||
},
|
}
|
||||||
default =>
|
|
||||||
throw new DocumentException('Database mode not set; cannot generate auto-ID INSERT statement'),
|
|
||||||
};
|
};
|
||||||
return "INSERT INTO $tableName VALUES ($values)";
|
return "INSERT INTO $tableName VALUES ($values)";
|
||||||
} catch (RandomException $ex) {
|
} catch (RandomException $ex) {
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument\Query;
|
namespace BitBadger\PDODocument\Query;
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument\Query;
|
namespace BitBadger\PDODocument\Query;
|
||||||
|
|
||||||
use BitBadger\PDODocument\{Configuration, DocumentException, DocumentIndex, Mode};
|
use BitBadger\PDODocument\{Configuration, DocumentException, DocumentIndex, Mode};
|
||||||
|
use Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queries to define tables and indexes
|
* Queries to define tables and indexes
|
||||||
|
@ -14,14 +21,13 @@ class Definition
|
||||||
*
|
*
|
||||||
* @param string $name The name of the table (including schema, if applicable)
|
* @param string $name The name of the table (including schema, if applicable)
|
||||||
* @return string The CREATE TABLE statement for the document table
|
* @return string The CREATE TABLE statement for the document table
|
||||||
* @throws DocumentException If the database mode has not been set
|
* @throws Exception If the database mode has not been set
|
||||||
*/
|
*/
|
||||||
public static function ensureTable(string $name): string
|
public static function ensureTable(string $name): string
|
||||||
{
|
{
|
||||||
$dataType = match (Configuration::$mode) {
|
$dataType = match (Configuration::mode('make create table statement')) {
|
||||||
Mode::PgSQL => 'JSONB',
|
Mode::PgSQL => 'JSONB',
|
||||||
Mode::SQLite => 'TEXT',
|
Mode::SQLite => 'TEXT',
|
||||||
default => throw new DocumentException('Database mode not set; cannot make create table statement')
|
|
||||||
};
|
};
|
||||||
return "CREATE TABLE IF NOT EXISTS $name (data $dataType NOT NULL)";
|
return "CREATE TABLE IF NOT EXISTS $name (data $dataType NOT NULL)";
|
||||||
}
|
}
|
||||||
|
@ -35,7 +41,7 @@ class Definition
|
||||||
private static function splitSchemaAndTable(string $tableName): array
|
private static function splitSchemaAndTable(string $tableName): array
|
||||||
{
|
{
|
||||||
$parts = explode('.', $tableName);
|
$parts = explode('.', $tableName);
|
||||||
return sizeof($parts) == 1 ? ["", $tableName] : [$parts[0], $parts[1]];
|
return sizeof($parts) === 1 ? ["", $tableName] : [$parts[0], $parts[1]];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,7 +57,7 @@ class Definition
|
||||||
[, $tbl] = self::splitSchemaAndTable($tableName);
|
[, $tbl] = self::splitSchemaAndTable($tableName);
|
||||||
$jsonFields = implode(', ', array_map(function (string $field) {
|
$jsonFields = implode(', ', array_map(function (string $field) {
|
||||||
$parts = explode(' ', $field);
|
$parts = explode(' ', $field);
|
||||||
$fieldName = sizeof($parts) == 1 ? $field : $parts[0];
|
$fieldName = sizeof($parts) === 1 ? $field : $parts[0];
|
||||||
$direction = sizeof($parts) < 2 ? "" : " $parts[1]";
|
$direction = sizeof($parts) < 2 ? "" : " $parts[1]";
|
||||||
return "(data->>'$fieldName')$direction";
|
return "(data->>'$fieldName')$direction";
|
||||||
}, $fields));
|
}, $fields));
|
||||||
|
@ -75,17 +81,17 @@ class Definition
|
||||||
* @param string $tableName The name of the table on which the document index should be created
|
* @param string $tableName The name of the table on which the document index should be created
|
||||||
* @param DocumentIndex $indexType The type of index to be created
|
* @param DocumentIndex $indexType The type of index to be created
|
||||||
* @return string The SQL statement to create an index on JSON documents in the specified table
|
* @return string The SQL statement to create an index on JSON documents in the specified table
|
||||||
* @throws DocumentException If the database mode is not PostgreSQL
|
* @throws Exception|DocumentException If the database mode is not PostgreSQL
|
||||||
*/
|
*/
|
||||||
public static function ensureDocumentIndexOn(string $tableName, DocumentIndex $indexType): string
|
public static function ensureDocumentIndexOn(string $tableName, DocumentIndex $indexType): string
|
||||||
{
|
{
|
||||||
if (Configuration::$mode <> Mode::PgSQL) {
|
if (Configuration::mode() <> Mode::PgSQL) {
|
||||||
throw new DocumentException('Document indexes are only supported on PostgreSQL');
|
throw new DocumentException('Document indexes are only supported on PostgreSQL');
|
||||||
}
|
}
|
||||||
[, $tbl] = self::splitSchemaAndTable($tableName);
|
[, $tbl] = self::splitSchemaAndTable($tableName);
|
||||||
$extraOps = match ($indexType) {
|
$extraOps = match ($indexType) {
|
||||||
DocumentIndex::Full => '',
|
DocumentIndex::Full => '',
|
||||||
DocumentIndex::Optimized => ' jsonb_path_ops'
|
DocumentIndex::Optimized => ' jsonb_path_ops',
|
||||||
};
|
};
|
||||||
return "CREATE INDEX IF NOT EXISTS idx_{$tbl}_document ON $tableName USING GIN (data$extraOps)";
|
return "CREATE INDEX IF NOT EXISTS idx_{$tbl}_document ON $tableName USING GIN (data$extraOps)";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument\Query;
|
namespace BitBadger\PDODocument\Query;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument\Query;
|
namespace BitBadger\PDODocument\Query;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument\Query;
|
namespace BitBadger\PDODocument\Query;
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument\Query;
|
namespace BitBadger\PDODocument\Query;
|
||||||
|
|
||||||
use BitBadger\PDODocument\{Configuration, DocumentException, Field, FieldMatch, Mode, Query};
|
use BitBadger\PDODocument\{Configuration, DocumentException, Field, FieldMatch, Mode, Query};
|
||||||
|
use Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queries to perform partial updates on documents
|
* Queries to perform partial updates on documents
|
||||||
|
@ -15,14 +22,13 @@ class Patch
|
||||||
* @param string $tableName The name of the table in which documents should be patched
|
* @param string $tableName The name of the table in which documents should be patched
|
||||||
* @param string $whereClause The body of the WHERE clause to use in the UPDATE statement
|
* @param string $whereClause The body of the WHERE clause to use in the UPDATE statement
|
||||||
* @return string The UPDATE statement to perform the patch
|
* @return string The UPDATE statement to perform the patch
|
||||||
* @throws DocumentException If the database mode has not been set
|
* @throws Exception If the database mode has not been set
|
||||||
*/
|
*/
|
||||||
public static function update(string $tableName, string $whereClause): string
|
public static function update(string $tableName, string $whereClause): string
|
||||||
{
|
{
|
||||||
$setValue = match (Configuration::$mode) {
|
$setValue = match (Configuration::mode('make patch statement')) {
|
||||||
Mode::PgSQL => 'data || :data',
|
Mode::PgSQL => 'data || :data',
|
||||||
Mode::SQLite => 'json_patch(data, json(:data))',
|
Mode::SQLite => 'json_patch(data, json(:data))',
|
||||||
default => throw new DocumentException('Database mode not set; cannot make patch statement')
|
|
||||||
};
|
};
|
||||||
return "UPDATE $tableName SET data = $setValue WHERE $whereClause";
|
return "UPDATE $tableName SET data = $setValue WHERE $whereClause";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument\Query;
|
namespace BitBadger\PDODocument\Query;
|
||||||
|
|
||||||
use BitBadger\PDODocument\{Configuration, DocumentException, Field, FieldMatch, Mode, Query};
|
use BitBadger\PDODocument\{Configuration, DocumentException, Field, FieldMatch, Mode, Query};
|
||||||
|
use Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queries to remove fields from documents
|
* Queries to remove fields from documents
|
||||||
|
@ -20,20 +27,16 @@ class RemoveFields
|
||||||
* @param array $parameters The parameter list for the query
|
* @param array $parameters The parameter list for the query
|
||||||
* @param string $whereClause The body of the WHERE clause for the update
|
* @param string $whereClause The body of the WHERE clause for the update
|
||||||
* @return string The UPDATE statement to remove fields from a JSON document
|
* @return string The UPDATE statement to remove fields from a JSON document
|
||||||
* @throws DocumentException If the database mode has not been set
|
* @throws Exception If the database mode has not been set
|
||||||
*/
|
*/
|
||||||
public static function update(string $tableName, array $parameters, string $whereClause): string
|
public static function update(string $tableName, array $parameters, string $whereClause): string
|
||||||
{
|
{
|
||||||
switch (Configuration::$mode) {
|
return match (Configuration::mode('generate field removal query')) {
|
||||||
case Mode::PgSQL:
|
Mode::PgSQL => "UPDATE $tableName SET data = data - " . array_keys($parameters)[0]
|
||||||
return "UPDATE $tableName SET data = data - " . array_keys($parameters)[0]
|
. "::text[] WHERE $whereClause",
|
||||||
. "::text[] WHERE $whereClause";
|
Mode::SQLite => "UPDATE $tableName SET data = json_remove(data, " . implode(', ', array_keys($parameters))
|
||||||
case Mode::SQLite:
|
. ") WHERE $whereClause",
|
||||||
$paramNames = implode(', ', array_keys($parameters));
|
};
|
||||||
return "UPDATE $tableName SET data = json_remove(data, $paramNames) WHERE $whereClause";
|
|
||||||
default:
|
|
||||||
throw new DocumentException('Database mode not set; cannot generate field removal query');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace BitBadger\PDODocument;
|
namespace BitBadger\PDODocument;
|
||||||
|
|
||||||
|
|
22
tests/PjsonDocument.php
Normal file
22
tests/PjsonDocument.php
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Test;
|
||||||
|
|
||||||
|
use Square\Pjson\{Json, JsonSerialize};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A test document annotated with pjson attributes using the `JsonSerialize` trait
|
||||||
|
*/
|
||||||
|
class PjsonDocument
|
||||||
|
{
|
||||||
|
use JsonSerialize;
|
||||||
|
|
||||||
|
public function __construct(#[Json] public PjsonId $id = new PjsonId(''), #[Json] public string $name = '',
|
||||||
|
#[Json('num_value')] public int $numValue = 0, public string $skipped = 'yep') { }
|
||||||
|
}
|
29
tests/PjsonId.php
Normal file
29
tests/PjsonId.php
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Test;
|
||||||
|
|
||||||
|
use Square\Pjson\JsonDataSerializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A serializable ID wrapper class
|
||||||
|
*/
|
||||||
|
class PjsonId implements JsonDataSerializable
|
||||||
|
{
|
||||||
|
public function __construct(protected string $value) { }
|
||||||
|
|
||||||
|
public function toJsonData(): string
|
||||||
|
{
|
||||||
|
return $this->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function fromJsonData($jd, array|string $path = []): static
|
||||||
|
{
|
||||||
|
return new static($jd);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Integration;
|
namespace Test\Integration;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Integration;
|
namespace Test\Integration;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Integration;
|
namespace Test\Integration;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Integration\PostgreSQL;
|
namespace Test\Integration\PostgreSQL;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Integration\PostgreSQL;
|
namespace Test\Integration\PostgreSQL;
|
||||||
|
|
||||||
|
@ -87,15 +93,15 @@ class CustomTest extends TestCase
|
||||||
{
|
{
|
||||||
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id", [':id' => 'one'],
|
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id", [':id' => 'one'],
|
||||||
new DocumentMapper(TestDocument::class));
|
new DocumentMapper(TestDocument::class));
|
||||||
$this->assertNotNull($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertEquals('one', $doc->id, 'The incorrect document was returned');
|
$this->assertEquals('one', $doc->get()->id, 'The incorrect document was returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSingleSucceedsWhenARowIsNotFound(): void
|
public function testSingleSucceedsWhenARowIsNotFound(): void
|
||||||
{
|
{
|
||||||
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id",
|
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id",
|
||||||
[':id' => 'eighty'], new DocumentMapper(TestDocument::class));
|
[':id' => 'eighty'], new DocumentMapper(TestDocument::class));
|
||||||
$this->assertFalse($doc, 'There should not have been a document returned');
|
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNonQuerySucceedsWhenOperatingOnData()
|
public function testNonQuerySucceedsWhenOperatingOnData()
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Integration\PostgreSQL;
|
namespace Test\Integration\PostgreSQL;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Integration\PostgreSQL;
|
namespace Test\Integration\PostgreSQL;
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Integration\PostgreSQL;
|
namespace Test\Integration\PostgreSQL;
|
||||||
|
|
||||||
use BitBadger\PDODocument\{DocumentList, Query};
|
use BitBadger\PDODocument\{DocumentException, DocumentList, Query};
|
||||||
use BitBadger\PDODocument\Mapper\DocumentMapper;
|
use BitBadger\PDODocument\Mapper\DocumentMapper;
|
||||||
use PHPUnit\Framework\Attributes\TestDox;
|
use PHPUnit\Framework\Attributes\TestDox;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
@ -37,7 +43,7 @@ class DocumentListTest extends TestCase
|
||||||
$list = null;
|
$list = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItems(): void
|
public function testItemsSucceeds(): void
|
||||||
{
|
{
|
||||||
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
||||||
new DocumentMapper(TestDocument::class));
|
new DocumentMapper(TestDocument::class));
|
||||||
|
@ -51,6 +57,18 @@ class DocumentListTest extends TestCase
|
||||||
$this->assertEquals(5, $count, 'There should have been 5 documents returned');
|
$this->assertEquals(5, $count, 'There should have been 5 documents returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testItemsFailsWhenAlreadyConsumed(): void
|
||||||
|
{
|
||||||
|
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
||||||
|
new DocumentMapper(TestDocument::class));
|
||||||
|
$this->assertNotNull($list, 'There should have been a document list created');
|
||||||
|
$this->assertTrue($list->hasItems(), 'There should be items in the list');
|
||||||
|
$ignored = iterator_to_array($list->items());
|
||||||
|
$this->assertFalse($list->hasItems(), 'The list should no longer have items');
|
||||||
|
$this->expectException(DocumentException::class);
|
||||||
|
iterator_to_array($list->items());
|
||||||
|
}
|
||||||
|
|
||||||
public function testHasItemsSucceedsWithEmptyResults(): void
|
public function testHasItemsSucceedsWithEmptyResults(): void
|
||||||
{
|
{
|
||||||
$list = DocumentList::create(
|
$list = DocumentList::create(
|
||||||
|
@ -71,4 +89,39 @@ class DocumentListTest extends TestCase
|
||||||
}
|
}
|
||||||
$this->assertFalse($list->hasItems(), 'There should be no remaining items in the list');
|
$this->assertFalse($list->hasItems(), 'There should be no remaining items in the list');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testMapSucceeds(): void
|
||||||
|
{
|
||||||
|
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
||||||
|
new DocumentMapper(TestDocument::class));
|
||||||
|
$this->assertNotNull($list, 'There should have been a document list created');
|
||||||
|
$this->assertTrue($list->hasItems(), 'There should be items in the list');
|
||||||
|
foreach ($list->map(fn($doc) => strrev($doc->id)) as $mapped) {
|
||||||
|
$this->assertContains($mapped, ['eno', 'owt', 'eerht', 'ruof', 'evif'],
|
||||||
|
'An unexpected mapped value was returned');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIterSucceeds(): void
|
||||||
|
{
|
||||||
|
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
||||||
|
new DocumentMapper(TestDocument::class));
|
||||||
|
$this->assertNotNull($list, 'There should have been a document list created');
|
||||||
|
$this->assertTrue($list->hasItems(), 'There should be items in the list');
|
||||||
|
$splats = [];
|
||||||
|
$list->iter(function ($doc) use (&$splats) { $splats[] = str_repeat('*', strlen($doc->id)); });
|
||||||
|
$this->assertEquals('*** *** ***** **** ****', implode(' ', $splats),
|
||||||
|
'Iteration did not have the expected result');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMapToArraySucceeds(): void
|
||||||
|
{
|
||||||
|
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
||||||
|
new DocumentMapper(TestDocument::class));
|
||||||
|
$this->assertNotNull($list, 'There should have been a document list created');
|
||||||
|
$this->assertTrue($list->hasItems(), 'There should be items in the list');
|
||||||
|
$lookup = $list->mapToArray(fn($it) => $it->id, fn($it) => $it->value);
|
||||||
|
$expected = ['one' => 'FIRST!', 'two' => 'another', 'three' => '', 'four' => 'purple', 'five' => 'purple'];
|
||||||
|
$this->assertEquals($expected, $lookup, 'The array was not mapped correctly');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Integration\PostgreSQL;
|
namespace Test\Integration\PostgreSQL;
|
||||||
|
|
||||||
|
@ -33,8 +39,9 @@ class DocumentTest extends TestCase
|
||||||
public function testInsertSucceedsForArrayNoAutoId(): void
|
public function testInsertSucceedsForArrayNoAutoId(): void
|
||||||
{
|
{
|
||||||
Document::insert(ThrowawayDb::TABLE, ['id' => 'turkey', 'sub' => ['foo' => 'gobble', 'bar' => 'gobble']]);
|
Document::insert(ThrowawayDb::TABLE, ['id' => 'turkey', 'sub' => ['foo' => 'gobble', 'bar' => 'gobble']]);
|
||||||
$doc = Find::byId(ThrowawayDb::TABLE, 'turkey', TestDocument::class);
|
$tryDoc = Find::byId(ThrowawayDb::TABLE, 'turkey', TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document inserted');
|
$this->assertTrue($tryDoc->isSome(), 'There should have been a document inserted');
|
||||||
|
$doc = $tryDoc->get();
|
||||||
$this->assertEquals('turkey', $doc->id, 'The ID was incorrect');
|
$this->assertEquals('turkey', $doc->id, 'The ID was incorrect');
|
||||||
$this->assertEquals('', $doc->value, 'The value was incorrect');
|
$this->assertEquals('', $doc->value, 'The value was incorrect');
|
||||||
$this->assertEquals(0, $doc->num_value, 'The numeric value was incorrect');
|
$this->assertEquals(0, $doc->num_value, 'The numeric value was incorrect');
|
||||||
|
@ -52,15 +59,15 @@ class DocumentTest extends TestCase
|
||||||
|
|
||||||
Document::insert(ThrowawayDb::TABLE, ['id' => 0, 'value' => 'new', 'num_value' => 8]);
|
Document::insert(ThrowawayDb::TABLE, ['id' => 0, 'value' => 'new', 'num_value' => 8]);
|
||||||
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE, [], new ArrayMapper());
|
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE, [], new ArrayMapper());
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$obj = json_decode($doc['data']);
|
$obj = json_decode($doc->get()['data']);
|
||||||
$this->assertEquals(1, $obj->id, 'The ID 1 should have been auto-generated');
|
$this->assertEquals(1, $obj->id, 'The ID 1 should have been auto-generated');
|
||||||
|
|
||||||
Document::insert(ThrowawayDb::TABLE, ['id' => 0, 'value' => 'again', 'num_value' => 7]);
|
Document::insert(ThrowawayDb::TABLE, ['id' => 0, 'value' => 'again', 'num_value' => 7]);
|
||||||
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE " . Query::whereById(docId: 2),
|
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE " . Query::whereById(docId: 2),
|
||||||
[':id' => 2], new ArrayMapper());
|
[':id' => 2], new ArrayMapper());
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$obj = json_decode($doc['data']);
|
$obj = json_decode($doc->get()['data']);
|
||||||
$this->assertEquals(2, $obj->id, 'The ID 2 should have been auto-generated');
|
$this->assertEquals(2, $obj->id, 'The ID 2 should have been auto-generated');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$autoId = AutoId::None;
|
Configuration::$autoId = AutoId::None;
|
||||||
|
@ -75,8 +82,8 @@ class DocumentTest extends TestCase
|
||||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||||
Document::insert(ThrowawayDb::TABLE, ['id' => 7, 'value' => 'new', 'num_value' => 8]);
|
Document::insert(ThrowawayDb::TABLE, ['id' => 7, 'value' => 'new', 'num_value' => 8]);
|
||||||
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE, [], new ArrayMapper());
|
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE, [], new ArrayMapper());
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$obj = json_decode($doc['data']);
|
$obj = json_decode($doc->get()['data']);
|
||||||
$this->assertEquals(7, $obj->id, 'The ID 7 should have been stored');
|
$this->assertEquals(7, $obj->id, 'The ID 7 should have been stored');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$autoId = AutoId::None;
|
Configuration::$autoId = AutoId::None;
|
||||||
|
@ -91,8 +98,8 @@ class DocumentTest extends TestCase
|
||||||
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::EQ('num_value', 5)], TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertNotEmpty($doc->id, 'The ID should have been auto-generated');
|
$this->assertNotEmpty($doc->get()->id, 'The ID should have been auto-generated');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$autoId = AutoId::None;
|
Configuration::$autoId = AutoId::None;
|
||||||
}
|
}
|
||||||
|
@ -107,8 +114,8 @@ class DocumentTest extends TestCase
|
||||||
$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::EQ('num_value', 12)], TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertEquals($uuid, $doc->id, 'The ID should not have been changed');
|
$this->assertEquals($uuid, $doc->get()->id, 'The ID should not have been changed');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$autoId = AutoId::None;
|
Configuration::$autoId = AutoId::None;
|
||||||
}
|
}
|
||||||
|
@ -123,8 +130,9 @@ class DocumentTest extends TestCase
|
||||||
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::EQ('num_value', 8)], TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertEquals(6, strlen($doc->id), 'The ID should have been auto-generated and had 6 characters');
|
$this->assertEquals(6, strlen($doc->get()->id),
|
||||||
|
'The ID should have been auto-generated and had 6 characters');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$autoId = AutoId::None;
|
Configuration::$autoId = AutoId::None;
|
||||||
Configuration::$idStringLength = 16;
|
Configuration::$idStringLength = 16;
|
||||||
|
@ -139,8 +147,8 @@ class DocumentTest extends TestCase
|
||||||
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::EQ('num_value', 3)], TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertEquals('my-key', $doc->id, 'The ID should not have been changed');
|
$this->assertEquals('my-key', $doc->get()->id, 'The ID should not have been changed');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$autoId = AutoId::None;
|
Configuration::$autoId = AutoId::None;
|
||||||
}
|
}
|
||||||
|
@ -150,8 +158,9 @@ class DocumentTest extends TestCase
|
||||||
public function testInsertSucceedsForObjectNoAutoId(): void
|
public function testInsertSucceedsForObjectNoAutoId(): void
|
||||||
{
|
{
|
||||||
Document::insert(ThrowawayDb::TABLE, new TestDocument('turkey', sub: new SubDocument('gobble', 'gobble')));
|
Document::insert(ThrowawayDb::TABLE, new TestDocument('turkey', sub: new SubDocument('gobble', 'gobble')));
|
||||||
$doc = Find::byId(ThrowawayDb::TABLE, 'turkey', TestDocument::class);
|
$tryDoc = Find::byId(ThrowawayDb::TABLE, 'turkey', TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document inserted');
|
$this->assertTrue($tryDoc->isSome(), 'There should have been a document inserted');
|
||||||
|
$doc = $tryDoc->get();
|
||||||
$this->assertEquals('turkey', $doc->id, 'The ID was incorrect');
|
$this->assertEquals('turkey', $doc->id, 'The ID was incorrect');
|
||||||
$this->assertEquals('', $doc->value, 'The value was incorrect');
|
$this->assertEquals('', $doc->value, 'The value was incorrect');
|
||||||
$this->assertEquals(0, $doc->num_value, 'The numeric value was incorrect');
|
$this->assertEquals(0, $doc->num_value, 'The numeric value was incorrect');
|
||||||
|
@ -169,13 +178,13 @@ class DocumentTest extends TestCase
|
||||||
|
|
||||||
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::EQ('value', 'taco')], NumDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertEquals(1, $doc->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::EQ('value', 'burrito')], NumDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertEquals(2, $doc->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 {
|
||||||
Configuration::$autoId = AutoId::None;
|
Configuration::$autoId = AutoId::None;
|
||||||
}
|
}
|
||||||
|
@ -189,8 +198,8 @@ class DocumentTest extends TestCase
|
||||||
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::EQ('value', 'large')], NumDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertEquals(64, $doc->id, 'The ID 64 should have been stored');
|
$this->assertEquals(64, $doc->get()->id, 'The ID 64 should have been stored');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$autoId = AutoId::None;
|
Configuration::$autoId = AutoId::None;
|
||||||
}
|
}
|
||||||
|
@ -204,8 +213,8 @@ class DocumentTest extends TestCase
|
||||||
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::EX('value')], TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertNotEmpty($doc->id, 'The ID should have been auto-generated');
|
$this->assertNotEmpty($doc->get()->id, 'The ID should have been auto-generated');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$autoId = AutoId::None;
|
Configuration::$autoId = AutoId::None;
|
||||||
}
|
}
|
||||||
|
@ -220,8 +229,8 @@ class DocumentTest extends TestCase
|
||||||
$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::EQ('num_value', 14)], TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertEquals($uuid, $doc->id, 'The ID should not have been changed');
|
$this->assertEquals($uuid, $doc->get()->id, 'The ID should not have been changed');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$autoId = AutoId::None;
|
Configuration::$autoId = AutoId::None;
|
||||||
}
|
}
|
||||||
|
@ -236,8 +245,9 @@ class DocumentTest extends TestCase
|
||||||
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::EQ('num_value', 55)], TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertEquals(40, strlen($doc->id), 'The ID should have been auto-generated and had 40 characters');
|
$this->assertEquals(40, strlen($doc->get()->id),
|
||||||
|
'The ID should have been auto-generated and had 40 characters');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$autoId = AutoId::None;
|
Configuration::$autoId = AutoId::None;
|
||||||
Configuration::$idStringLength = 16;
|
Configuration::$idStringLength = 16;
|
||||||
|
@ -252,8 +262,8 @@ class DocumentTest extends TestCase
|
||||||
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::EQ('num_value', 3)], TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertEquals('my-key', $doc->id, 'The ID should not have been changed');
|
$this->assertEquals('my-key', $doc->get()->id, 'The ID should not have been changed');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$autoId = AutoId::None;
|
Configuration::$autoId = AutoId::None;
|
||||||
}
|
}
|
||||||
|
@ -269,14 +279,15 @@ class DocumentTest extends TestCase
|
||||||
{
|
{
|
||||||
Document::save(ThrowawayDb::TABLE, new TestDocument('test', sub: new SubDocument('a', 'b')));
|
Document::save(ThrowawayDb::TABLE, new TestDocument('test', sub: new SubDocument('a', 'b')));
|
||||||
$doc = Find::byId(ThrowawayDb::TABLE, 'one', TestDocument::class);
|
$doc = Find::byId(ThrowawayDb::TABLE, 'one', TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSaveSucceedsWhenADocumentIsUpdated(): void
|
public function testSaveSucceedsWhenADocumentIsUpdated(): void
|
||||||
{
|
{
|
||||||
Document::save(ThrowawayDb::TABLE, new TestDocument('two', num_value: 44));
|
Document::save(ThrowawayDb::TABLE, new TestDocument('two', num_value: 44));
|
||||||
$doc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class);
|
$tryDoc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($tryDoc->isSome(), 'There should have been a document returned');
|
||||||
|
$doc = $tryDoc->get();
|
||||||
$this->assertEquals(44, $doc->num_value, 'The numeric value was not updated');
|
$this->assertEquals(44, $doc->num_value, 'The numeric value was not updated');
|
||||||
$this->assertNull($doc->sub, 'The sub-document should have been null');
|
$this->assertNull($doc->sub, 'The sub-document should have been null');
|
||||||
}
|
}
|
||||||
|
@ -284,8 +295,9 @@ class DocumentTest extends TestCase
|
||||||
public function testUpdateSucceedsWhenReplacingADocument(): void
|
public function testUpdateSucceedsWhenReplacingADocument(): void
|
||||||
{
|
{
|
||||||
Document::update(ThrowawayDb::TABLE, 'one', new TestDocument('one', 'howdy', 8, new SubDocument('y', 'z')));
|
Document::update(ThrowawayDb::TABLE, 'one', new TestDocument('one', 'howdy', 8, new SubDocument('y', 'z')));
|
||||||
$doc = Find::byId(ThrowawayDb::TABLE, 'one', TestDocument::class);
|
$tryDoc = Find::byId(ThrowawayDb::TABLE, 'one', TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertNotFalse($tryDoc->isSome(), 'There should have been a document returned');
|
||||||
|
$doc = $tryDoc->get();
|
||||||
$this->assertEquals('howdy', $doc->value, 'The value was incorrect');
|
$this->assertEquals('howdy', $doc->value, 'The value was incorrect');
|
||||||
$this->assertEquals(8, $doc->num_value, 'The numeric value was incorrect');
|
$this->assertEquals(8, $doc->num_value, 'The numeric value was incorrect');
|
||||||
$this->assertNotNull($doc->sub, 'The sub-document should not have been null');
|
$this->assertNotNull($doc->sub, 'The sub-document should not have been null');
|
||||||
|
@ -297,6 +309,6 @@ class DocumentTest extends TestCase
|
||||||
{
|
{
|
||||||
Document::update(ThrowawayDb::TABLE, 'two-hundred', new TestDocument('200'));
|
Document::update(ThrowawayDb::TABLE, 'two-hundred', new TestDocument('200'));
|
||||||
$doc = Find::byId(ThrowawayDb::TABLE, 'two-hundred', TestDocument::class);
|
$doc = Find::byId(ThrowawayDb::TABLE, 'two-hundred', TestDocument::class);
|
||||||
$this->assertFalse($doc, 'There should not have been a document returned');
|
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Integration\PostgreSQL;
|
namespace Test\Integration\PostgreSQL;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Integration\PostgreSQL;
|
namespace Test\Integration\PostgreSQL;
|
||||||
|
|
||||||
|
@ -49,8 +55,8 @@ class FindTest extends TestCase
|
||||||
public function testByIdSucceedsWhenADocumentIsFound(): void
|
public function testByIdSucceedsWhenADocumentIsFound(): void
|
||||||
{
|
{
|
||||||
$doc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class);
|
$doc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertEquals('two', $doc->id, 'An incorrect document was returned');
|
$this->assertEquals('two', $doc->get()->id, 'An incorrect document was returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('By ID succeeds when a document is found with numeric ID')]
|
#[TestDox('By ID succeeds when a document is found with numeric ID')]
|
||||||
|
@ -59,15 +65,15 @@ class FindTest extends TestCase
|
||||||
Delete::byFields(ThrowawayDb::TABLE, [Field::NEX('absent')]);
|
Delete::byFields(ThrowawayDb::TABLE, [Field::NEX('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->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertEquals(18, $doc->id, 'An incorrect document was returned');
|
$this->assertEquals(18, $doc->get()->id, 'An incorrect document was returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('By ID succeeds when a document is not found')]
|
#[TestDox('By ID succeeds when a document is not found')]
|
||||||
public function testByIdSucceedsWhenADocumentIsNotFound(): void
|
public function testByIdSucceedsWhenADocumentIsNotFound(): void
|
||||||
{
|
{
|
||||||
$doc = Find::byId(ThrowawayDb::TABLE, 'seventy-five', TestDocument::class);
|
$doc = Find::byId(ThrowawayDb::TABLE, 'seventy-five', TestDocument::class);
|
||||||
$this->assertFalse($doc, 'There should not have been a document returned');
|
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testByFieldsSucceedsWhenDocumentsAreFound(): void
|
public function testByFieldsSucceedsWhenDocumentsAreFound(): void
|
||||||
|
@ -123,62 +129,63 @@ 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::EQ('value', 'another')], TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertEquals('two', $doc->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::EQ('sub.foo', 'green')], TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertContains($doc->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::EQ('value', 'absent')], TestDocument::class);
|
||||||
$this->assertFalse($doc, 'There should not have been a document returned');
|
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFirstByContainsSucceedsWhenADocumentIsFound(): void
|
public function testFirstByContainsSucceedsWhenADocumentIsFound(): void
|
||||||
{
|
{
|
||||||
$doc = Find::firstByContains(ThrowawayDb::TABLE, ['value' => 'FIRST!'], TestDocument::class);
|
$doc = Find::firstByContains(ThrowawayDb::TABLE, ['value' => 'FIRST!'], TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertEquals('one', $doc->id, 'The incorrect document was returned');
|
$this->assertEquals('one', $doc->get()->id, 'The incorrect document was returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFirstByContainsSucceedsWhenMultipleDocumentsAreFound(): void
|
public function testFirstByContainsSucceedsWhenMultipleDocumentsAreFound(): void
|
||||||
{
|
{
|
||||||
$doc = Find::firstByContains(ThrowawayDb::TABLE, ['value' => 'purple'], TestDocument::class);
|
$doc = Find::firstByContains(ThrowawayDb::TABLE, ['value' => 'purple'], TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertContains($doc->id, ['four', 'five'], 'An incorrect document was returned');
|
$this->assertContains($doc->get()->id, ['four', 'five'], 'An incorrect document was returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFirstByContainsSucceedsWhenADocumentIsNotFound(): void
|
public function testFirstByContainsSucceedsWhenADocumentIsNotFound(): void
|
||||||
{
|
{
|
||||||
$doc = Find::firstByContains(ThrowawayDb::TABLE, ['value' => 'indigo'], TestDocument::class);
|
$doc = Find::firstByContains(ThrowawayDb::TABLE, ['value' => 'indigo'], TestDocument::class);
|
||||||
$this->assertFalse($doc, 'There should not have been a document returned');
|
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('First by JSON Path succeeds when a document is found')]
|
#[TestDox('First by JSON Path succeeds when a document is found')]
|
||||||
public function testFirstByJsonPathSucceedsWhenADocumentIsFound(): void
|
public function testFirstByJsonPathSucceedsWhenADocumentIsFound(): void
|
||||||
{
|
{
|
||||||
$doc = Find::firstByJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ == 10)', TestDocument::class);
|
$doc = Find::firstByJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ == 10)', TestDocument::class);
|
||||||
$this->assertEquals('two', $doc->id, 'The incorrect document was returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
|
$this->assertEquals('two', $doc->get()->id, 'The incorrect document was returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('First by JSON Path succeeds when multiple documents are found')]
|
#[TestDox('First by JSON Path succeeds when multiple documents are found')]
|
||||||
public function testFirstByJsonPathSucceedsWhenMultipleDocumentsAreFound(): void
|
public function testFirstByJsonPathSucceedsWhenMultipleDocumentsAreFound(): void
|
||||||
{
|
{
|
||||||
$doc = Find::firstByJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ > 10)', TestDocument::class);
|
$doc = Find::firstByJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ > 10)', TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertContains($doc->id, ['four', 'five'], 'An incorrect document was returned');
|
$this->assertContains($doc->get()->id, ['four', 'five'], 'An incorrect document was returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('First by JSON Path succeeds when a document is not found')]
|
#[TestDox('First by JSON Path succeeds when a document is not found')]
|
||||||
public function testFirstByJsonPathSucceedsWhenADocumentIsNotFound(): void
|
public function testFirstByJsonPathSucceedsWhenADocumentIsNotFound(): void
|
||||||
{
|
{
|
||||||
$doc = Find::firstByJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ > 100)', TestDocument::class);
|
$doc = Find::firstByJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ > 100)', TestDocument::class);
|
||||||
$this->assertFalse($doc, 'There should not have been a document returned');
|
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Integration\PostgreSQL;
|
namespace Test\Integration\PostgreSQL;
|
||||||
|
|
||||||
|
@ -33,8 +39,8 @@ class PatchTest extends TestCase
|
||||||
{
|
{
|
||||||
Patch::byId(ThrowawayDb::TABLE, 'one', ['num_value' => 44]);
|
Patch::byId(ThrowawayDb::TABLE, 'one', ['num_value' => 44]);
|
||||||
$doc = Find::byId(ThrowawayDb::TABLE, 'one', TestDocument::class);
|
$doc = Find::byId(ThrowawayDb::TABLE, 'one', TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertEquals(44, $doc->num_value, 'The updated document is not correct');
|
$this->assertEquals(44, $doc->get()->num_value, 'The updated document is not correct');
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('By ID succeeds when no document is updated')]
|
#[TestDox('By ID succeeds when no document is updated')]
|
||||||
|
@ -64,8 +70,9 @@ class PatchTest extends TestCase
|
||||||
public function testByContainsSucceedsWhenDocumentsAreUpdated(): void
|
public function testByContainsSucceedsWhenDocumentsAreUpdated(): void
|
||||||
{
|
{
|
||||||
Patch::byContains(ThrowawayDb::TABLE, ['value' => 'another'], ['num_value' => 12]);
|
Patch::byContains(ThrowawayDb::TABLE, ['value' => 'another'], ['num_value' => 12]);
|
||||||
$doc = Find::firstByContains(ThrowawayDb::TABLE, ['value' => 'another'], TestDocument::class);
|
$tryDoc = Find::firstByContains(ThrowawayDb::TABLE, ['value' => 'another'], TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($tryDoc->isSome(), 'There should have been a document returned');
|
||||||
|
$doc = $tryDoc->get();
|
||||||
$this->assertEquals('two', $doc->id, 'An incorrect document was returned');
|
$this->assertEquals('two', $doc->id, 'An incorrect document was returned');
|
||||||
$this->assertEquals(12, $doc->num_value, 'The document was not patched');
|
$this->assertEquals(12, $doc->num_value, 'The document was not patched');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Integration\PostgreSQL;
|
namespace Test\Integration\PostgreSQL;
|
||||||
|
|
||||||
|
@ -32,8 +38,9 @@ class RemoveFieldsTest extends TestCase
|
||||||
public function testByIdSucceedsWhenFieldsAreRemoved(): void
|
public function testByIdSucceedsWhenFieldsAreRemoved(): void
|
||||||
{
|
{
|
||||||
RemoveFields::byId(ThrowawayDb::TABLE, 'two', ['sub', 'value']);
|
RemoveFields::byId(ThrowawayDb::TABLE, 'two', ['sub', 'value']);
|
||||||
$doc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class);
|
$tryDoc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($tryDoc->isSome(), 'There should have been a document returned');
|
||||||
|
$doc = $tryDoc->get();
|
||||||
$this->assertEquals('', $doc->value, 'Value should have been blank (its default value)');
|
$this->assertEquals('', $doc->value, 'Value should have been blank (its default value)');
|
||||||
$this->assertNull($doc->sub, 'Sub-document should have been null');
|
$this->assertNull($doc->sub, 'Sub-document should have been null');
|
||||||
}
|
}
|
||||||
|
@ -56,8 +63,8 @@ class RemoveFieldsTest extends TestCase
|
||||||
{
|
{
|
||||||
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 17)], ['sub']);
|
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 17)], ['sub']);
|
||||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 17)], TestDocument::class);
|
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 17)], TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertNull($doc->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
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
* @see https://github.com/Zaid-Ajaj/ThrowawayDb The origin concept
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Integration\PostgreSQL;
|
namespace Test\Integration\PostgreSQL;
|
||||||
|
|
||||||
use BitBadger\PDODocument\{AutoId, Configuration, Custom, Definition, Document, DocumentException, Mode};
|
use BitBadger\PDODocument\{AutoId, Configuration, Custom, Definition, Document, DocumentException};
|
||||||
use Random\RandomException;
|
use Random\RandomException;
|
||||||
use Test\Integration\{SubDocument, TestDocument};
|
use Test\Integration\{SubDocument, TestDocument};
|
||||||
|
|
||||||
|
@ -12,21 +19,21 @@ use Test\Integration\{SubDocument, TestDocument};
|
||||||
class ThrowawayDb
|
class ThrowawayDb
|
||||||
{
|
{
|
||||||
/** @var string The table used for document manipulation */
|
/** @var string The table used for document manipulation */
|
||||||
public const TABLE = "test_table";
|
public const TABLE = 'test_table';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configure the document library for the given database (or the main PostgreSQL connection, if the database name
|
* Configure the document library for the given database (or the main PostgreSQL connection, if the database name
|
||||||
* is not provided; this is used for creating and dropping databases)
|
* is not provided; this is used for creating and dropping databases)
|
||||||
*
|
*
|
||||||
* @param string|null $dbName The name of the database to configure (optional, defaults to env or "postgres")
|
* @param string|null $dbName The name of the database to configure (optional, defaults to env or "postgres")
|
||||||
|
* @throws DocumentException If any is encountered
|
||||||
*/
|
*/
|
||||||
private static function configure(?string $dbName = null): void
|
private static function configure(?string $dbName = null): void
|
||||||
{
|
{
|
||||||
Configuration::$pdoDSN = sprintf("pgsql:host=%s;dbname=%s", $_ENV['PDO_DOC_PGSQL_HOST'] ?? 'localhost',
|
Configuration::useDSN(sprintf("pgsql:host=%s;dbname=%s", $_ENV['PDO_DOC_PGSQL_HOST'] ?? 'localhost',
|
||||||
$dbName ?? $_ENV['PDO_DOC_PGSQL_DB'] ?? 'postgres');
|
$dbName ?? $_ENV['PDO_DOC_PGSQL_DB'] ?? 'postgres'));
|
||||||
Configuration::$username = $_ENV['PDO_DOC_PGSQL_USER'] ?? 'postgres';
|
Configuration::$username = $_ENV['PDO_DOC_PGSQL_USER'] ?? 'postgres';
|
||||||
Configuration::$password = $_ENV['PDO_DOC_PGSQL_PASS'] ?? 'postgres';
|
Configuration::$password = $_ENV['PDO_DOC_PGSQL_PASS'] ?? 'postgres';
|
||||||
Configuration::$mode = Mode::PgSQL;
|
|
||||||
Configuration::resetPDO();
|
Configuration::resetPDO();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,10 +73,9 @@ class ThrowawayDb
|
||||||
{
|
{
|
||||||
self::configure();
|
self::configure();
|
||||||
Custom::nonQuery("DROP DATABASE IF EXISTS $dbName WITH (FORCE)", []);
|
Custom::nonQuery("DROP DATABASE IF EXISTS $dbName WITH (FORCE)", []);
|
||||||
Configuration::$pdoDSN = '';
|
Configuration::useDSN('');
|
||||||
Configuration::$username = null;
|
Configuration::$username = null;
|
||||||
Configuration::$password = null;
|
Configuration::$password = null;
|
||||||
Configuration::$mode = null;
|
|
||||||
Configuration::resetPDO();
|
Configuration::resetPDO();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Integration\SQLite;
|
namespace Test\Integration\SQLite;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Integration\SQLite;
|
namespace Test\Integration\SQLite;
|
||||||
|
|
||||||
|
@ -86,15 +92,15 @@ class CustomTest extends TestCase
|
||||||
{
|
{
|
||||||
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id", [':id' => 'one'],
|
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id", [':id' => 'one'],
|
||||||
new DocumentMapper(TestDocument::class));
|
new DocumentMapper(TestDocument::class));
|
||||||
$this->assertNotNull($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertEquals('one', $doc->id, 'The incorrect document was returned');
|
$this->assertEquals('one', $doc->get()->id, 'The incorrect document was returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSingleSucceedsWhenARowIsNotFound(): void
|
public function testSingleSucceedsWhenARowIsNotFound(): void
|
||||||
{
|
{
|
||||||
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id",
|
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id",
|
||||||
[':id' => 'eighty'], new DocumentMapper(TestDocument::class));
|
[':id' => 'eighty'], new DocumentMapper(TestDocument::class));
|
||||||
$this->assertFalse($doc, 'There should not have been a document returned');
|
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNonQuerySucceedsWhenOperatingOnData()
|
public function testNonQuerySucceedsWhenOperatingOnData()
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Integration\SQLite;
|
namespace Test\Integration\SQLite;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Integration\SQLite;
|
namespace Test\Integration\SQLite;
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Integration\SQLite;
|
namespace Test\Integration\SQLite;
|
||||||
|
|
||||||
use BitBadger\PDODocument\{DocumentList, Query};
|
use BitBadger\PDODocument\{DocumentException, DocumentList, Query};
|
||||||
use BitBadger\PDODocument\Mapper\DocumentMapper;
|
use BitBadger\PDODocument\Mapper\DocumentMapper;
|
||||||
use PHPUnit\Framework\Attributes\TestDox;
|
use PHPUnit\Framework\Attributes\TestDox;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
@ -37,7 +43,7 @@ class DocumentListTest extends TestCase
|
||||||
$list = null;
|
$list = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItems(): void
|
public function testItemsSucceeds(): void
|
||||||
{
|
{
|
||||||
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
||||||
new DocumentMapper(TestDocument::class));
|
new DocumentMapper(TestDocument::class));
|
||||||
|
@ -51,6 +57,18 @@ class DocumentListTest extends TestCase
|
||||||
$this->assertEquals(5, $count, 'There should have been 5 documents returned');
|
$this->assertEquals(5, $count, 'There should have been 5 documents returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testItemsFailsWhenAlreadyConsumed(): void
|
||||||
|
{
|
||||||
|
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
||||||
|
new DocumentMapper(TestDocument::class));
|
||||||
|
$this->assertNotNull($list, 'There should have been a document list created');
|
||||||
|
$this->assertTrue($list->hasItems(), 'There should be items in the list');
|
||||||
|
$ignored = iterator_to_array($list->items());
|
||||||
|
$this->assertFalse($list->hasItems(), 'The list should no longer have items');
|
||||||
|
$this->expectException(DocumentException::class);
|
||||||
|
iterator_to_array($list->items());
|
||||||
|
}
|
||||||
|
|
||||||
public function testHasItemsSucceedsWithEmptyResults(): void
|
public function testHasItemsSucceedsWithEmptyResults(): void
|
||||||
{
|
{
|
||||||
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE) . " WHERE data->>'num_value' < 0", [],
|
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE) . " WHERE data->>'num_value' < 0", [],
|
||||||
|
@ -70,4 +88,38 @@ class DocumentListTest extends TestCase
|
||||||
}
|
}
|
||||||
$this->assertFalse($list->hasItems(), 'There should be no remaining items in the list');
|
$this->assertFalse($list->hasItems(), 'There should be no remaining items in the list');
|
||||||
}
|
}
|
||||||
|
public function testMapSucceeds(): void
|
||||||
|
{
|
||||||
|
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
||||||
|
new DocumentMapper(TestDocument::class));
|
||||||
|
$this->assertNotNull($list, 'There should have been a document list created');
|
||||||
|
$this->assertTrue($list->hasItems(), 'There should be items in the list');
|
||||||
|
foreach ($list->map(fn($doc) => strrev($doc->id)) as $mapped) {
|
||||||
|
$this->assertContains($mapped, ['eno', 'owt', 'eerht', 'ruof', 'evif'],
|
||||||
|
'An unexpected mapped value was returned');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIterSucceeds(): void
|
||||||
|
{
|
||||||
|
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
||||||
|
new DocumentMapper(TestDocument::class));
|
||||||
|
$this->assertNotNull($list, 'There should have been a document list created');
|
||||||
|
$this->assertTrue($list->hasItems(), 'There should be items in the list');
|
||||||
|
$splats = [];
|
||||||
|
$list->iter(function ($doc) use (&$splats) { $splats[] = str_repeat('*', strlen($doc->id)); });
|
||||||
|
$this->assertEquals('*** *** ***** **** ****', implode(' ', $splats),
|
||||||
|
'Iteration did not have the expected result');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMapToArraySucceeds(): void
|
||||||
|
{
|
||||||
|
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
||||||
|
new DocumentMapper(TestDocument::class));
|
||||||
|
$this->assertNotNull($list, 'There should have been a document list created');
|
||||||
|
$this->assertTrue($list->hasItems(), 'There should be items in the list');
|
||||||
|
$lookup = $list->mapToArray(fn($it) => $it->id, fn($it) => $it->value);
|
||||||
|
$expected = ['one' => 'FIRST!', 'two' => 'another', 'three' => '', 'four' => 'purple', 'five' => 'purple'];
|
||||||
|
$this->assertEquals($expected, $lookup, 'The array was not mapped correctly');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Integration\SQLite;
|
namespace Test\Integration\SQLite;
|
||||||
|
|
||||||
|
@ -33,8 +39,9 @@ class DocumentTest extends TestCase
|
||||||
public function testInsertSucceedsForArrayNoAutoId(): void
|
public function testInsertSucceedsForArrayNoAutoId(): void
|
||||||
{
|
{
|
||||||
Document::insert(ThrowawayDb::TABLE, ['id' => 'turkey', 'sub' => ['foo' => 'gobble', 'bar' => 'gobble']]);
|
Document::insert(ThrowawayDb::TABLE, ['id' => 'turkey', 'sub' => ['foo' => 'gobble', 'bar' => 'gobble']]);
|
||||||
$doc = Find::byId(ThrowawayDb::TABLE, 'turkey', TestDocument::class);
|
$tryDoc = Find::byId(ThrowawayDb::TABLE, 'turkey', TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document inserted');
|
$this->assertTrue($tryDoc->isSome(), 'There should have been a document inserted');
|
||||||
|
$doc = $tryDoc->get();
|
||||||
$this->assertEquals('turkey', $doc->id, 'The ID was incorrect');
|
$this->assertEquals('turkey', $doc->id, 'The ID was incorrect');
|
||||||
$this->assertEquals('', $doc->value, 'The value was incorrect');
|
$this->assertEquals('', $doc->value, 'The value was incorrect');
|
||||||
$this->assertEquals(0, $doc->num_value, 'The numeric value was incorrect');
|
$this->assertEquals(0, $doc->num_value, 'The numeric value was incorrect');
|
||||||
|
@ -52,15 +59,15 @@ class DocumentTest extends TestCase
|
||||||
|
|
||||||
Document::insert(ThrowawayDb::TABLE, ['id' => 0, 'value' => 'new', 'num_value' => 8]);
|
Document::insert(ThrowawayDb::TABLE, ['id' => 0, 'value' => 'new', 'num_value' => 8]);
|
||||||
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE, [], new ArrayMapper());
|
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE, [], new ArrayMapper());
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$obj = json_decode($doc['data']);
|
$obj = json_decode($doc->get()['data']);
|
||||||
$this->assertEquals(1, $obj->id, 'The ID 1 should have been auto-generated');
|
$this->assertEquals(1, $obj->id, 'The ID 1 should have been auto-generated');
|
||||||
|
|
||||||
Document::insert(ThrowawayDb::TABLE, ['id' => 0, 'value' => 'again', 'num_value' => 7]);
|
Document::insert(ThrowawayDb::TABLE, ['id' => 0, 'value' => 'again', 'num_value' => 7]);
|
||||||
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = 2", [],
|
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = 2", [],
|
||||||
new ArrayMapper());
|
new ArrayMapper());
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$obj = json_decode($doc['data']);
|
$obj = json_decode($doc->get()['data']);
|
||||||
$this->assertEquals(2, $obj->id, 'The ID 2 should have been auto-generated');
|
$this->assertEquals(2, $obj->id, 'The ID 2 should have been auto-generated');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$autoId = AutoId::None;
|
Configuration::$autoId = AutoId::None;
|
||||||
|
@ -75,8 +82,8 @@ class DocumentTest extends TestCase
|
||||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||||
Document::insert(ThrowawayDb::TABLE, ['id' => 7, 'value' => 'new', 'num_value' => 8]);
|
Document::insert(ThrowawayDb::TABLE, ['id' => 7, 'value' => 'new', 'num_value' => 8]);
|
||||||
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE, [], new ArrayMapper());
|
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE, [], new ArrayMapper());
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$obj = json_decode($doc['data']);
|
$obj = json_decode($doc->get()['data']);
|
||||||
$this->assertEquals(7, $obj->id, 'The ID 7 should have been stored');
|
$this->assertEquals(7, $obj->id, 'The ID 7 should have been stored');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$autoId = AutoId::None;
|
Configuration::$autoId = AutoId::None;
|
||||||
|
@ -91,8 +98,8 @@ class DocumentTest extends TestCase
|
||||||
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::EQ('num_value', 5)], TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertNotEmpty($doc->id, 'The ID should have been auto-generated');
|
$this->assertNotEmpty($doc->get()->id, 'The ID should have been auto-generated');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$autoId = AutoId::None;
|
Configuration::$autoId = AutoId::None;
|
||||||
}
|
}
|
||||||
|
@ -107,8 +114,8 @@ class DocumentTest extends TestCase
|
||||||
$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::EQ('num_value', 12)], TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertEquals($uuid, $doc->id, 'The ID should not have been changed');
|
$this->assertEquals($uuid, $doc->get()->id, 'The ID should not have been changed');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$autoId = AutoId::None;
|
Configuration::$autoId = AutoId::None;
|
||||||
}
|
}
|
||||||
|
@ -123,8 +130,9 @@ class DocumentTest extends TestCase
|
||||||
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::EQ('num_value', 8)], TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertEquals(6, strlen($doc->id), 'The ID should have been auto-generated and had 6 characters');
|
$this->assertEquals(6, strlen($doc->get()->id),
|
||||||
|
'The ID should have been auto-generated and had 6 characters');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$autoId = AutoId::None;
|
Configuration::$autoId = AutoId::None;
|
||||||
Configuration::$idStringLength = 16;
|
Configuration::$idStringLength = 16;
|
||||||
|
@ -139,8 +147,8 @@ class DocumentTest extends TestCase
|
||||||
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::EQ('num_value', 3)], TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertEquals('my-key', $doc->id, 'The ID should not have been changed');
|
$this->assertEquals('my-key', $doc->get()->id, 'The ID should not have been changed');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$autoId = AutoId::None;
|
Configuration::$autoId = AutoId::None;
|
||||||
}
|
}
|
||||||
|
@ -150,8 +158,9 @@ class DocumentTest extends TestCase
|
||||||
public function testInsertSucceedsForObjectNoAutoId(): void
|
public function testInsertSucceedsForObjectNoAutoId(): void
|
||||||
{
|
{
|
||||||
Document::insert(ThrowawayDb::TABLE, new TestDocument('turkey', sub: new SubDocument('gobble', 'gobble')));
|
Document::insert(ThrowawayDb::TABLE, new TestDocument('turkey', sub: new SubDocument('gobble', 'gobble')));
|
||||||
$doc = Find::byId(ThrowawayDb::TABLE, 'turkey', TestDocument::class);
|
$tryDoc = Find::byId(ThrowawayDb::TABLE, 'turkey', TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document inserted');
|
$this->assertNotFalse($tryDoc->isSome(), 'There should have been a document inserted');
|
||||||
|
$doc = $tryDoc->get();
|
||||||
$this->assertEquals('turkey', $doc->id, 'The ID was incorrect');
|
$this->assertEquals('turkey', $doc->id, 'The ID was incorrect');
|
||||||
$this->assertEquals('', $doc->value, 'The value was incorrect');
|
$this->assertEquals('', $doc->value, 'The value was incorrect');
|
||||||
$this->assertEquals(0, $doc->num_value, 'The numeric value was incorrect');
|
$this->assertEquals(0, $doc->num_value, 'The numeric value was incorrect');
|
||||||
|
@ -169,13 +178,13 @@ class DocumentTest extends TestCase
|
||||||
|
|
||||||
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::EQ('value', 'taco')], NumDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertEquals(1, $doc->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::EQ('value', 'burrito')], NumDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertEquals(2, $doc->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 {
|
||||||
Configuration::$autoId = AutoId::None;
|
Configuration::$autoId = AutoId::None;
|
||||||
}
|
}
|
||||||
|
@ -189,8 +198,8 @@ class DocumentTest extends TestCase
|
||||||
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::EQ('value', 'large')], NumDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertEquals(64, $doc->id, 'The ID 64 should have been stored');
|
$this->assertEquals(64, $doc->get()->id, 'The ID 64 should have been stored');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$autoId = AutoId::None;
|
Configuration::$autoId = AutoId::None;
|
||||||
}
|
}
|
||||||
|
@ -204,8 +213,8 @@ class DocumentTest extends TestCase
|
||||||
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::EX('value')], TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertNotEmpty($doc->id, 'The ID should have been auto-generated');
|
$this->assertNotEmpty($doc->get()->id, 'The ID should have been auto-generated');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$autoId = AutoId::None;
|
Configuration::$autoId = AutoId::None;
|
||||||
}
|
}
|
||||||
|
@ -220,8 +229,8 @@ class DocumentTest extends TestCase
|
||||||
$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::EQ('num_value', 14)], TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertEquals($uuid, $doc->id, 'The ID should not have been changed');
|
$this->assertEquals($uuid, $doc->get()->id, 'The ID should not have been changed');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$autoId = AutoId::None;
|
Configuration::$autoId = AutoId::None;
|
||||||
}
|
}
|
||||||
|
@ -236,8 +245,9 @@ class DocumentTest extends TestCase
|
||||||
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::EQ('num_value', 55)], TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertEquals(40, strlen($doc->id), 'The ID should have been auto-generated and had 40 characters');
|
$this->assertEquals(40, strlen($doc->get()->id),
|
||||||
|
'The ID should have been auto-generated and had 40 characters');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$autoId = AutoId::None;
|
Configuration::$autoId = AutoId::None;
|
||||||
Configuration::$idStringLength = 16;
|
Configuration::$idStringLength = 16;
|
||||||
|
@ -252,8 +262,8 @@ class DocumentTest extends TestCase
|
||||||
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::EQ('num_value', 3)], TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertEquals('my-key', $doc->id, 'The ID should not have been changed');
|
$this->assertEquals('my-key', $doc->get()->id, 'The ID should not have been changed');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$autoId = AutoId::None;
|
Configuration::$autoId = AutoId::None;
|
||||||
}
|
}
|
||||||
|
@ -269,14 +279,15 @@ class DocumentTest extends TestCase
|
||||||
{
|
{
|
||||||
Document::save(ThrowawayDb::TABLE, new TestDocument('test', sub: new SubDocument('a', 'b')));
|
Document::save(ThrowawayDb::TABLE, new TestDocument('test', sub: new SubDocument('a', 'b')));
|
||||||
$doc = Find::byId(ThrowawayDb::TABLE, 'one', TestDocument::class);
|
$doc = Find::byId(ThrowawayDb::TABLE, 'one', TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSaveSucceedsWhenADocumentIsUpdated(): void
|
public function testSaveSucceedsWhenADocumentIsUpdated(): void
|
||||||
{
|
{
|
||||||
Document::save(ThrowawayDb::TABLE, new TestDocument('two', num_value: 44));
|
Document::save(ThrowawayDb::TABLE, new TestDocument('two', num_value: 44));
|
||||||
$doc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class);
|
$tryDoc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($tryDoc->isSome(), 'There should have been a document returned');
|
||||||
|
$doc = $tryDoc->get();
|
||||||
$this->assertEquals(44, $doc->num_value, 'The numeric value was not updated');
|
$this->assertEquals(44, $doc->num_value, 'The numeric value was not updated');
|
||||||
$this->assertNull($doc->sub, 'The sub-document should have been null');
|
$this->assertNull($doc->sub, 'The sub-document should have been null');
|
||||||
}
|
}
|
||||||
|
@ -284,8 +295,9 @@ class DocumentTest extends TestCase
|
||||||
public function testUpdateSucceedsWhenReplacingADocument(): void
|
public function testUpdateSucceedsWhenReplacingADocument(): void
|
||||||
{
|
{
|
||||||
Document::update(ThrowawayDb::TABLE, 'one', new TestDocument('one', 'howdy', 8, new SubDocument('y', 'z')));
|
Document::update(ThrowawayDb::TABLE, 'one', new TestDocument('one', 'howdy', 8, new SubDocument('y', 'z')));
|
||||||
$doc = Find::byId(ThrowawayDb::TABLE, 'one', TestDocument::class);
|
$tryDoc = Find::byId(ThrowawayDb::TABLE, 'one', TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($tryDoc->isSome(), 'There should have been a document returned');
|
||||||
|
$doc = $tryDoc->get();
|
||||||
$this->assertEquals('howdy', $doc->value, 'The value was incorrect');
|
$this->assertEquals('howdy', $doc->value, 'The value was incorrect');
|
||||||
$this->assertEquals(8, $doc->num_value, 'The numeric value was incorrect');
|
$this->assertEquals(8, $doc->num_value, 'The numeric value was incorrect');
|
||||||
$this->assertNotNull($doc->sub, 'The sub-document should not have been null');
|
$this->assertNotNull($doc->sub, 'The sub-document should not have been null');
|
||||||
|
@ -297,6 +309,6 @@ class DocumentTest extends TestCase
|
||||||
{
|
{
|
||||||
Document::update(ThrowawayDb::TABLE, 'two-hundred', new TestDocument('200'));
|
Document::update(ThrowawayDb::TABLE, 'two-hundred', new TestDocument('200'));
|
||||||
$doc = Find::byId(ThrowawayDb::TABLE, 'two-hundred', TestDocument::class);
|
$doc = Find::byId(ThrowawayDb::TABLE, 'two-hundred', TestDocument::class);
|
||||||
$this->assertFalse($doc, 'There should not have been a document returned');
|
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Integration\SQLite;
|
namespace Test\Integration\SQLite;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Integration\SQLite;
|
namespace Test\Integration\SQLite;
|
||||||
|
|
||||||
|
@ -49,8 +55,8 @@ class FindTest extends TestCase
|
||||||
public function testByIdSucceedsWhenADocumentIsFound(): void
|
public function testByIdSucceedsWhenADocumentIsFound(): void
|
||||||
{
|
{
|
||||||
$doc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class);
|
$doc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertEquals('two', $doc->id, 'An incorrect document was returned');
|
$this->assertEquals('two', $doc->get()->id, 'An incorrect document was returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('By ID succeeds when a document is found with numeric ID')]
|
#[TestDox('By ID succeeds when a document is found with numeric ID')]
|
||||||
|
@ -58,15 +64,15 @@ class FindTest extends TestCase
|
||||||
{
|
{
|
||||||
Document::insert(ThrowawayDb::TABLE, ['id' => 18, 'value' => 'howdy']);
|
Document::insert(ThrowawayDb::TABLE, ['id' => 18, 'value' => 'howdy']);
|
||||||
$doc = Find::byId(ThrowawayDb::TABLE, 18, TestDocument::class);
|
$doc = Find::byId(ThrowawayDb::TABLE, 18, TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertEquals('18', $doc->id, 'An incorrect document was returned');
|
$this->assertEquals('18', $doc->get()->id, 'An incorrect document was returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('By ID succeeds when a document is not found')]
|
#[TestDox('By ID succeeds when a document is not found')]
|
||||||
public function testByIdSucceedsWhenADocumentIsNotFound(): void
|
public function testByIdSucceedsWhenADocumentIsNotFound(): void
|
||||||
{
|
{
|
||||||
$doc = Find::byId(ThrowawayDb::TABLE, 'seventy-five', TestDocument::class);
|
$doc = Find::byId(ThrowawayDb::TABLE, 'seventy-five', TestDocument::class);
|
||||||
$this->assertFalse($doc, 'There should not have been a document returned');
|
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testByFieldsSucceedsWhenDocumentsAreFound(): void
|
public function testByFieldsSucceedsWhenDocumentsAreFound(): void
|
||||||
|
@ -101,21 +107,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::EQ('value', 'another')], TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertEquals('two', $doc->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::EQ('sub.foo', 'green')], TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertContains($doc->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::EQ('value', 'absent')], TestDocument::class);
|
||||||
$this->assertFalse($doc, 'There should not have been a document returned');
|
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFirstByContainsFails(): void
|
public function testFirstByContainsFails(): void
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Integration\SQLite;
|
namespace Test\Integration\SQLite;
|
||||||
|
|
||||||
|
@ -33,8 +39,8 @@ class PatchTest extends TestCase
|
||||||
{
|
{
|
||||||
Patch::byId(ThrowawayDb::TABLE, 'one', ['num_value' => 44]);
|
Patch::byId(ThrowawayDb::TABLE, 'one', ['num_value' => 44]);
|
||||||
$doc = Find::byId(ThrowawayDb::TABLE, 'one', TestDocument::class);
|
$doc = Find::byId(ThrowawayDb::TABLE, 'one', TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertEquals(44, $doc->num_value, 'The updated document is not correct');
|
$this->assertEquals(44, $doc->get()->num_value, 'The updated document is not correct');
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('By ID succeeds when no document is updated')]
|
#[TestDox('By ID succeeds when no document is updated')]
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Integration\SQLite;
|
namespace Test\Integration\SQLite;
|
||||||
|
|
||||||
|
@ -32,8 +38,9 @@ class RemoveFieldsTest extends TestCase
|
||||||
public function testByIdSucceedsWhenFieldsAreRemoved(): void
|
public function testByIdSucceedsWhenFieldsAreRemoved(): void
|
||||||
{
|
{
|
||||||
RemoveFields::byId(ThrowawayDb::TABLE, 'two', ['sub', 'value']);
|
RemoveFields::byId(ThrowawayDb::TABLE, 'two', ['sub', 'value']);
|
||||||
$doc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class);
|
$tryDoc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($tryDoc->isSome(), 'There should have been a document returned');
|
||||||
|
$doc = $tryDoc->get();
|
||||||
$this->assertEquals('', $doc->value, 'Value should have been blank (its default value)');
|
$this->assertEquals('', $doc->value, 'Value should have been blank (its default value)');
|
||||||
$this->assertNull($doc->sub, 'Sub-document should have been null');
|
$this->assertNull($doc->sub, 'Sub-document should have been null');
|
||||||
}
|
}
|
||||||
|
@ -56,8 +63,8 @@ class RemoveFieldsTest extends TestCase
|
||||||
{
|
{
|
||||||
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 17)], ['sub']);
|
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 17)], ['sub']);
|
||||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 17)], TestDocument::class);
|
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 17)], TestDocument::class);
|
||||||
$this->assertNotFalse($doc, 'There should have been a document returned');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
$this->assertNull($doc->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
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
* @see https://github.com/Zaid-Ajaj/ThrowawayDb The origin concept
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Integration\SQLite;
|
namespace Test\Integration\SQLite;
|
||||||
|
|
||||||
use BitBadger\PDODocument\{AutoId, Configuration, Definition, Document, DocumentException, Mode};
|
use BitBadger\PDODocument\{AutoId, Configuration, Definition, Document, DocumentException};
|
||||||
use Random\RandomException;
|
use Random\RandomException;
|
||||||
use Test\Integration\{SubDocument, TestDocument};
|
use Test\Integration\{SubDocument, TestDocument};
|
||||||
|
|
||||||
|
@ -12,7 +19,7 @@ use Test\Integration\{SubDocument, TestDocument};
|
||||||
class ThrowawayDb
|
class ThrowawayDb
|
||||||
{
|
{
|
||||||
/** @var string The table used for document manipulation */
|
/** @var string The table used for document manipulation */
|
||||||
public const TABLE = "test_table";
|
public const TABLE = 'test_table';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a throwaway SQLite database
|
* Create a throwaway SQLite database
|
||||||
|
@ -24,8 +31,7 @@ class ThrowawayDb
|
||||||
public static function create(bool $withData = true): string
|
public static function create(bool $withData = true): string
|
||||||
{
|
{
|
||||||
$fileName = sprintf('throwaway-%s.db', AutoId::generateRandom(10));
|
$fileName = sprintf('throwaway-%s.db', AutoId::generateRandom(10));
|
||||||
Configuration::$pdoDSN = "sqlite:./$fileName";
|
Configuration::useDSN("sqlite:./$fileName");
|
||||||
Configuration::$mode = Mode::SQLite;
|
|
||||||
Configuration::resetPDO();
|
Configuration::resetPDO();
|
||||||
|
|
||||||
if ($withData) {
|
if ($withData) {
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Unit;
|
namespace Test\Unit;
|
||||||
|
|
||||||
|
@ -46,7 +52,7 @@ class ConfigurationTest extends TestCase
|
||||||
public function testDbConnFailsWhenNoDSNSpecified(): void
|
public function testDbConnFailsWhenNoDSNSpecified(): void
|
||||||
{
|
{
|
||||||
$this->expectException(DocumentException::class);
|
$this->expectException(DocumentException::class);
|
||||||
Configuration::$pdoDSN = '';
|
Configuration::useDSN('');
|
||||||
Configuration::dbConn();
|
Configuration::dbConn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Unit;
|
namespace Test\Unit;
|
||||||
|
|
||||||
|
@ -13,7 +19,7 @@ use PHPUnit\Framework\TestCase;
|
||||||
#[TestDox('Document Exception (Unit tests)')]
|
#[TestDox('Document Exception (Unit tests)')]
|
||||||
class DocumentExceptionTest extends TestCase
|
class DocumentExceptionTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testConstructorSucceedsWithCodeAndPriorException()
|
public function testConstructorSucceedsWithCodeAndPriorException(): void
|
||||||
{
|
{
|
||||||
$priorEx = new Exception('Uh oh');
|
$priorEx = new Exception('Uh oh');
|
||||||
$ex = new DocumentException('Test Exception', 17, $priorEx);
|
$ex = new DocumentException('Test Exception', 17, $priorEx);
|
||||||
|
@ -23,7 +29,7 @@ class DocumentExceptionTest extends TestCase
|
||||||
$this->assertSame($priorEx, $ex->getPrevious(), 'Prior exception not filled properly');
|
$this->assertSame($priorEx, $ex->getPrevious(), 'Prior exception not filled properly');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testConstructorSucceedsWithoutCodeAndPriorException()
|
public function testConstructorSucceedsWithoutCodeAndPriorException(): void
|
||||||
{
|
{
|
||||||
$ex = new DocumentException('Oops');
|
$ex = new DocumentException('Oops');
|
||||||
$this->assertNotNull($ex, 'The exception should not have been null');
|
$this->assertNotNull($ex, 'The exception should not have been null');
|
||||||
|
@ -32,14 +38,14 @@ class DocumentExceptionTest extends TestCase
|
||||||
$this->assertNull($ex->getPrevious(), 'Prior exception should have been null');
|
$this->assertNull($ex->getPrevious(), 'Prior exception should have been null');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testToStringSucceedsWithoutCode()
|
public function testToStringSucceedsWithoutCode(): void
|
||||||
{
|
{
|
||||||
$ex = new DocumentException('Test failure');
|
$ex = new DocumentException('Test failure');
|
||||||
$this->assertEquals("BitBadger\PDODocument\DocumentException: Test failure\n", "$ex",
|
$this->assertEquals("BitBadger\PDODocument\DocumentException: Test failure\n", "$ex",
|
||||||
'toString not generated correctly');
|
'toString not generated correctly');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testToStringSucceedsWithCode()
|
public function testToStringSucceedsWithCode(): void
|
||||||
{
|
{
|
||||||
$ex = new DocumentException('Oof', -6);
|
$ex = new DocumentException('Oof', -6);
|
||||||
$this->assertEquals("BitBadger\PDODocument\DocumentException: [-6] Oof\n", "$ex",
|
$this->assertEquals("BitBadger\PDODocument\DocumentException: [-6] Oof\n", "$ex",
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Unit;
|
namespace Test\Unit;
|
||||||
|
|
||||||
|
@ -12,13 +18,15 @@ use PHPUnit\Framework\TestCase;
|
||||||
#[TestDox('Field Match (Unit tests)')]
|
#[TestDox('Field Match (Unit tests)')]
|
||||||
class FieldMatchTest extends TestCase
|
class FieldMatchTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testToStringSucceedsForAll(): void
|
#[TestDox('To SQL succeeds for all')]
|
||||||
|
public function testToSQLSucceedsForAll(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals('AND', FieldMatch::All->toString(), 'All should have returned AND');
|
$this->assertEquals('AND', FieldMatch::All->toSQL(), 'All should have returned AND');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testToStringSucceedsForAny(): void
|
#[TestDox('To SQL succeeds for any')]
|
||||||
|
public function testToSQLSucceedsForAny(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals('OR', FieldMatch::Any->toString(), 'Any should have returned OR');
|
$this->assertEquals('OR', FieldMatch::Any->toSQL(), 'Any should have returned OR');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Unit;
|
namespace Test\Unit;
|
||||||
|
|
||||||
|
@ -40,232 +46,232 @@ class FieldTest extends TestCase
|
||||||
#[TestDox('To where succeeds for EX without qualifier for PostgreSQL')]
|
#[TestDox('To where succeeds for EX without qualifier for PostgreSQL')]
|
||||||
public function testToWhereSucceedsForEXWithoutQualifierForPostgreSQL(): void
|
public function testToWhereSucceedsForEXWithoutQualifierForPostgreSQL(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = 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::EX('that_field')->toWhere(),
|
||||||
'WHERE fragment not generated correctly');
|
'WHERE fragment not generated correctly');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('To where succeeds for EX without qualifier for SQLite')]
|
#[TestDox('To where succeeds for EX without qualifier for SQLite')]
|
||||||
public function testToWhereSucceedsForEXWithoutQualifierForSQLite(): void
|
public function testToWhereSucceedsForEXWithoutQualifierForSQLite(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = 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::EX('that_field')->toWhere(),
|
||||||
'WHERE fragment not generated correctly');
|
'WHERE fragment not generated correctly');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('To where succeeds for NEX without qualifier for PostgreSQL')]
|
#[TestDox('To where succeeds for NEX without qualifier for PostgreSQL')]
|
||||||
public function testToWhereSucceedsForNEXWithoutQualifierForPostgreSQL(): void
|
public function testToWhereSucceedsForNEXWithoutQualifierForPostgreSQL(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = 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::NEX('a_field')->toWhere(),
|
||||||
'WHERE fragment not generated correctly');
|
'WHERE fragment not generated correctly');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('To where succeeds for NEX without qualifier for SQLite')]
|
#[TestDox('To where succeeds for NEX without qualifier for SQLite')]
|
||||||
public function testToWhereSucceedsForNEXWithoutQualifierForSQLite(): void
|
public function testToWhereSucceedsForNEXWithoutQualifierForSQLite(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = 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::NEX('a_field')->toWhere(),
|
||||||
'WHERE fragment not generated correctly');
|
'WHERE fragment not generated correctly');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('To where succeeds for BT without qualifier for SQLite')]
|
#[TestDox('To where succeeds for BT without qualifier for SQLite')]
|
||||||
public function testToWhereSucceedsForBTWithoutQualifierForSQLite(): void
|
public function testToWhereSucceedsForBTWithoutQualifierForSQLite(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = 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", Field::BT('age', 13, 17, '@age')->toWhere(),
|
||||||
'WHERE fragment not generated correctly');
|
'WHERE fragment not generated correctly');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('To where succeeds for BT without qualifier for PostgreSQL with numeric range')]
|
#[TestDox('To where succeeds for BT without qualifier for PostgreSQL with numeric range')]
|
||||||
public function testToWhereSucceedsForBTWithoutQualifierForPostgreSQLWithNumericRange(): void
|
public function testToWhereSucceedsForBTWithoutQualifierForPostgreSQLWithNumericRange(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = 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::BT('age', 13, 17, '@age')->toWhere(), 'WHERE fragment not generated correctly');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('To where succeeds for BT without qualifier for PostgreSQL with non-numeric range')]
|
#[TestDox('To where succeeds for BT without qualifier for PostgreSQL with non-numeric range')]
|
||||||
public function testToWhereSucceedsForBTWithoutQualifierForPostgreSQLWithNonNumericRange(): void
|
public function testToWhereSucceedsForBTWithoutQualifierForPostgreSQLWithNonNumericRange(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = 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::BT('city', 'Atlanta', 'Chicago', ':city')->toWhere(), 'WHERE fragment not generated correctly');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('To where succeeds for BT with qualifier for SQLite')]
|
#[TestDox('To where succeeds for BT with qualifier for SQLite')]
|
||||||
public function testToWhereSucceedsForBTWithQualifierForSQLite(): void
|
public function testToWhereSucceedsForBTWithQualifierForSQLite(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::SQLite;
|
Configuration::overrideMode(Mode::SQLite);
|
||||||
try {
|
try {
|
||||||
$field = Field::BT('age', 13, 17, '@age');
|
$field = Field::BT('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');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('To where succeeds for BT with qualifier for PostgreSQL with numeric range')]
|
#[TestDox('To where succeeds for BT with qualifier for PostgreSQL with numeric range')]
|
||||||
public function testToWhereSucceedsForBTWithQualifierForPostgreSQLWithNumericRange(): void
|
public function testToWhereSucceedsForBTWithQualifierForPostgreSQLWithNumericRange(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
try {
|
try {
|
||||||
$field = Field::BT('age', 13, 17, '@age');
|
$field = Field::BT('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');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('To where succeeds for BT with qualifier for PostgreSQL with non-numeric range')]
|
#[TestDox('To where succeeds for BT with qualifier for PostgreSQL with non-numeric range')]
|
||||||
public function testToWhereSucceedsForBTWithQualifierForPostgreSQLWithNonNumericRange(): void
|
public function testToWhereSucceedsForBTWithQualifierForPostgreSQLWithNonNumericRange(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
try {
|
try {
|
||||||
$field = Field::BT('city', 'Atlanta', 'Chicago', ':city');
|
$field = Field::BT('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');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('To where succeeds for others without qualifier for PostgreSQL')]
|
#[TestDox('To where succeeds for others without qualifier for PostgreSQL')]
|
||||||
public function testToWhereSucceedsForOthersWithoutQualifierForPostgreSQL(): void
|
public function testToWhereSucceedsForOthersWithoutQualifierForPostgreSQL(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = 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::EQ('some_field', '', '@value')->toWhere(),
|
||||||
'WHERE fragment not generated correctly');
|
'WHERE fragment not generated correctly');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('To where succeeds for others without qualifier for SQLite')]
|
#[TestDox('To where succeeds for others without qualifier for SQLite')]
|
||||||
public function testToWhereSucceedsForOthersWithoutQualifierForSQLite(): void
|
public function testToWhereSucceedsForOthersWithoutQualifierForSQLite(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = 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::EQ('some_field', '', '@value')->toWhere(),
|
||||||
'WHERE fragment not generated correctly');
|
'WHERE fragment not generated correctly');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('To where succeeds with qualifier no parameter for PostgreSQL')]
|
#[TestDox('To where succeeds with qualifier no parameter for PostgreSQL')]
|
||||||
public function testToWhereSucceedsWithQualifierNoParameterForPostgreSQL(): void
|
public function testToWhereSucceedsWithQualifierNoParameterForPostgreSQL(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
try {
|
try {
|
||||||
$field = Field::EX('no_field');
|
$field = Field::EX('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');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('To where succeeds with qualifier no parameter for SQLite')]
|
#[TestDox('To where succeeds with qualifier no parameter for SQLite')]
|
||||||
public function testToWhereSucceedsWithQualifierNoParameterForSQLite(): void
|
public function testToWhereSucceedsWithQualifierNoParameterForSQLite(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::SQLite;
|
Configuration::overrideMode(Mode::SQLite);
|
||||||
try {
|
try {
|
||||||
$field = Field::EX('no_field');
|
$field = Field::EX('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');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('To where succeeds with qualifier and parameter for PostgreSQL')]
|
#[TestDox('To where succeeds with qualifier and parameter for PostgreSQL')]
|
||||||
public function testToWhereSucceedsWithQualifierAndParameterForPostgreSQL(): void
|
public function testToWhereSucceedsWithQualifierAndParameterForPostgreSQL(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
try {
|
try {
|
||||||
$field = Field::LE('le_field', 18, '@it');
|
$field = Field::LE('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');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('To where succeeds with qualifier and parameter for SQLite')]
|
#[TestDox('To where succeeds with qualifier and parameter for SQLite')]
|
||||||
public function testToWhereSucceedsWithQualifierAndParameterForSQLite(): void
|
public function testToWhereSucceedsWithQualifierAndParameterForSQLite(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::SQLite;
|
Configuration::overrideMode(Mode::SQLite);
|
||||||
try {
|
try {
|
||||||
$field = Field::LE('le_field', 18, '@it');
|
$field = Field::LE('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');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('To where succeeds with sub-document for PostgreSQL')]
|
#[TestDox('To where succeeds with sub-document for PostgreSQL')]
|
||||||
public function testToWhereSucceedsWithSubDocumentForPostgreSQL(): void
|
public function testToWhereSucceedsWithSubDocumentForPostgreSQL(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
try {
|
try {
|
||||||
$field = Field::EQ('sub.foo.bar', 22, '@it');
|
$field = Field::EQ('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 {
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('To where succeeds with sub-document for SQLite')]
|
#[TestDox('To where succeeds with sub-document for SQLite')]
|
||||||
public function testToWhereSucceedsWithSubDocumentForSQLite(): void
|
public function testToWhereSucceedsWithSubDocumentForSQLite(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::SQLite;
|
Configuration::overrideMode(Mode::SQLite);
|
||||||
try {
|
try {
|
||||||
$field = Field::EQ('sub.foo.bar', 22, '@it');
|
$field = Field::EQ('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 {
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Unit\Mapper;
|
namespace Test\Unit\Mapper;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Unit\Mapper;
|
namespace Test\Unit\Mapper;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Unit\Mapper;
|
namespace Test\Unit\Mapper;
|
||||||
|
|
||||||
|
@ -6,6 +12,7 @@ use BitBadger\PDODocument\{DocumentException, Field};
|
||||||
use BitBadger\PDODocument\Mapper\DocumentMapper;
|
use BitBadger\PDODocument\Mapper\DocumentMapper;
|
||||||
use PHPUnit\Framework\Attributes\TestDox;
|
use PHPUnit\Framework\Attributes\TestDox;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Test\{PjsonDocument, PjsonId};
|
||||||
|
|
||||||
// ** Test class hierarchy for serialization **
|
// ** Test class hierarchy for serialization **
|
||||||
|
|
||||||
|
@ -48,10 +55,28 @@ class DocumentMapperTest extends TestCase
|
||||||
$this->assertEquals('tester', $doc->subDoc->name, 'Sub-document name not filled correctly');
|
$this->assertEquals('tester', $doc->subDoc->name, 'Sub-document name not filled correctly');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('Map succeeds with valid JSON for pjson class')]
|
||||||
|
public function testMapSucceedsWithValidJSONForPjsonClass(): void
|
||||||
|
{
|
||||||
|
$doc = (new DocumentMapper(PjsonDocument::class))->map(['data' => '{"id":"seven","name":"bob","num_value":8}']);
|
||||||
|
$this->assertNotNull($doc, 'The document should not have been null');
|
||||||
|
$this->assertEquals(new PjsonId('seven'), $doc->id, 'ID not filled correctly');
|
||||||
|
$this->assertEquals('bob', $doc->name, 'Name not filled correctly');
|
||||||
|
$this->assertEquals(8, $doc->numValue, 'Numeric value not filled correctly');
|
||||||
|
$this->assertFalse(isset($doc->skipped), 'Non-JSON field has not been set');
|
||||||
|
}
|
||||||
|
|
||||||
#[TestDox('Map fails with invalid JSON')]
|
#[TestDox('Map fails with invalid JSON')]
|
||||||
public function testMapFailsWithInvalidJSON(): void
|
public function testMapFailsWithInvalidJSON(): void
|
||||||
{
|
{
|
||||||
$this->expectException(DocumentException::class);
|
$this->expectException(DocumentException::class);
|
||||||
(new DocumentMapper(TestDocument::class))->map(['data' => 'this is not valid']);
|
(new DocumentMapper(TestDocument::class))->map(['data' => 'this is not valid']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('Map fails with invalid JSON for pjson class')]
|
||||||
|
public function testMapFailsWithInvalidJSONForPjsonClass(): void
|
||||||
|
{
|
||||||
|
$this->expectException(DocumentException::class);
|
||||||
|
(new DocumentMapper(PjsonDocument::class))->map(['data' => 'not even close']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Unit\Mapper;
|
namespace Test\Unit\Mapper;
|
||||||
|
|
||||||
|
@ -17,10 +23,10 @@ class ExistsMapperTest extends TestCase
|
||||||
public function testMapSucceedsForPostgreSQL(): void
|
public function testMapSucceedsForPostgreSQL(): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
$this->assertFalse((new ExistsMapper())->map([false, 'nope']), 'Result should have been false');
|
$this->assertFalse((new ExistsMapper())->map([false, 'nope']), 'Result should have been false');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,17 +34,17 @@ class ExistsMapperTest extends TestCase
|
||||||
public function testMapSucceedsForSQLite(): void
|
public function testMapSucceedsForSQLite(): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Configuration::$mode = Mode::SQLite;
|
Configuration::overrideMode(Mode::SQLite);
|
||||||
$this->assertTrue((new ExistsMapper())->map([1, 'yep']), 'Result should have been true');
|
$this->assertTrue((new ExistsMapper())->map([1, 'yep']), 'Result should have been true');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMapFailsWhenModeNotSet(): void
|
public function testMapFailsWhenModeNotSet(): void
|
||||||
{
|
{
|
||||||
$this->expectException(DocumentException::class);
|
$this->expectException(DocumentException::class);
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
(new ExistsMapper())->map(['0']);
|
(new ExistsMapper())->map(['0']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Unit\Mapper;
|
namespace Test\Unit\Mapper;
|
||||||
|
|
||||||
|
|
39
tests/unit/ModeTest.php
Normal file
39
tests/unit/ModeTest.php
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Test\Unit;
|
||||||
|
|
||||||
|
use BitBadger\PDODocument\{DocumentException, Mode};
|
||||||
|
use PHPUnit\Framework\Attributes\TestDox;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit tests for the Mode enumeration
|
||||||
|
*/
|
||||||
|
#[TestDox('Mode (Unit tests)')]
|
||||||
|
class ModeTest extends TestCase
|
||||||
|
{
|
||||||
|
#[TestDox('Derive from DSN succeeds for PostgreSQL')]
|
||||||
|
public function testDeriveFromDSNSucceedsForPostgreSQL(): void
|
||||||
|
{
|
||||||
|
$this->assertEquals(Mode::PgSQL, Mode::deriveFromDSN('pgsql:Host=localhost'), 'PostgreSQL mode incorrect');
|
||||||
|
}
|
||||||
|
|
||||||
|
#[TestDox('Derive from DSN succeeds for SQLite')]
|
||||||
|
public function testDeriveFromDSNSucceedsForSQLite(): void
|
||||||
|
{
|
||||||
|
$this->assertEquals(Mode::SQLite, Mode::deriveFromDSN('sqlite:data.db'), 'SQLite mode incorrect');
|
||||||
|
}
|
||||||
|
|
||||||
|
#[TestDox('Derive from DSN fails for MySQL')]
|
||||||
|
public function testDeriveFromDSNFailsForMySQL(): void
|
||||||
|
{
|
||||||
|
$this->expectException(DocumentException::class);
|
||||||
|
Mode::deriveFromDSN('mysql:Host=localhost');
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Unit;
|
namespace Test\Unit;
|
||||||
|
|
||||||
|
@ -12,57 +18,57 @@ use PHPUnit\Framework\TestCase;
|
||||||
#[TestDox('Op (Unit tests)')]
|
#[TestDox('Op (Unit tests)')]
|
||||||
class OpTest extends TestCase
|
class OpTest extends TestCase
|
||||||
{
|
{
|
||||||
#[TestDox('To string succeeds for EQ')]
|
#[TestDox('To SQL succeeds for EQ')]
|
||||||
public function testToStringSucceedsForEQ(): void
|
public function testToSQLSucceedsForEQ(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals('=', Op::EQ->toString(), 'EQ operator incorrect');
|
$this->assertEquals('=', Op::EQ->toSQL(), 'EQ operator incorrect');
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('To string succeeds for GT')]
|
#[TestDox('To SQL succeeds for GT')]
|
||||||
public function testToStringSucceedsForGT(): void
|
public function testToSQLSucceedsForGT(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals('>', Op::GT->toString(), 'GT operator incorrect');
|
$this->assertEquals('>', Op::GT->toSQL(), 'GT operator incorrect');
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('To string succeeds for GE')]
|
#[TestDox('To SQL succeeds for GE')]
|
||||||
public function testToStringSucceedsForGE(): void
|
public function testToSQLSucceedsForGE(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals('>=', Op::GE->toString(), 'GE operator incorrect');
|
$this->assertEquals('>=', Op::GE->toSQL(), 'GE operator incorrect');
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('To string succeeds for LT')]
|
#[TestDox('To SQL succeeds for LT')]
|
||||||
public function testToStringSucceedsForLT(): void
|
public function testToSQLSucceedsForLT(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals('<', Op::LT->toString(), 'LT operator incorrect');
|
$this->assertEquals('<', Op::LT->toSQL(), 'LT operator incorrect');
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('To string succeeds for LE')]
|
#[TestDox('To SQL succeeds for LE')]
|
||||||
public function testToStringSucceedsForLE(): void
|
public function testToSQLSucceedsForLE(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals('<=', Op::LE->toString(), 'LE operator incorrect');
|
$this->assertEquals('<=', Op::LE->toSQL(), 'LE operator incorrect');
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('To string succeeds for NE')]
|
#[TestDox('To SQL succeeds for NE')]
|
||||||
public function testToStringSucceedsForNE(): void
|
public function testToSQLSucceedsForNE(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals('<>', Op::NE->toString(), 'NE operator incorrect');
|
$this->assertEquals('<>', Op::NE->toSQL(), 'NE operator incorrect');
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('To string succeeds for BT')]
|
#[TestDox('To SQL succeeds for BT')]
|
||||||
public function testToStringSucceedsForBT(): void
|
public function testToSQLSucceedsForBT(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals('BETWEEN', Op::BT->toString(), 'BT operator incorrect');
|
$this->assertEquals('BETWEEN', Op::BT->toSQL(), 'BT operator incorrect');
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('To string succeeds for EX')]
|
#[TestDox('To SQL succeeds for EX')]
|
||||||
public function testToStringSucceedsForEX(): void
|
public function testToSQLSucceedsForEX(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals('IS NOT NULL', Op::EX->toString(), 'EX operator incorrect');
|
$this->assertEquals('IS NOT NULL', Op::EX->toSQL(), 'EX operator incorrect');
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('To string succeeds for NEX')]
|
#[TestDox('To SQL succeeds for NEX')]
|
||||||
public function testToStringSucceedsForNEX(): void
|
public function testToSQLSucceedsForNEX(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals('IS NULL', Op::NEX->toString(), 'NEX operator incorrect');
|
$this->assertEquals('IS NULL', Op::NEX->toSQL(), 'NEX operator incorrect');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,18 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Unit;
|
namespace Test\Unit;
|
||||||
|
|
||||||
use BitBadger\PDODocument\{Configuration, DocumentException, Field, Mode, Parameters};
|
use BitBadger\PDODocument\{Configuration, DocumentException, Field, Mode, Parameters};
|
||||||
use PHPUnit\Framework\Attributes\TestDox;
|
use PHPUnit\Framework\Attributes\TestDox;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use stdClass;
|
||||||
|
use Test\{PjsonDocument, PjsonId};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for the Parameters class
|
* Unit tests for the Parameters class
|
||||||
|
@ -24,13 +32,51 @@ class ParametersTest extends TestCase
|
||||||
$this->assertEquals([':id' => '7'], Parameters::id(7), 'ID parameter not constructed correctly');
|
$this->assertEquals([':id' => '7'], Parameters::id(7), 'ID parameter not constructed correctly');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testJsonSucceeds(): void
|
public function testJsonSucceedsForArray(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals([':it' => '{"id":18,"url":"https://www.unittest.com"}'],
|
$this->assertEquals([':it' => '{"id":18,"url":"https://www.unittest.com"}'],
|
||||||
Parameters::json(':it', ['id' => 18, 'url' => 'https://www.unittest.com']),
|
Parameters::json(':it', ['id' => 18, 'url' => 'https://www.unittest.com']),
|
||||||
'JSON parameter not constructed correctly');
|
'JSON parameter not constructed correctly');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testJsonSucceedsForArrayWithEmptyArrayParameter(): void
|
||||||
|
{
|
||||||
|
$this->assertEquals([':it' => '{"id":18,"urls":[]}'], Parameters::json(':it', ['id' => 18, 'urls' => []]),
|
||||||
|
'JSON parameter not constructed correctly');
|
||||||
|
}
|
||||||
|
|
||||||
|
#[TestDox('json succeeds for 1D array with empty array parameter')]
|
||||||
|
public function testJsonSucceedsFor1DArrayWithEmptyArrayParameter(): void
|
||||||
|
{
|
||||||
|
$this->assertEquals([':it' => '{"urls":[]}'], Parameters::json(':it', ['urls' => []]),
|
||||||
|
'JSON parameter not constructed correctly');
|
||||||
|
}
|
||||||
|
|
||||||
|
#[TestDox('json succeeds for stdClass')]
|
||||||
|
public function testJsonSucceedsForStdClass(): void
|
||||||
|
{
|
||||||
|
$obj = new stdClass();
|
||||||
|
$obj->id = 19;
|
||||||
|
$obj->url = 'https://testhere.info';
|
||||||
|
$this->assertEquals([':it' => '{"id":19,"url":"https://testhere.info"}'], Parameters::json(':it', $obj),
|
||||||
|
'JSON parameter not constructed correctly');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testJsonSucceedsForPjsonClass(): void
|
||||||
|
{
|
||||||
|
$this->assertEquals([':it' => '{"id":"999","name":"a test","num_value":98}'],
|
||||||
|
Parameters::json(':it', new PjsonDocument(new PjsonId('999'), 'a test', 98, 'nothing')),
|
||||||
|
'JSON parameter not constructed correctly');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testJsonSucceedsForArrayOfPjsonClass(): void
|
||||||
|
{
|
||||||
|
$this->assertEquals([':it' => '{"pjson":[{"id":"997","name":"another test","num_value":94}]}'],
|
||||||
|
Parameters::json(':it',
|
||||||
|
['pjson' => [new PjsonDocument(new PjsonId('997'), 'another test', 94, 'nothing')]]),
|
||||||
|
'JSON parameter not constructed correctly');
|
||||||
|
}
|
||||||
|
|
||||||
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::EQ('it', 17), Field::EQ('also', 22, ':also'), Field::EQ('other', 24)]);
|
||||||
|
@ -51,11 +97,11 @@ class ParametersTest extends TestCase
|
||||||
public function testFieldNamesSucceedsForPostgreSQL(): void
|
public function testFieldNamesSucceedsForPostgreSQL(): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
$this->assertEquals([':names' => "{one,two,seven}"],
|
$this->assertEquals([':names' => "{one,two,seven}"],
|
||||||
Parameters::fieldNames(':names', ['one', 'two', 'seven']), 'Field name parameters not correct');
|
Parameters::fieldNames(':names', ['one', 'two', 'seven']), 'Field name parameters not correct');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,18 +109,18 @@ class ParametersTest extends TestCase
|
||||||
public function testFieldNamesSucceedsForSQLite(): void
|
public function testFieldNamesSucceedsForSQLite(): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Configuration::$mode = Mode::SQLite;
|
Configuration::overrideMode(Mode::SQLite);
|
||||||
$this->assertEquals([':it0' => '$.test', ':it1' => '$.unit', ':it2' => '$.wow'],
|
$this->assertEquals([':it0' => '$.test', ':it1' => '$.unit', ':it2' => '$.wow'],
|
||||||
Parameters::fieldNames(':it', ['test', 'unit', 'wow']), 'Field name parameters not correct');
|
Parameters::fieldNames(':it', ['test', 'unit', 'wow']), 'Field name parameters not correct');
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFieldNamesFailsWhenModeNotSet(): void
|
public function testFieldNamesFailsWhenModeNotSet(): void
|
||||||
{
|
{
|
||||||
$this->expectException(DocumentException::class);
|
$this->expectException(DocumentException::class);
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
Parameters::fieldNames('', []);
|
Parameters::fieldNames('', []);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Unit\Query;
|
namespace Test\Unit\Query;
|
||||||
|
|
||||||
|
@ -15,7 +21,7 @@ class CountTest extends TestCase
|
||||||
{
|
{
|
||||||
public function tearDown(): void
|
public function tearDown(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +33,7 @@ class CountTest extends TestCase
|
||||||
|
|
||||||
public function testByFieldsSucceeds(): void
|
public function testByFieldsSucceeds(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = 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::GT('errors', 10, ':errors')]),
|
||||||
'SELECT statement not generated correctly');
|
'SELECT statement not generated correctly');
|
||||||
|
@ -36,7 +42,7 @@ class CountTest extends TestCase
|
||||||
#[TestDox('By contains succeeds for PostgreSQL')]
|
#[TestDox('By contains succeeds for PostgreSQL')]
|
||||||
public function testByContainsSucceedsForPostgreSQL(): void
|
public function testByContainsSucceedsForPostgreSQL(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
$this->assertEquals('SELECT COUNT(*) FROM the_table WHERE data @> :criteria', Count::byContains('the_table'),
|
$this->assertEquals('SELECT COUNT(*) FROM the_table WHERE data @> :criteria', Count::byContains('the_table'),
|
||||||
'SELECT statement not generated correctly');
|
'SELECT statement not generated correctly');
|
||||||
}
|
}
|
||||||
|
@ -51,7 +57,7 @@ class CountTest extends TestCase
|
||||||
#[TestDox('By JSON Path succeeds for PostgreSQL')]
|
#[TestDox('By JSON Path succeeds for PostgreSQL')]
|
||||||
public function testByJsonPathSucceedsForPostgreSQL(): void
|
public function testByJsonPathSucceedsForPostgreSQL(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
$this->assertEquals('SELECT COUNT(*) FROM a_table WHERE jsonb_path_exists(data, :path::jsonpath)',
|
$this->assertEquals('SELECT COUNT(*) FROM a_table WHERE jsonb_path_exists(data, :path::jsonpath)',
|
||||||
Count::byJsonPath('a_table'), 'SELECT statement not generated correctly');
|
Count::byJsonPath('a_table'), 'SELECT statement not generated correctly');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Unit\Query;
|
namespace Test\Unit\Query;
|
||||||
|
|
||||||
|
@ -15,14 +21,14 @@ class DefinitionTest extends TestCase
|
||||||
{
|
{
|
||||||
protected function tearDown(): void
|
protected function tearDown(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('Ensure table succeeds for PosgtreSQL')]
|
#[TestDox('Ensure table succeeds for PosgtreSQL')]
|
||||||
public function testEnsureTableSucceedsForPostgreSQL(): void
|
public function testEnsureTableSucceedsForPostgreSQL(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
$this->assertEquals('CREATE TABLE IF NOT EXISTS documents (data JSONB NOT NULL)',
|
$this->assertEquals('CREATE TABLE IF NOT EXISTS documents (data JSONB NOT NULL)',
|
||||||
Definition::ensureTable('documents'), 'CREATE TABLE statement not generated correctly');
|
Definition::ensureTable('documents'), 'CREATE TABLE statement not generated correctly');
|
||||||
}
|
}
|
||||||
|
@ -30,7 +36,7 @@ class DefinitionTest extends TestCase
|
||||||
#[TestDox('Ensure table succeeds for SQLite')]
|
#[TestDox('Ensure table succeeds for SQLite')]
|
||||||
public function testEnsureTableSucceedsForSQLite(): void
|
public function testEnsureTableSucceedsForSQLite(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::SQLite;
|
Configuration::overrideMode(Mode::SQLite);
|
||||||
$this->assertEquals('CREATE TABLE IF NOT EXISTS dox (data TEXT NOT NULL)', Definition::ensureTable('dox'),
|
$this->assertEquals('CREATE TABLE IF NOT EXISTS dox (data TEXT NOT NULL)', Definition::ensureTable('dox'),
|
||||||
'CREATE TABLE statement not generated correctly');
|
'CREATE TABLE statement not generated correctly');
|
||||||
}
|
}
|
||||||
|
@ -63,14 +69,14 @@ class DefinitionTest extends TestCase
|
||||||
|
|
||||||
public function testEnsureDocumentIndexOnSucceedsForSchemaAndFull(): void
|
public function testEnsureDocumentIndexOnSucceedsForSchemaAndFull(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
$this->assertEquals("CREATE INDEX IF NOT EXISTS idx_tbl_document ON my.tbl USING GIN (data)",
|
$this->assertEquals("CREATE INDEX IF NOT EXISTS idx_tbl_document ON my.tbl USING GIN (data)",
|
||||||
Definition::ensureDocumentIndexOn('my.tbl', DocumentIndex::Full));
|
Definition::ensureDocumentIndexOn('my.tbl', DocumentIndex::Full));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testEnsureDocumentIndexOnSucceedsForNoSchemaAndOptimized(): void
|
public function testEnsureDocumentIndexOnSucceedsForNoSchemaAndOptimized(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
$this->assertEquals("CREATE INDEX IF NOT EXISTS idx_it_document ON it USING GIN (data jsonb_path_ops)",
|
$this->assertEquals("CREATE INDEX IF NOT EXISTS idx_it_document ON it USING GIN (data jsonb_path_ops)",
|
||||||
Definition::ensureDocumentIndexOn('it', DocumentIndex::Optimized));
|
Definition::ensureDocumentIndexOn('it', DocumentIndex::Optimized));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Unit\Query;
|
namespace Test\Unit\Query;
|
||||||
|
|
||||||
|
@ -15,20 +21,20 @@ class DeleteTest extends TestCase
|
||||||
{
|
{
|
||||||
protected function tearDown(): void
|
protected function tearDown(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('By ID succeeds')]
|
#[TestDox('By ID succeeds')]
|
||||||
public function testByIdSucceeds(): void
|
public function testByIdSucceeds(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::SQLite;
|
Configuration::overrideMode(Mode::SQLite);
|
||||||
$this->assertEquals("DELETE FROM over_there WHERE data->>'id' = :id", Delete::byId('over_there'),
|
$this->assertEquals("DELETE FROM over_there WHERE data->>'id' = :id", Delete::byId('over_there'),
|
||||||
'DELETE statement not constructed correctly');
|
'DELETE statement not constructed correctly');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testByFieldsSucceeds(): void
|
public function testByFieldsSucceeds(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = 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::LT('value', 99, ':max'), Field::GE('value', 18, ':min')]),
|
||||||
'DELETE statement not constructed correctly');
|
'DELETE statement not constructed correctly');
|
||||||
|
@ -37,7 +43,7 @@ class DeleteTest extends TestCase
|
||||||
#[TestDox('By contains succeeds for PostgreSQL')]
|
#[TestDox('By contains succeeds for PostgreSQL')]
|
||||||
public function testByContainsSucceedsForPostgreSQL(): void
|
public function testByContainsSucceedsForPostgreSQL(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
$this->assertEquals('DELETE FROM somewhere WHERE data @> :criteria', Delete::byContains('somewhere'),
|
$this->assertEquals('DELETE FROM somewhere WHERE data @> :criteria', Delete::byContains('somewhere'),
|
||||||
'DELETE statement not constructed correctly');
|
'DELETE statement not constructed correctly');
|
||||||
}
|
}
|
||||||
|
@ -52,7 +58,7 @@ class DeleteTest extends TestCase
|
||||||
#[TestDox('By JSON Path succeeds for PostgreSQL')]
|
#[TestDox('By JSON Path succeeds for PostgreSQL')]
|
||||||
public function testByJsonPathSucceedsForPostgreSQL(): void
|
public function testByJsonPathSucceedsForPostgreSQL(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
$this->assertEquals('DELETE FROM here WHERE jsonb_path_exists(data, :path::jsonpath)',
|
$this->assertEquals('DELETE FROM here WHERE jsonb_path_exists(data, :path::jsonpath)',
|
||||||
Delete::byJsonPath('here'), 'DELETE statement not constructed correctly');
|
Delete::byJsonPath('here'), 'DELETE statement not constructed correctly');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Unit\Query;
|
namespace Test\Unit\Query;
|
||||||
|
|
||||||
|
@ -15,12 +21,12 @@ class ExistsTest extends TestCase
|
||||||
{
|
{
|
||||||
protected function tearDown(): void
|
protected function tearDown(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testQuerySucceeds(): void
|
public function testQuerySucceeds(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::SQLite;
|
Configuration::overrideMode(Mode::SQLite);
|
||||||
$this->assertEquals('SELECT EXISTS (SELECT 1 FROM abc WHERE def)', Exists::query('abc', 'def'),
|
$this->assertEquals('SELECT EXISTS (SELECT 1 FROM abc WHERE def)', Exists::query('abc', 'def'),
|
||||||
'Existence query not generated correctly');
|
'Existence query not generated correctly');
|
||||||
}
|
}
|
||||||
|
@ -28,14 +34,14 @@ class ExistsTest extends TestCase
|
||||||
#[TestDox('By ID succeeds')]
|
#[TestDox('By ID succeeds')]
|
||||||
public function testByIdSucceeds(): void
|
public function testByIdSucceeds(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::SQLite;
|
Configuration::overrideMode(Mode::SQLite);
|
||||||
$this->assertEquals("SELECT EXISTS (SELECT 1 FROM dox WHERE data->>'id' = :id)", Exists::byId('dox'),
|
$this->assertEquals("SELECT EXISTS (SELECT 1 FROM dox WHERE data->>'id' = :id)", Exists::byId('dox'),
|
||||||
'Existence query not generated correctly');
|
'Existence query not generated correctly');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testByFieldsSucceeds(): void
|
public function testByFieldsSucceeds(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = 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::NE('status', 'occupied', ':status')]),
|
||||||
'Existence query not generated correctly');
|
'Existence query not generated correctly');
|
||||||
|
@ -44,7 +50,7 @@ class ExistsTest extends TestCase
|
||||||
#[TestDox('By contains succeeds for PostgreSQL')]
|
#[TestDox('By contains succeeds for PostgreSQL')]
|
||||||
public function testByContainsSucceedsForPostgreSQL(): void
|
public function testByContainsSucceedsForPostgreSQL(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
$this->assertEquals('SELECT EXISTS (SELECT 1 FROM pocket WHERE data @> :criteria)',
|
$this->assertEquals('SELECT EXISTS (SELECT 1 FROM pocket WHERE data @> :criteria)',
|
||||||
Exists::byContains('pocket'), 'Existence query not generated correctly');
|
Exists::byContains('pocket'), 'Existence query not generated correctly');
|
||||||
}
|
}
|
||||||
|
@ -59,7 +65,7 @@ class ExistsTest extends TestCase
|
||||||
#[TestDox('By JSON Path succeeds for PostgreSQL')]
|
#[TestDox('By JSON Path succeeds for PostgreSQL')]
|
||||||
public function testByJsonPathSucceedsForPostgreSQL(): void
|
public function testByJsonPathSucceedsForPostgreSQL(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
$this->assertEquals('SELECT EXISTS (SELECT 1 FROM lint WHERE jsonb_path_exists(data, :path::jsonpath))',
|
$this->assertEquals('SELECT EXISTS (SELECT 1 FROM lint WHERE jsonb_path_exists(data, :path::jsonpath))',
|
||||||
Exists::byJsonPath('lint'), 'Existence query not generated correctly');
|
Exists::byJsonPath('lint'), 'Existence query not generated correctly');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Unit\Query;
|
namespace Test\Unit\Query;
|
||||||
|
|
||||||
|
@ -15,20 +21,20 @@ class FindTest extends TestCase
|
||||||
{
|
{
|
||||||
protected function tearDown(): void
|
protected function tearDown(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('By ID succeeds')]
|
#[TestDox('By ID succeeds')]
|
||||||
public function testByIdSucceeds(): void
|
public function testByIdSucceeds(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::SQLite;
|
Configuration::overrideMode(Mode::SQLite);
|
||||||
$this->assertEquals("SELECT data FROM here WHERE data->>'id' = :id", Find::byId('here'),
|
$this->assertEquals("SELECT data FROM here WHERE data->>'id' = :id", Find::byId('here'),
|
||||||
'SELECT query not generated correctly');
|
'SELECT query not generated correctly');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testByFieldsSucceeds(): void
|
public function testByFieldsSucceeds(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = 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::EQ('active', true, ':act'), Field::EQ('locked', true, ':lock')],
|
||||||
FieldMatch::Any),
|
FieldMatch::Any),
|
||||||
|
@ -38,7 +44,7 @@ class FindTest extends TestCase
|
||||||
#[TestDox('By contains succeeds for PostgreSQL')]
|
#[TestDox('By contains succeeds for PostgreSQL')]
|
||||||
public function testByContainsSucceedsForPostgreSQL(): void
|
public function testByContainsSucceedsForPostgreSQL(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
$this->assertEquals('SELECT data FROM disc WHERE data @> :criteria', Find::byContains('disc'),
|
$this->assertEquals('SELECT data FROM disc WHERE data @> :criteria', Find::byContains('disc'),
|
||||||
'SELECT query not generated correctly');
|
'SELECT query not generated correctly');
|
||||||
}
|
}
|
||||||
|
@ -53,7 +59,7 @@ class FindTest extends TestCase
|
||||||
#[TestDox('By JSON Path succeeds for PostgreSQL')]
|
#[TestDox('By JSON Path succeeds for PostgreSQL')]
|
||||||
public function testByJsonPathSucceedsForPostgreSQL(): void
|
public function testByJsonPathSucceedsForPostgreSQL(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
$this->assertEquals('SELECT data FROM light WHERE jsonb_path_exists(data, :path::jsonpath)',
|
$this->assertEquals('SELECT data FROM light WHERE jsonb_path_exists(data, :path::jsonpath)',
|
||||||
Find::byJsonPath('light'), 'SELECT query not generated correctly');
|
Find::byJsonPath('light'), 'SELECT query not generated correctly');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Unit\Query;
|
namespace Test\Unit\Query;
|
||||||
|
|
||||||
|
@ -15,13 +21,13 @@ class PatchTest extends TestCase
|
||||||
{
|
{
|
||||||
protected function tearDown(): void
|
protected function tearDown(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
#[TestDox('By ID succeeds for PostgreSQL')]
|
#[TestDox('By ID succeeds for PostgreSQL')]
|
||||||
public function testByIdSucceedsForPostgreSQL(): void
|
public function testByIdSucceedsForPostgreSQL(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
$this->assertEquals("UPDATE doc_table SET data = data || :data WHERE data->>'id' = :id",
|
$this->assertEquals("UPDATE doc_table SET data = data || :data WHERE data->>'id' = :id",
|
||||||
Patch::byId('doc_table'), 'Patch UPDATE statement is not correct');
|
Patch::byId('doc_table'), 'Patch UPDATE statement is not correct');
|
||||||
}
|
}
|
||||||
|
@ -29,7 +35,7 @@ class PatchTest extends TestCase
|
||||||
#[TestDox('By ID succeeds for SQLite')]
|
#[TestDox('By ID succeeds for SQLite')]
|
||||||
public function testByIdSucceedsForSQLite(): void
|
public function testByIdSucceedsForSQLite(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::SQLite;
|
Configuration::overrideMode(Mode::SQLite);
|
||||||
$this->assertEquals("UPDATE my_table SET data = json_patch(data, json(:data)) WHERE data->>'id' = :id",
|
$this->assertEquals("UPDATE my_table SET data = json_patch(data, json(:data)) WHERE data->>'id' = :id",
|
||||||
Patch::byId('my_table'), 'Patch UPDATE statement is not correct');
|
Patch::byId('my_table'), 'Patch UPDATE statement is not correct');
|
||||||
}
|
}
|
||||||
|
@ -44,7 +50,7 @@ class PatchTest extends TestCase
|
||||||
#[TestDox('By fields succeeds for PostgreSQL')]
|
#[TestDox('By fields succeeds for PostgreSQL')]
|
||||||
public function testByFieldsSucceedsForPostgreSQL(): void
|
public function testByFieldsSucceedsForPostgreSQL(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = 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::LT('something', 17, ':some')]), 'Patch UPDATE statement is not correct');
|
||||||
}
|
}
|
||||||
|
@ -52,7 +58,7 @@ class PatchTest extends TestCase
|
||||||
#[TestDox('By fields succeeds for SQLite')]
|
#[TestDox('By fields succeeds for SQLite')]
|
||||||
public function testByFieldsSucceedsForSQLite(): void
|
public function testByFieldsSucceedsForSQLite(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = 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::GT('something', 17, ':it')]), 'Patch UPDATE statement is not correct');
|
||||||
|
@ -67,7 +73,7 @@ class PatchTest extends TestCase
|
||||||
#[TestDox('By contains succeeds for PostgreSQL')]
|
#[TestDox('By contains succeeds for PostgreSQL')]
|
||||||
public function testByContainsSucceedsForPostgreSQL(): void
|
public function testByContainsSucceedsForPostgreSQL(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
$this->assertEquals('UPDATE this SET data = data || :data WHERE data @> :criteria', Patch::byContains('this'),
|
$this->assertEquals('UPDATE this SET data = data || :data WHERE data @> :criteria', Patch::byContains('this'),
|
||||||
'Patch UPDATE statement is not correct');
|
'Patch UPDATE statement is not correct');
|
||||||
}
|
}
|
||||||
|
@ -82,7 +88,7 @@ class PatchTest extends TestCase
|
||||||
#[TestDox('By JSON Path succeeds for PostgreSQL')]
|
#[TestDox('By JSON Path succeeds for PostgreSQL')]
|
||||||
public function testByJsonPathSucceedsForPostgreSQL(): void
|
public function testByJsonPathSucceedsForPostgreSQL(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
$this->assertEquals('UPDATE that SET data = data || :data WHERE jsonb_path_exists(data, :path::jsonpath)',
|
$this->assertEquals('UPDATE that SET data = data || :data WHERE jsonb_path_exists(data, :path::jsonpath)',
|
||||||
Patch::byJsonPath('that'), 'Patch UPDATE statement is not correct');
|
Patch::byJsonPath('that'), 'Patch UPDATE statement is not correct');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Unit\Query;
|
namespace Test\Unit\Query;
|
||||||
|
|
||||||
|
@ -15,13 +21,13 @@ class RemoveFieldsTest extends TestCase
|
||||||
{
|
{
|
||||||
protected function tearDown(): void
|
protected function tearDown(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('Update succeeds for PostgreSQL')]
|
#[TestDox('Update succeeds for PostgreSQL')]
|
||||||
public function testUpdateSucceedsForPostgreSQL(): void
|
public function testUpdateSucceedsForPostgreSQL(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
$this->assertEquals('UPDATE taco SET data = data - :names::text[] WHERE it = true',
|
$this->assertEquals('UPDATE taco SET data = data - :names::text[] WHERE it = true',
|
||||||
RemoveFields::update('taco', [':names' => "{one,two}"], 'it = true'), 'UPDATE statement not correct');
|
RemoveFields::update('taco', [':names' => "{one,two}"], 'it = true'), 'UPDATE statement not correct');
|
||||||
}
|
}
|
||||||
|
@ -29,7 +35,7 @@ class RemoveFieldsTest extends TestCase
|
||||||
#[TestDox('Update succeeds for SQLite')]
|
#[TestDox('Update succeeds for SQLite')]
|
||||||
public function testUpdateSucceedsForSQLite(): void
|
public function testUpdateSucceedsForSQLite(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::SQLite;
|
Configuration::overrideMode(Mode::SQLite);
|
||||||
$this->assertEquals('UPDATE burrito SET data = json_remove(data, :name0, :name1, :name2) WHERE a = b',
|
$this->assertEquals('UPDATE burrito SET data = json_remove(data, :name0, :name1, :name2) WHERE a = b',
|
||||||
RemoveFields::update('burrito', Parameters::fieldNames(':name', ['one', 'two', 'ten']), 'a = b'),
|
RemoveFields::update('burrito', Parameters::fieldNames(':name', ['one', 'two', 'ten']), 'a = b'),
|
||||||
'UPDATE statement not correct');
|
'UPDATE statement not correct');
|
||||||
|
@ -44,7 +50,7 @@ class RemoveFieldsTest extends TestCase
|
||||||
#[TestDox('By ID succeeds for PostgreSQL')]
|
#[TestDox('By ID succeeds for PostgreSQL')]
|
||||||
public function testByIdSucceedsForPostgreSQL()
|
public function testByIdSucceedsForPostgreSQL()
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
$this->assertEquals("UPDATE churro SET data = data - :bite::text[] WHERE data->>'id' = :id",
|
$this->assertEquals("UPDATE churro SET data = data - :bite::text[] WHERE data->>'id' = :id",
|
||||||
RemoveFields::byId('churro', Parameters::fieldNames(':bite', ['byte'])), 'UPDATE statement not correct');
|
RemoveFields::byId('churro', Parameters::fieldNames(':bite', ['byte'])), 'UPDATE statement not correct');
|
||||||
}
|
}
|
||||||
|
@ -52,7 +58,7 @@ class RemoveFieldsTest extends TestCase
|
||||||
#[TestDox('By ID succeeds for SQLite')]
|
#[TestDox('By ID succeeds for SQLite')]
|
||||||
public function testByIdSucceedsForSQLite()
|
public function testByIdSucceedsForSQLite()
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::SQLite;
|
Configuration::overrideMode(Mode::SQLite);
|
||||||
$this->assertEquals("UPDATE quesadilla SET data = json_remove(data, :bite0) WHERE data->>'id' = :id",
|
$this->assertEquals("UPDATE quesadilla SET data = json_remove(data, :bite0) WHERE data->>'id' = :id",
|
||||||
RemoveFields::byId('quesadilla', Parameters::fieldNames(':bite', ['byte'])),
|
RemoveFields::byId('quesadilla', Parameters::fieldNames(':bite', ['byte'])),
|
||||||
'UPDATE statement not correct');
|
'UPDATE statement not correct');
|
||||||
|
@ -68,7 +74,7 @@ class RemoveFieldsTest extends TestCase
|
||||||
#[TestDox('By fields succeeds for PostgreSQL')]
|
#[TestDox('By fields succeeds for PostgreSQL')]
|
||||||
public function testByFieldsSucceedsForPostgreSQL()
|
public function testByFieldsSucceedsForPostgreSQL()
|
||||||
{
|
{
|
||||||
Configuration::$mode = 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::EQ('cheese', 'jack', ':queso')],
|
||||||
Parameters::fieldNames(':sauce', ['white'])),
|
Parameters::fieldNames(':sauce', ['white'])),
|
||||||
|
@ -78,7 +84,7 @@ class RemoveFieldsTest extends TestCase
|
||||||
#[TestDox('By fields succeeds for SQLite')]
|
#[TestDox('By fields succeeds for SQLite')]
|
||||||
public function testByFieldsSucceedsForSQLite()
|
public function testByFieldsSucceedsForSQLite()
|
||||||
{
|
{
|
||||||
Configuration::$mode = 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::EQ('side', 'beans', ':rice')],
|
||||||
|
@ -95,7 +101,7 @@ class RemoveFieldsTest extends TestCase
|
||||||
#[TestDox('By contains succeeds for PostgreSQL')]
|
#[TestDox('By contains succeeds for PostgreSQL')]
|
||||||
public function testByContainsSucceedsForPostgreSQL(): void
|
public function testByContainsSucceedsForPostgreSQL(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
$this->assertEquals('UPDATE food SET data = data - :drink::text[] WHERE data @> :criteria',
|
$this->assertEquals('UPDATE food SET data = data - :drink::text[] WHERE data @> :criteria',
|
||||||
RemoveFields::byContains('food', Parameters::fieldNames(':drink', ['a', 'b'])),
|
RemoveFields::byContains('food', Parameters::fieldNames(':drink', ['a', 'b'])),
|
||||||
'UPDATE statement not correct');
|
'UPDATE statement not correct');
|
||||||
|
@ -111,7 +117,7 @@ class RemoveFieldsTest extends TestCase
|
||||||
#[TestDox('By JSON Path succeeds for PostgreSQL')]
|
#[TestDox('By JSON Path succeeds for PostgreSQL')]
|
||||||
public function testByJsonPathSucceedsForPostgreSQL(): void
|
public function testByJsonPathSucceedsForPostgreSQL(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'UPDATE dessert SET data = data - :cake::text[] WHERE jsonb_path_exists(data, :path::jsonpath)',
|
'UPDATE dessert SET data = data - :cake::text[] WHERE jsonb_path_exists(data, :path::jsonpath)',
|
||||||
RemoveFields::byJsonPath('dessert', Parameters::fieldNames(':cake', ['b', 'c'])),
|
RemoveFields::byJsonPath('dessert', Parameters::fieldNames(':cake', ['b', 'c'])),
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Test\Unit;
|
namespace Test\Unit;
|
||||||
|
|
||||||
|
@ -14,12 +20,12 @@ class QueryTest extends TestCase
|
||||||
{
|
{
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::SQLite;
|
Configuration::overrideMode(Mode::SQLite);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown(): void
|
protected function tearDown(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSelectFromTableSucceeds(): void
|
public function testSelectFromTableSucceeds(): void
|
||||||
|
@ -63,30 +69,21 @@ class QueryTest extends TestCase
|
||||||
|
|
||||||
public function testWhereDataContainsSucceedsWithDefaultParameter(): void
|
public function testWhereDataContainsSucceedsWithDefaultParameter(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
try {
|
|
||||||
$this->assertEquals('data @> :criteria', Query::whereDataContains(),
|
$this->assertEquals('data @> :criteria', Query::whereDataContains(),
|
||||||
'WHERE fragment not constructed correctly');
|
'WHERE fragment not constructed correctly');
|
||||||
} finally {
|
|
||||||
Configuration::$mode = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWhereDataContainsSucceedsWithSpecifiedParameter(): void
|
public function testWhereDataContainsSucceedsWithSpecifiedParameter(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
try {
|
$this->assertEquals('data @> :it', Query::whereDataContains(':it'), 'WHERE fragment not constructed correctly');
|
||||||
$this->assertEquals('data @> :it', Query::whereDataContains(':it'),
|
|
||||||
'WHERE fragment not constructed correctly');
|
|
||||||
} finally {
|
|
||||||
Configuration::$mode = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('Where data contains fails if not PostgreSQL')]
|
#[TestDox('Where data contains fails if not PostgreSQL')]
|
||||||
public function testWhereDataContainsFailsIfNotPostgreSQL(): void
|
public function testWhereDataContainsFailsIfNotPostgreSQL(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
$this->expectException(DocumentException::class);
|
$this->expectException(DocumentException::class);
|
||||||
Query::whereDataContains();
|
Query::whereDataContains();
|
||||||
}
|
}
|
||||||
|
@ -94,31 +91,23 @@ class QueryTest extends TestCase
|
||||||
#[TestDox('Where JSON Path matches succeeds with default parameter')]
|
#[TestDox('Where JSON Path matches succeeds with default parameter')]
|
||||||
public function testWhereJsonPathMatchesSucceedsWithDefaultParameter(): void
|
public function testWhereJsonPathMatchesSucceedsWithDefaultParameter(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
try {
|
|
||||||
$this->assertEquals('jsonb_path_exists(data, :path::jsonpath)', Query::whereJsonPathMatches(),
|
$this->assertEquals('jsonb_path_exists(data, :path::jsonpath)', Query::whereJsonPathMatches(),
|
||||||
'WHERE fragment not constructed correctly');
|
'WHERE fragment not constructed correctly');
|
||||||
} finally {
|
|
||||||
Configuration::$mode = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('Where JSON Path matches succeeds with specified parameter')]
|
#[TestDox('Where JSON Path matches succeeds with specified parameter')]
|
||||||
public function testWhereJsonPathMatchesSucceedsWithSpecifiedParameter(): void
|
public function testWhereJsonPathMatchesSucceedsWithSpecifiedParameter(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
try {
|
|
||||||
$this->assertEquals('jsonb_path_exists(data, :road::jsonpath)', Query::whereJsonPathMatches(':road'),
|
$this->assertEquals('jsonb_path_exists(data, :road::jsonpath)', Query::whereJsonPathMatches(':road'),
|
||||||
'WHERE fragment not constructed correctly');
|
'WHERE fragment not constructed correctly');
|
||||||
} finally {
|
|
||||||
Configuration::$mode = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('Where JSON Path matches fails if not PostgreSQL')]
|
#[TestDox('Where JSON Path matches fails if not PostgreSQL')]
|
||||||
public function testWhereJsonPathMatchesFailsIfNotPostgreSQL(): void
|
public function testWhereJsonPathMatchesFailsIfNotPostgreSQL(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
$this->expectException(DocumentException::class);
|
$this->expectException(DocumentException::class);
|
||||||
Query::whereJsonPathMatches();
|
Query::whereJsonPathMatches();
|
||||||
}
|
}
|
||||||
|
@ -126,87 +115,60 @@ class QueryTest extends TestCase
|
||||||
#[TestDox('Insert succeeds with no auto-ID for PostgreSQL')]
|
#[TestDox('Insert succeeds with no auto-ID for PostgreSQL')]
|
||||||
public function testInsertSucceedsWithNoAutoIdForPostgreSQL(): void
|
public function testInsertSucceedsWithNoAutoIdForPostgreSQL(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
try {
|
|
||||||
$this->assertEquals('INSERT INTO test_tbl VALUES (:data)', Query::insert('test_tbl'),
|
$this->assertEquals('INSERT INTO test_tbl VALUES (:data)', Query::insert('test_tbl'),
|
||||||
'INSERT statement not constructed correctly');
|
'INSERT statement not constructed correctly');
|
||||||
} finally {
|
|
||||||
Configuration::$mode = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('Insert succeeds with no auto-ID for SQLite')]
|
#[TestDox('Insert succeeds with no auto-ID for SQLite')]
|
||||||
public function testInsertSucceedsWithNoAutoIdForSQLite(): void
|
public function testInsertSucceedsWithNoAutoIdForSQLite(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::SQLite;
|
|
||||||
try {
|
|
||||||
$this->assertEquals('INSERT INTO test_tbl VALUES (:data)', Query::insert('test_tbl'),
|
$this->assertEquals('INSERT INTO test_tbl VALUES (:data)', Query::insert('test_tbl'),
|
||||||
'INSERT statement not constructed correctly');
|
'INSERT statement not constructed correctly');
|
||||||
} finally {
|
|
||||||
Configuration::$mode = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('Insert succeeds with auto numeric ID for PostgreSQL')]
|
#[TestDox('Insert succeeds with auto numeric ID for PostgreSQL')]
|
||||||
public function testInsertSucceedsWithAutoNumericIdForPostgreSQL(): void
|
public function testInsertSucceedsWithAutoNumericIdForPostgreSQL(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
try {
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
"INSERT INTO test_tbl VALUES (:data::jsonb || ('{\"id\":' "
|
"INSERT INTO test_tbl VALUES (:data::jsonb || ('{\"id\":' "
|
||||||
. "|| (SELECT COALESCE(MAX((data->>'id')::numeric), 0) + 1 FROM test_tbl) || '}')::jsonb)",
|
. "|| (SELECT COALESCE(MAX((data->>'id')::numeric), 0) + 1 FROM test_tbl) || '}')::jsonb)",
|
||||||
Query::insert('test_tbl', AutoId::Number), 'INSERT statement not constructed correctly');
|
Query::insert('test_tbl', AutoId::Number), 'INSERT statement not constructed correctly');
|
||||||
} finally {
|
|
||||||
Configuration::$mode = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('Insert succeeds with auto numeric ID for SQLite')]
|
#[TestDox('Insert succeeds with auto numeric ID for SQLite')]
|
||||||
public function testInsertSucceedsWithAutoNumericIdForSQLite(): void
|
public function testInsertSucceedsWithAutoNumericIdForSQLite(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::SQLite;
|
|
||||||
try {
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
"INSERT INTO test_tbl VALUES (json_set(:data, '$.id', "
|
"INSERT INTO test_tbl VALUES (json_set(:data, '$.id', "
|
||||||
. "(SELECT coalesce(max(data->>'id'), 0) + 1 FROM test_tbl)))",
|
. "(SELECT coalesce(max(data->>'id'), 0) + 1 FROM test_tbl)))",
|
||||||
Query::insert('test_tbl', AutoId::Number), 'INSERT statement not constructed correctly');
|
Query::insert('test_tbl', AutoId::Number), 'INSERT statement not constructed correctly');
|
||||||
} finally {
|
|
||||||
Configuration::$mode = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('Insert succeeds with auto UUID for PostgreSQL')]
|
#[TestDox('Insert succeeds with auto UUID for PostgreSQL')]
|
||||||
public function testInsertSucceedsWithAutoUuidForPostgreSQL(): void
|
public function testInsertSucceedsWithAutoUuidForPostgreSQL(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
try {
|
|
||||||
$query = Query::insert('test_tbl', AutoId::UUID);
|
$query = Query::insert('test_tbl', AutoId::UUID);
|
||||||
$this->assertStringStartsWith("INSERT INTO test_tbl VALUES (:data::jsonb || '{\"id\":\"", $query,
|
$this->assertStringStartsWith("INSERT INTO test_tbl VALUES (:data::jsonb || '{\"id\":\"", $query,
|
||||||
'INSERT statement not constructed correctly');
|
'INSERT statement not constructed correctly');
|
||||||
$this->assertStringEndsWith("\"}')", $query, 'INSERT statement not constructed correctly');
|
$this->assertStringEndsWith("\"}')", $query, 'INSERT statement not constructed correctly');
|
||||||
} finally {
|
|
||||||
Configuration::$mode = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('Insert succeeds with auto UUID for SQLite')]
|
#[TestDox('Insert succeeds with auto UUID for SQLite')]
|
||||||
public function testInsertSucceedsWithAutoUuidForSQLite(): void
|
public function testInsertSucceedsWithAutoUuidForSQLite(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::SQLite;
|
|
||||||
try {
|
|
||||||
$query = Query::insert('test_tbl', AutoId::UUID);
|
$query = Query::insert('test_tbl', AutoId::UUID);
|
||||||
$this->assertStringStartsWith("INSERT INTO test_tbl VALUES (json_set(:data, '$.id', '", $query,
|
$this->assertStringStartsWith("INSERT INTO test_tbl VALUES (json_set(:data, '$.id', '", $query,
|
||||||
'INSERT statement not constructed correctly');
|
'INSERT statement not constructed correctly');
|
||||||
$this->assertStringEndsWith("'))", $query, 'INSERT statement not constructed correctly');
|
$this->assertStringEndsWith("'))", $query, 'INSERT statement not constructed correctly');
|
||||||
} finally {
|
|
||||||
Configuration::$mode = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('Insert succeeds with auto random string for PostgreSQL')]
|
#[TestDox('Insert succeeds with auto random string for PostgreSQL')]
|
||||||
public function testInsertSucceedsWithAutoRandomStringForPostgreSQL(): void
|
public function testInsertSucceedsWithAutoRandomStringForPostgreSQL(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::PgSQL;
|
Configuration::overrideMode(Mode::PgSQL);
|
||||||
Configuration::$idStringLength = 8;
|
Configuration::$idStringLength = 8;
|
||||||
try {
|
try {
|
||||||
$query = Query::insert('test_tbl', AutoId::RandomString);
|
$query = Query::insert('test_tbl', AutoId::RandomString);
|
||||||
|
@ -216,7 +178,6 @@ class QueryTest extends TestCase
|
||||||
$id = str_replace(["INSERT INTO test_tbl VALUES (:data::jsonb || '{\"id\":\"", "\"}')"], '', $query);
|
$id = str_replace(["INSERT INTO test_tbl VALUES (:data::jsonb || '{\"id\":\"", "\"}')"], '', $query);
|
||||||
$this->assertEquals(8, strlen($id), "Generated ID [$id] should have been 8 characters long");
|
$this->assertEquals(8, strlen($id), "Generated ID [$id] should have been 8 characters long");
|
||||||
} finally {
|
} finally {
|
||||||
Configuration::$mode = null;
|
|
||||||
Configuration::$idStringLength = 16;
|
Configuration::$idStringLength = 16;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -224,23 +185,18 @@ class QueryTest extends TestCase
|
||||||
#[TestDox('Insert succeeds with auto random string for SQLite')]
|
#[TestDox('Insert succeeds with auto random string for SQLite')]
|
||||||
public function testInsertSucceedsWithAutoRandomStringForSQLite(): void
|
public function testInsertSucceedsWithAutoRandomStringForSQLite(): void
|
||||||
{
|
{
|
||||||
Configuration::$mode = Mode::SQLite;
|
|
||||||
try {
|
|
||||||
$query = Query::insert('test_tbl', AutoId::RandomString);
|
$query = Query::insert('test_tbl', AutoId::RandomString);
|
||||||
$this->assertStringStartsWith("INSERT INTO test_tbl VALUES (json_set(:data, '$.id', '", $query,
|
$this->assertStringStartsWith("INSERT INTO test_tbl VALUES (json_set(:data, '$.id', '", $query,
|
||||||
'INSERT statement not constructed correctly');
|
'INSERT statement not constructed correctly');
|
||||||
$this->assertStringEndsWith("'))", $query, 'INSERT statement not constructed correctly');
|
$this->assertStringEndsWith("'))", $query, 'INSERT statement not constructed correctly');
|
||||||
$id = str_replace(["INSERT INTO test_tbl VALUES (json_set(:data, '$.id', '", "'))"], '', $query);
|
$id = str_replace(["INSERT INTO test_tbl VALUES (json_set(:data, '$.id', '", "'))"], '', $query);
|
||||||
$this->assertEquals(16, strlen($id), "Generated ID [$id] should have been 16 characters long");
|
$this->assertEquals(16, strlen($id), "Generated ID [$id] should have been 16 characters long");
|
||||||
} finally {
|
|
||||||
Configuration::$mode = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInsertFailsWhenModeNotSet(): void
|
public function testInsertFailsWhenModeNotSet(): void
|
||||||
{
|
{
|
||||||
$this->expectException(DocumentException::class);
|
$this->expectException(DocumentException::class);
|
||||||
Configuration::$mode = null;
|
Configuration::overrideMode(null);
|
||||||
Query::insert('kaboom');
|
Query::insert('kaboom');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user