From 15ff5d3cb6501afded4a1961546e306546cc3543 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Tue, 27 Aug 2024 23:30:05 -0400 Subject: [PATCH] Implement level 6 PHPStan fixes --- composer.json | 3 +- composer.lock | 60 ++++++++++++++++++- src/Configuration.php | 2 +- src/Count.php | 2 +- src/Custom.php | 12 ++-- src/Definition.php | 2 +- src/Delete.php | 2 +- src/Document.php | 6 +- src/DocumentList.php | 8 +-- src/Exists.php | 2 +- src/Field.php | 59 +++++++++--------- src/Find.php | 6 +- src/Mapper/ArrayMapper.php | 2 + src/Mapper/CountMapper.php | 2 + src/Mapper/DocumentMapper.php | 2 +- src/Mapper/ExistsMapper.php | 2 + src/Mapper/Mapper.php | 2 +- src/Parameters.php | 10 ++-- src/Patch.php | 10 ++-- src/Query/Definition.php | 2 +- src/Query/RemoveFields.php | 10 ++-- src/RemoveFields.php | 2 +- tests/PjsonId.php | 7 ++- tests/integration/postgresql/CustomTest.php | 22 +++---- tests/integration/postgresql/DocumentTest.php | 40 ++++++------- tests/integration/postgresql/FindTest.php | 24 ++++---- tests/integration/postgresql/PatchTest.php | 4 +- .../postgresql/RemoveFieldsTest.php | 4 +- tests/integration/sqlite/CustomTest.php | 22 +++---- tests/integration/sqlite/DocumentTest.php | 40 ++++++------- tests/integration/sqlite/FindTest.php | 12 ++-- tests/integration/sqlite/PatchTest.php | 2 +- tests/integration/sqlite/RemoveFieldsTest.php | 4 +- tests/unit/ConfigurationTest.php | 2 +- tests/unit/Mapper/StringMapperTest.php | 6 +- tests/unit/Query/RemoveFieldsTest.php | 8 +-- tests/unit/QueryTest.php | 2 +- 37 files changed, 239 insertions(+), 168 deletions(-) diff --git a/composer.json b/composer.json index 5bb93c1..eed51d7 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,8 @@ }, "require-dev": { "phpunit/phpunit": "^11", - "square/pjson": "^0.5.0" + "square/pjson": "^0.5.0", + "phpstan/phpstan": "^1.12" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index efe8e2a..e0cc394 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "223a16e330809798fc103d89c35faaa7", + "content-hash": "c67e3128fb7ace9411499eec10e46446", "packages": [ { "name": "bit-badger/inspired-by-fsharp", @@ -415,6 +415,64 @@ }, "time": "2022-02-21T01:04:05+00:00" }, + { + "name": "phpstan/phpstan", + "version": "1.12.0", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "384af967d35b2162f69526c7276acadce534d0e1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/384af967d35b2162f69526c7276acadce534d0e1", + "reference": "384af967d35b2162f69526c7276acadce534d0e1", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + } + ], + "time": "2024-08-27T09:18:05+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "11.0.5", diff --git a/src/Configuration.php b/src/Configuration.php index a2b51db..eade52d 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -34,7 +34,7 @@ class Configuration /** @var string|null The password to use to establish a data connection (use env PDO_DOC_PASSWORD if possible) */ public static ?string $password = null; - /** @var array|null Options to use for connections (driver-specific) */ + /** @var mixed[]|null Options to use for connections (driver-specific) */ public static ?array $options = null; /** @var Option The mode in which the library is operating */ diff --git a/src/Count.php b/src/Count.php index 23cf2e5..8d7d1fd 100644 --- a/src/Count.php +++ b/src/Count.php @@ -47,7 +47,7 @@ class Count * Count matching documents using a JSON containment query (`@>`; PostgreSQL only) * * @param string $tableName The name of the table in which documents should be counted - * @param array|object $criteria The criteria for the JSON containment query + * @param mixed[]|object $criteria The criteria for the JSON containment query * @return int The number of documents matching the JSON containment query * @throws DocumentException If the database mode is not PostgreSQL, or if an error occurs */ diff --git a/src/Custom.php b/src/Custom.php index e01147c..fbfdadd 100644 --- a/src/Custom.php +++ b/src/Custom.php @@ -23,7 +23,7 @@ class Custom * Prepare a query for execution and run it * * @param string $query The query to be run - * @param array $parameters The parameters for the query + * @param array $parameters The parameters for the query * @return PDOStatement The result of executing the query * @throws DocumentException If the query execution is unsuccessful */ @@ -67,7 +67,7 @@ class Custom * * @template TDoc The domain type of the document to retrieve * @param string $query The query to be executed - * @param array $parameters Parameters to use in executing the query + * @param array $parameters Parameters to use in executing the query * @param Mapper $mapper Mapper to deserialize the result * @return DocumentList The items matching the query * @throws DocumentException If any is encountered @@ -82,7 +82,7 @@ class Custom * * @template TDoc The domain type of the document to retrieve * @param string $query The query to be executed - * @param array $parameters Parameters to use in executing the query + * @param array $parameters Parameters to use in executing the query * @param Mapper $mapper Mapper to deserialize the result * @return TDoc[] The items matching the query * @throws DocumentException If any is encountered @@ -97,7 +97,7 @@ class Custom * * @template TDoc The domain type of the document to retrieve * @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 $mapper Mapper to deserialize the result * @return Option A `Some` instance if the item is found, `None` otherwise * @throws DocumentException If any is encountered @@ -116,7 +116,7 @@ class Custom * Execute a query that does not return a value * * @param string $query The query to execute - * @param array $parameters Parameters to use in executing the query + * @param array $parameters Parameters to use in executing the query * @throws DocumentException If any is encountered */ public static function nonQuery(string $query, array $parameters): void @@ -133,7 +133,7 @@ class Custom * * @template T The scalar type to return * @param string $query The query to retrieve the value - * @param array $parameters Parameters to use in executing the query + * @param array $parameters Parameters to use in executing the query * @param Mapper $mapper The mapper to obtain the result * @return mixed|false|T The scalar value if found, false if not * @throws DocumentException If any is encountered diff --git a/src/Definition.php b/src/Definition.php index 72b975d..0839c6d 100644 --- a/src/Definition.php +++ b/src/Definition.php @@ -30,7 +30,7 @@ class Definition * * @param string $tableName The name of the table which should be indexed * @param string $indexName The name of the index - * @param array $fields Fields which should be a part of this index + * @param string[] $fields Fields which should be a part of this index * @throws DocumentException If any is encountered */ public static function ensureFieldIndex(string $tableName, string $indexName, array $fields): void diff --git a/src/Delete.php b/src/Delete.php index b5eba2d..c77d32f 100644 --- a/src/Delete.php +++ b/src/Delete.php @@ -44,7 +44,7 @@ class Delete * Delete documents matching a JSON containment query (`@>`; PostgreSQL only) * * @param string $tableName The table from which documents should be deleted - * @param array|object $criteria The JSON containment query values + * @param mixed[]|object $criteria The JSON containment query values * @throws DocumentException If the database mode is not PostgreSQL, or if an error occurs */ public static function byContains(string $tableName, array|object $criteria): void diff --git a/src/Document.php b/src/Document.php index 83c5ae2..e7c8ff7 100644 --- a/src/Document.php +++ b/src/Document.php @@ -17,7 +17,7 @@ class Document * Insert a new document * * @param string $tableName The name of the table into which the document should be inserted - * @param array|object $document The document to be inserted + * @param mixed[]|object $document The document to be inserted * @throws DocumentException If any is encountered */ public static function insert(string $tableName, array|object $document): void @@ -47,7 +47,7 @@ class Document * Save a document, inserting it if it does not exist and updating it if it does (AKA "upsert") * * @param string $tableName The name of the table to which the document should be saved - * @param array|object $document The document to be saved + * @param mixed[]|object $document The document to be saved * @throws DocumentException If any is encountered */ public static function save(string $tableName, array|object $document): void @@ -60,7 +60,7 @@ class Document * * @param string $tableName The table in which the document should be updated * @param mixed $docId The ID of the document to be updated - * @param array|object $document The document to be updated + * @param mixed[]|object $document The document to be updated * @throws DocumentException If any is encountered */ public static function update(string $tableName, mixed $docId, array|object $document): void diff --git a/src/DocumentList.php b/src/DocumentList.php index 47bdace..d992ee8 100644 --- a/src/DocumentList.php +++ b/src/DocumentList.php @@ -115,14 +115,14 @@ class DocumentList * Construct a new document list * * @param string $query The query to run to retrieve results - * @param array $parameters An associative array of parameters for the query + * @param array $parameters An associative array of parameters for the query * @param Mapper $mapper A mapper to deserialize JSON documents - * @return static The document list instance + * @return self The document list instance * @throws DocumentException If any is encountered */ - public static function create(string $query, array $parameters, Mapper $mapper): static + public static function create(string $query, array $parameters, Mapper $mapper): self { $stmt = &Custom::runQuery($query, $parameters); - return new static($stmt, $mapper); + return new self($stmt, $mapper); } } diff --git a/src/Exists.php b/src/Exists.php index 3eac9c3..dc7f6f3 100644 --- a/src/Exists.php +++ b/src/Exists.php @@ -48,7 +48,7 @@ class Exists * Determine if documents exist by a JSON containment query (`@>`; PostgreSQL only) * * @param string $tableName The name of the table in which document existence should be determined - * @param array|object $criteria The criteria for the JSON containment query + * @param mixed[]|object $criteria The criteria for the JSON containment query * @return bool True if any documents match the JSON containment query, false if not * @throws DocumentException If the database mode is not PostgreSQL, or if an error occurs */ diff --git a/src/Field.php b/src/Field.php index b8accb2..07866aa 100644 --- a/src/Field.php +++ b/src/Field.php @@ -9,6 +9,7 @@ declare(strict_types=1); namespace BitBadger\PDODocument; use Exception; +use mysql_xdevapi\Session; /** * Criteria for a field WHERE clause @@ -33,8 +34,8 @@ class Field /** * Append the parameter name and value to the given associative array * - * @param array $existing The existing parameters - * @return array The given parameter array with this field's name and value appended + * @param array $existing The existing parameters + * @return array The given parameter array with this field's name and value appended */ public function appendParameter(array $existing): array { @@ -88,11 +89,11 @@ class Field * @param string $fieldName The name of the field against which the value will be compared * @param mixed $value The value for which equality will be checked * @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank) - * @return static The field with the requested criterion + * @return self The field with the requested criterion */ - public static function EQ(string $fieldName, mixed $value, string $paramName = ''): static + public static function EQ(string $fieldName, mixed $value, string $paramName = ''): self { - return new static($fieldName, Op::EQ, $value, $paramName); + return new self($fieldName, Op::EQ, $value, $paramName); } /** @@ -101,11 +102,11 @@ class Field * @param string $fieldName The name of the field against which the value will be compared * @param mixed $value The value for the greater than comparison * @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank) - * @return static The field with the requested criterion + * @return self The field with the requested criterion */ - public static function GT(string $fieldName, mixed $value, string $paramName = ''): static + public static function GT(string $fieldName, mixed $value, string $paramName = ''): self { - return new static($fieldName, Op::GT, $value, $paramName); + return new self($fieldName, Op::GT, $value, $paramName); } /** @@ -114,11 +115,11 @@ class Field * @param string $fieldName The name of the field against which the value will be compared * @param mixed $value The value for the greater than or equal to comparison * @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank) - * @return static The field with the requested criterion + * @return self The field with the requested criterion */ - public static function GE(string $fieldName, mixed $value, string $paramName = ''): static + public static function GE(string $fieldName, mixed $value, string $paramName = ''): self { - return new static($fieldName, Op::GE, $value, $paramName); + return new self($fieldName, Op::GE, $value, $paramName); } /** @@ -127,11 +128,11 @@ class Field * @param string $fieldName The name of the field against which the value will be compared * @param mixed $value The value for the less than comparison * @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank) - * @return static The field with the requested criterion + * @return self The field with the requested criterion */ - public static function LT(string $fieldName, mixed $value, string $paramName = ''): static + public static function LT(string $fieldName, mixed $value, string $paramName = ''): self { - return new static($fieldName, Op::LT, $value, $paramName); + return new self($fieldName, Op::LT, $value, $paramName); } /** @@ -140,11 +141,11 @@ class Field * @param string $fieldName The name of the field against which the value will be compared * @param mixed $value The value for the less than or equal to comparison * @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank) - * @return static The field with the requested criterion + * @return self The field with the requested criterion */ - public static function LE(string $fieldName, mixed $value, string $paramName = ''): static + public static function LE(string $fieldName, mixed $value, string $paramName = ''): self { - return new static($fieldName, Op::LE, $value, $paramName); + return new self($fieldName, Op::LE, $value, $paramName); } /** @@ -153,11 +154,11 @@ class Field * @param string $fieldName The name of the field against which the value will be compared * @param mixed $value The value for the not equals comparison * @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank) - * @return static The field with the requested criterion + * @return self The field with the requested criterion */ - public static function NE(string $fieldName, mixed $value, string $paramName = ''): static + public static function NE(string $fieldName, mixed $value, string $paramName = ''): self { - return new static($fieldName, Op::NE, $value, $paramName); + return new self($fieldName, Op::NE, $value, $paramName); } /** @@ -167,32 +168,32 @@ class Field * @param mixed $minValue The lower value for range * @param mixed $maxValue The upper value for the range * @param string $paramName The name of the parameter to which this should be bound (optional; generated if blank) - * @return static The field with the requested criterion + * @return self The field with the requested criterion */ - public static function BT(string $fieldName, mixed $minValue, mixed $maxValue, string $paramName = ''): static + public static function BT(string $fieldName, mixed $minValue, mixed $maxValue, string $paramName = ''): self { - return new static($fieldName, Op::BT, [$minValue, $maxValue], $paramName); + return new self($fieldName, Op::BT, [$minValue, $maxValue], $paramName); } /** * Create an exists (IS NOT NULL) field criterion * * @param string $fieldName The name of the field for which existence will be checked - * @return static The field with the requested criterion + * @return self The field with the requested criterion */ - public static function EX(string $fieldName): static + public static function EX(string $fieldName): self { - return new static($fieldName, Op::EX, '', ''); + return new self($fieldName, Op::EX, '', ''); } /** * Create a not exists (IS NULL) field criterion * * @param string $fieldName The name of the field for which non-existence will be checked - * @return static The field with the requested criterion + * @return self The field with the requested criterion */ - public static function NEX(string $fieldName): static + public static function NEX(string $fieldName): self { - return new static($fieldName, Op::NEX, '', ''); + return new self($fieldName, Op::NEX, '', ''); } } diff --git a/src/Find.php b/src/Find.php index c283f4e..ae6c3f5 100644 --- a/src/Find.php +++ b/src/Find.php @@ -8,8 +8,8 @@ declare(strict_types=1); namespace BitBadger\PDODocument; +use BitBadger\InspiredByFSharp\Option; use BitBadger\PDODocument\Mapper\DocumentMapper; -use PhpOption\Option; /** * Functions to find documents @@ -70,7 +70,7 @@ class Find * * @template TDoc The type of document to 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 mixed[]|object $criteria The criteria for the JSON containment query * @param class-string $className The name of the class to be retrieved * @return DocumentList A list of documents matching the JSON containment query * @throws DocumentException If the database mode is not PostgreSQL, or if an error occurs @@ -120,7 +120,7 @@ class Find * * @template TDoc The type of document to 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 mixed[]|object $criteria The criteria for the JSON containment query * @param class-string $className The name of the class to be retrieved * @return Option 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 diff --git a/src/Mapper/ArrayMapper.php b/src/Mapper/ArrayMapper.php index baaf9c1..453a1c2 100644 --- a/src/Mapper/ArrayMapper.php +++ b/src/Mapper/ArrayMapper.php @@ -10,6 +10,8 @@ namespace BitBadger\PDODocument\Mapper; /** * A mapper that returns the associative array from the database + * + * @implements Mapper> */ class ArrayMapper implements Mapper { diff --git a/src/Mapper/CountMapper.php b/src/Mapper/CountMapper.php index 91695d3..7a60019 100644 --- a/src/Mapper/CountMapper.php +++ b/src/Mapper/CountMapper.php @@ -10,6 +10,8 @@ namespace BitBadger\PDODocument\Mapper; /** * A mapper that returns the integer value of the first item in the results + * + * @implements Mapper */ class CountMapper implements Mapper { diff --git a/src/Mapper/DocumentMapper.php b/src/Mapper/DocumentMapper.php index 9bf4859..f8e650c 100644 --- a/src/Mapper/DocumentMapper.php +++ b/src/Mapper/DocumentMapper.php @@ -31,7 +31,7 @@ class DocumentMapper implements Mapper /** * Map a result to a domain class instance * - * @param array $result An associative array representing a single database result + * @param array $result An associative array representing a single database result * @return TDoc The document, deserialized from its JSON representation * @throws DocumentException If the JSON cannot be deserialized */ diff --git a/src/Mapper/ExistsMapper.php b/src/Mapper/ExistsMapper.php index 56f6a26..42aee1f 100644 --- a/src/Mapper/ExistsMapper.php +++ b/src/Mapper/ExistsMapper.php @@ -13,6 +13,8 @@ use Exception; /** * Map an EXISTS result to a boolean value + * + * @implements Mapper */ class ExistsMapper implements Mapper { diff --git a/src/Mapper/Mapper.php b/src/Mapper/Mapper.php index d0af9ca..c923d14 100644 --- a/src/Mapper/Mapper.php +++ b/src/Mapper/Mapper.php @@ -18,7 +18,7 @@ interface Mapper /** * Map a result to the specified type * - * @param array $result An associative array representing a single database result + * @param array $result An associative array representing a single database result * @return T The item mapped from the given result */ public function map(array $result): mixed; diff --git a/src/Parameters.php b/src/Parameters.php index 6dc21e9..22b35fd 100644 --- a/src/Parameters.php +++ b/src/Parameters.php @@ -30,8 +30,8 @@ class Parameters * Create a parameter with a JSON value * * @param string $name The name of the JSON parameter - * @param object|array $document The value that should be passed as a JSON string - * @return array An associative array with the named parameter/value pair + * @param mixed[]|array $document The value that should be passed as a JSON string + * @return array An associative array with the named parameter/value pair */ public static function json(string $name, object|array $document): array { @@ -74,8 +74,8 @@ class Parameters * Add field parameters to the given set of parameters * * @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 - * @return array An associative array of parameter names and values with the fields 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 */ public static function addFields(array $fields, array $parameters): array { @@ -87,7 +87,7 @@ class Parameters * * @param string $paramName The name of the parameter for the field names * @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 Exception If the database mode has not been set */ public static function fieldNames(string $paramName, array $fieldNames): array diff --git a/src/Patch.php b/src/Patch.php index 6e862a8..c4f19e1 100644 --- a/src/Patch.php +++ b/src/Patch.php @@ -18,7 +18,7 @@ class Patch * * @param string $tableName The table in which the document should be patched * @param mixed $docId The ID of the document to be patched - * @param array|object $patch The object with which the document should be patched (will be JSON-encoded) + * @param mixed[]|object $patch The object with which the document should be patched (will be JSON-encoded) * @throws DocumentException If any is encountered (database mode must be set) */ public static function byId(string $tableName, mixed $docId, array|object $patch): void @@ -32,7 +32,7 @@ class Patch * * @param string $tableName The table in which documents should be patched * @param array|Field[] $fields The field comparison to match - * @param array|object $patch The object with which the documents should be patched (will be JSON-encoded) + * @param mixed[]|object $patch The object with which the documents should be patched (will be JSON-encoded) * @param FieldMatch|null $match How to handle multiple conditions (optional; defaults to All) * @throws DocumentException If any is encountered */ @@ -48,8 +48,8 @@ class Patch * Patch documents using a JSON containment query (`@>`; PostgreSQL only) * * @param string $tableName The table in which documents should be patched - * @param array|object $criteria The JSON containment query values to match - * @param array|object $patch The object with which the documents should be patched (will be JSON-encoded) + * @param mixed[]|object $criteria The JSON containment query values to match + * @param mixed[]|object $patch The object with which the documents should be patched (will be JSON-encoded) * @throws DocumentException If the database mode is not PostgreSQL, or if an error occurs */ public static function byContains(string $tableName, array|object $criteria, array|object $patch): void @@ -63,7 +63,7 @@ class Patch * * @param string $tableName The table in which documents should be patched * @param string $path The JSON Path match string - * @param array|object $patch The object with which the documents should be patched (will be JSON-encoded) + * @param mixed[]|object $patch The object with which the documents should be patched (will be JSON-encoded) * @throws DocumentException If the database mode is not PostgreSQL, or if an error occurs */ public static function byJsonPath(string $tableName, string $path, array|object $patch): void diff --git a/src/Query/Definition.php b/src/Query/Definition.php index 1f1f953..b221ad1 100644 --- a/src/Query/Definition.php +++ b/src/Query/Definition.php @@ -49,7 +49,7 @@ class Definition * * @param string $tableName The name of the table which should be indexed * @param string $indexName The name of the index to create - * @param array $fields An array of fields to be indexed; may contain direction (ex. 'salary DESC') + * @param string[] $fields An array of fields to be indexed; may contain direction (ex. 'salary DESC') * @return string The CREATE INDEX statement to ensure the index exists */ public static function ensureIndexOn(string $tableName, string $indexName, array $fields): string diff --git a/src/Query/RemoveFields.php b/src/Query/RemoveFields.php index 16bded7..aa8ff93 100644 --- a/src/Query/RemoveFields.php +++ b/src/Query/RemoveFields.php @@ -24,7 +24,7 @@ class RemoveFields * Create an UPDATE statement to remove fields from a JSON document * * @param string $tableName The name of the table in which documents should be manipulated - * @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 * @return string The UPDATE statement to remove fields from a JSON document * @throws Exception If the database mode has not been set @@ -43,7 +43,7 @@ class RemoveFields * Query to remove fields from a document by the document's ID * * @param string $tableName The name of the table in which the document should be manipulated - * @param array $parameters The parameter list for the query + * @param array $parameters The parameter list for the query * @param mixed $docId The ID of the document from which fields should be removed (optional; string ID assumed) * @return string The UPDATE statement to remove fields from a document by its ID * @throws DocumentException If the database mode has not been set @@ -58,7 +58,7 @@ class RemoveFields * * @param string $tableName The name of the table in which documents should be manipulated * @param array|Field[] $fields The field comparison to match - * @param array $parameters The parameter list for the query + * @param array $parameters The parameter list for the query * @param FieldMatch|null $match How to handle multiple conditions (optional; defaults to All) * @return string The UPDATE statement to remove fields from documents via field comparison * @throws DocumentException If the database mode has not been set @@ -73,7 +73,7 @@ class RemoveFields * Query to remove fields from documents via a JSON containment query (PostgreSQL only) * * @param string $tableName The name of the table in which documents should be manipulated - * @param array $parameters The parameter list for the query + * @param array $parameters The parameter list for the query * @return string The UPDATE statement to remove fields from documents via a JSON containment query * @throws DocumentException If the database mode is not PostgreSQL */ @@ -86,7 +86,7 @@ class RemoveFields * Query to remove fields from documents via a JSON Path match query (PostgreSQL only) * * @param string $tableName The name of the table in which documents should be manipulated - * @param array $parameters The parameter list for the query + * @param array $parameters The parameter list for the query * @return string The UPDATE statement to remove fields from documents via a JSON Path match * @throws DocumentException */ diff --git a/src/RemoveFields.php b/src/RemoveFields.php index d719937..7100beb 100644 --- a/src/RemoveFields.php +++ b/src/RemoveFields.php @@ -50,7 +50,7 @@ class RemoveFields * Remove fields from documents via a JSON containment query (`@>`; PostgreSQL only) * * @param string $tableName The table in which documents should have fields removed - * @param array|object $criteria The JSON containment query values + * @param mixed[]|object $criteria The JSON containment query values * @param array|string[] $fieldNames The names of the fields to be removed * @throws DocumentException If the database mode is not PostgreSQL, or if an error occurs */ diff --git a/tests/PjsonId.php b/tests/PjsonId.php index 0e5de4e..0580996 100644 --- a/tests/PjsonId.php +++ b/tests/PjsonId.php @@ -13,7 +13,7 @@ use Square\Pjson\JsonDataSerializable; /** * A serializable ID wrapper class */ -class PjsonId implements JsonDataSerializable +final class PjsonId implements JsonDataSerializable { public function __construct(protected string $value) { } @@ -22,6 +22,11 @@ class PjsonId implements JsonDataSerializable return $this->value; } + /** + * @param mixed $jd JSON data + * @param string[]|string $path The path within the data to be retrieved + * @return self + */ public static function fromJsonData($jd, array|string $path = []): static { return new static($jd); diff --git a/tests/integration/postgresql/CustomTest.php b/tests/integration/postgresql/CustomTest.php index 728b958..6bab006 100644 --- a/tests/integration/postgresql/CustomTest.php +++ b/tests/integration/postgresql/CustomTest.php @@ -34,7 +34,7 @@ class CustomTest extends TestCase ThrowawayDb::destroy($this->dbName); } - public function testRunQuerySucceedsWithAValidQuery() + public function testRunQuerySucceedsWithAValidQuery(): void { $stmt = &Custom::runQuery('SELECT data FROM ' . ThrowawayDb::TABLE . ' LIMIT 1', []); try { @@ -44,7 +44,7 @@ class CustomTest extends TestCase } } - public function testRunQueryFailsWithAnInvalidQuery() + public function testRunQueryFailsWithAnInvalidQuery(): void { $this->expectException(DocumentException::class); $stmt = &Custom::runQuery('GRAB stuff FROM over_there UNTIL done', []); @@ -55,7 +55,7 @@ class CustomTest extends TestCase } } - public function testListSucceedsWhenDataIsFound() + public function testListSucceedsWhenDataIsFound(): void { $list = Custom::list(Query::selectFromTable(ThrowawayDb::TABLE), [], new DocumentMapper(TestDocument::class)); $this->assertNotNull($list, 'The document list should not be null'); @@ -64,7 +64,7 @@ class CustomTest extends TestCase $this->assertEquals(5, $count, 'There should have been 5 documents in the list'); } - public function testListSucceedsWhenNoDataIsFound() + public function testListSucceedsWhenNoDataIsFound(): void { $list = Custom::list( Query::selectFromTable(ThrowawayDb::TABLE) . " WHERE (data->>'num_value')::numeric > :value", @@ -73,7 +73,7 @@ class CustomTest extends TestCase $this->assertFalse($list->hasItems(), 'There should have been no documents in the list'); } - public function testArraySucceedsWhenDataIsFound() + public function testArraySucceedsWhenDataIsFound(): void { $array = Custom::array(Query::selectFromTable(ThrowawayDb::TABLE) . " WHERE data->>'sub' IS NOT NULL", [], new DocumentMapper(TestDocument::class)); @@ -81,7 +81,7 @@ class CustomTest extends TestCase $this->assertCount(2, $array, 'There should have been 2 documents in the array'); } - public function testArraySucceedsWhenNoDataIsFound() + public function testArraySucceedsWhenNoDataIsFound(): void { $array = Custom::array(Query::selectFromTable(ThrowawayDb::TABLE) . " WHERE data->>'value' = :value", [':value' => 'not there'], new DocumentMapper(TestDocument::class)); @@ -93,7 +93,7 @@ class CustomTest extends TestCase { $doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id", [':id' => 'one'], new DocumentMapper(TestDocument::class)); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals('one', $doc->get()->id, 'The incorrect document was returned'); } @@ -101,17 +101,17 @@ class CustomTest extends TestCase { $doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id", [':id' => 'eighty'], new DocumentMapper(TestDocument::class)); - $this->assertTrue($doc->isEmpty(), '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(): void { Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); $remaining = Count::all(ThrowawayDb::TABLE); $this->assertEquals(0, $remaining, 'There should be no documents remaining in the table'); } - public function testNonQuerySucceedsWhenNoDataMatchesWhereClause() + public function testNonQuerySucceedsWhenNoDataMatchesWhereClause(): void { Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE . " WHERE (data->>'num_value')::numeric > :value", [':value' => 100]); @@ -119,7 +119,7 @@ class CustomTest extends TestCase $this->assertEquals(5, $remaining, 'There should be 5 documents remaining in the table'); } - public function testScalarSucceeds() + public function testScalarSucceeds(): void { $value = Custom::scalar("SELECT 5 AS it", [], new CountMapper()); $this->assertEquals(5, $value, 'The scalar value was not returned correctly'); diff --git a/tests/integration/postgresql/DocumentTest.php b/tests/integration/postgresql/DocumentTest.php index e5d5979..01d09d4 100644 --- a/tests/integration/postgresql/DocumentTest.php +++ b/tests/integration/postgresql/DocumentTest.php @@ -40,7 +40,7 @@ class DocumentTest extends TestCase { Document::insert(ThrowawayDb::TABLE, ['id' => 'turkey', 'sub' => ['foo' => 'gobble', 'bar' => 'gobble']]); $tryDoc = Find::byId(ThrowawayDb::TABLE, 'turkey', TestDocument::class); - $this->assertTrue($tryDoc->isDefined(), '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('', $doc->value, 'The value was incorrect'); @@ -59,14 +59,14 @@ class DocumentTest extends TestCase Document::insert(ThrowawayDb::TABLE, ['id' => 0, 'value' => 'new', 'num_value' => 8]); $doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE, [], new ArrayMapper()); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $obj = json_decode($doc->get()['data']); $this->assertEquals(1, $obj->id, 'The ID 1 should have been auto-generated'); Document::insert(ThrowawayDb::TABLE, ['id' => 0, 'value' => 'again', 'num_value' => 7]); $doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE " . Query::whereById(docId: 2), [':id' => 2], new ArrayMapper()); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $obj = json_decode($doc->get()['data']); $this->assertEquals(2, $obj->id, 'The ID 2 should have been auto-generated'); } finally { @@ -82,7 +82,7 @@ class DocumentTest extends TestCase Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Document::insert(ThrowawayDb::TABLE, ['id' => 7, 'value' => 'new', 'num_value' => 8]); $doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE, [], new ArrayMapper()); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $obj = json_decode($doc->get()['data']); $this->assertEquals(7, $obj->id, 'The ID 7 should have been stored'); } finally { @@ -98,7 +98,7 @@ class DocumentTest extends TestCase Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Document::insert(ThrowawayDb::TABLE, ['id' => '', 'num_value' => 5]); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 5)], TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertNotEmpty($doc->get()->id, 'The ID should have been auto-generated'); } finally { Configuration::$autoId = AutoId::None; @@ -114,7 +114,7 @@ class DocumentTest extends TestCase $uuid = AutoId::generateUUID(); Document::insert(ThrowawayDb::TABLE, ['id' => $uuid, 'value' => 'uuid', 'num_value' => 12]); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 12)], TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals($uuid, $doc->get()->id, 'The ID should not have been changed'); } finally { Configuration::$autoId = AutoId::None; @@ -130,7 +130,7 @@ class DocumentTest extends TestCase Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Document::insert(ThrowawayDb::TABLE, ['id' => '', 'value' => 'new', 'num_value' => 8]); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 8)], TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals(6, strlen($doc->get()->id), 'The ID should have been auto-generated and had 6 characters'); } finally { @@ -147,7 +147,7 @@ class DocumentTest extends TestCase Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Document::insert(ThrowawayDb::TABLE, ['id' => 'my-key', 'value' => 'old', 'num_value' => 3]); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 3)], TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals('my-key', $doc->get()->id, 'The ID should not have been changed'); } finally { Configuration::$autoId = AutoId::None; @@ -159,7 +159,7 @@ class DocumentTest extends TestCase { Document::insert(ThrowawayDb::TABLE, new TestDocument('turkey', sub: new SubDocument('gobble', 'gobble'))); $tryDoc = Find::byId(ThrowawayDb::TABLE, 'turkey', TestDocument::class); - $this->assertTrue($tryDoc->isDefined(), '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('', $doc->value, 'The value was incorrect'); @@ -178,12 +178,12 @@ class DocumentTest extends TestCase Document::insert(ThrowawayDb::TABLE, new NumDocument(value: 'taco')); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'taco')], NumDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals(1, $doc->get()->id, 'The ID 1 should have been auto-generated'); Document::insert(ThrowawayDb::TABLE, new NumDocument(value: 'burrito')); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'burrito')], NumDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals(2, $doc->get()->id, 'The ID 2 should have been auto-generated'); } finally { Configuration::$autoId = AutoId::None; @@ -198,7 +198,7 @@ class DocumentTest extends TestCase Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Document::insert(ThrowawayDb::TABLE, new NumDocument(64, 'large')); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'large')], NumDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals(64, $doc->get()->id, 'The ID 64 should have been stored'); } finally { Configuration::$autoId = AutoId::None; @@ -213,7 +213,7 @@ class DocumentTest extends TestCase Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Document::insert(ThrowawayDb::TABLE, new TestDocument(value: 'something', num_value: 9)); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EX('value')], TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertNotEmpty($doc->get()->id, 'The ID should have been auto-generated'); } finally { Configuration::$autoId = AutoId::None; @@ -229,7 +229,7 @@ class DocumentTest extends TestCase $uuid = AutoId::generateUUID(); Document::insert(ThrowawayDb::TABLE, new TestDocument($uuid, num_value: 14)); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 14)], TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals($uuid, $doc->get()->id, 'The ID should not have been changed'); } finally { Configuration::$autoId = AutoId::None; @@ -245,7 +245,7 @@ class DocumentTest extends TestCase Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Document::insert(ThrowawayDb::TABLE, new TestDocument(num_value: 55)); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 55)], TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals(40, strlen($doc->get()->id), 'The ID should have been auto-generated and had 40 characters'); } finally { @@ -262,7 +262,7 @@ class DocumentTest extends TestCase Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Document::insert(ThrowawayDb::TABLE, new TestDocument('my-key', num_value: 3)); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 3)], TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals('my-key', $doc->get()->id, 'The ID should not have been changed'); } finally { Configuration::$autoId = AutoId::None; @@ -279,14 +279,14 @@ class DocumentTest extends TestCase { Document::save(ThrowawayDb::TABLE, new TestDocument('test', sub: new SubDocument('a', 'b'))); $doc = Find::byId(ThrowawayDb::TABLE, 'one', TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); } public function testSaveSucceedsWhenADocumentIsUpdated(): void { Document::save(ThrowawayDb::TABLE, new TestDocument('two', num_value: 44)); $tryDoc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class); - $this->assertTrue($tryDoc->isDefined(), '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->assertNull($doc->sub, 'The sub-document should have been null'); @@ -296,7 +296,7 @@ class DocumentTest extends TestCase { Document::update(ThrowawayDb::TABLE, 'one', new TestDocument('one', 'howdy', 8, new SubDocument('y', 'z'))); $tryDoc = Find::byId(ThrowawayDb::TABLE, 'one', TestDocument::class); - $this->assertNotFalse($tryDoc->isDefined(), '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(8, $doc->num_value, 'The numeric value was incorrect'); @@ -309,6 +309,6 @@ class DocumentTest extends TestCase { Document::update(ThrowawayDb::TABLE, 'two-hundred', new TestDocument('200')); $doc = Find::byId(ThrowawayDb::TABLE, 'two-hundred', TestDocument::class); - $this->assertTrue($doc->isEmpty(), 'There should not have been a document returned'); + $this->assertTrue($doc->isNone(), 'There should not have been a document returned'); } } diff --git a/tests/integration/postgresql/FindTest.php b/tests/integration/postgresql/FindTest.php index b04523d..bb81b97 100644 --- a/tests/integration/postgresql/FindTest.php +++ b/tests/integration/postgresql/FindTest.php @@ -55,7 +55,7 @@ class FindTest extends TestCase public function testByIdSucceedsWhenADocumentIsFound(): void { $doc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals('two', $doc->get()->id, 'An incorrect document was returned'); } @@ -65,7 +65,7 @@ class FindTest extends TestCase Delete::byFields(ThrowawayDb::TABLE, [Field::NEX('absent')]); Document::insert(ThrowawayDb::TABLE, ['id' => 18, 'value' => 'howdy']); $doc = Find::byId(ThrowawayDb::TABLE, 18, NumDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals(18, $doc->get()->id, 'An incorrect document was returned'); } @@ -73,7 +73,7 @@ class FindTest extends TestCase public function testByIdSucceedsWhenADocumentIsNotFound(): void { $doc = Find::byId(ThrowawayDb::TABLE, 'seventy-five', TestDocument::class); - $this->assertTrue($doc->isEmpty(), 'There should not have been a document returned'); + $this->assertTrue($doc->isNone(), 'There should not have been a document returned'); } public function testByFieldsSucceedsWhenDocumentsAreFound(): void @@ -129,48 +129,48 @@ class FindTest extends TestCase public function testFirstByFieldsSucceedsWhenADocumentIsFound(): void { $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'another')], TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals('two', $doc->get()->id, 'The incorrect document was returned'); } public function testFirstByFieldsSucceedsWhenMultipleDocumentsAreFound(): void { $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('sub.foo', 'green')], TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertContains($doc->get()->id, ['two', 'four'], 'An incorrect document was returned'); } public function testFirstByFieldsSucceedsWhenADocumentIsNotFound(): void { $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'absent')], TestDocument::class); - $this->assertTrue($doc->isEmpty(), 'There should not have been a document returned'); + $this->assertTrue($doc->isNone(), 'There should not have been a document returned'); } public function testFirstByContainsSucceedsWhenADocumentIsFound(): void { $doc = Find::firstByContains(ThrowawayDb::TABLE, ['value' => 'FIRST!'], TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals('one', $doc->get()->id, 'The incorrect document was returned'); } public function testFirstByContainsSucceedsWhenMultipleDocumentsAreFound(): void { $doc = Find::firstByContains(ThrowawayDb::TABLE, ['value' => 'purple'], TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertContains($doc->get()->id, ['four', 'five'], 'An incorrect document was returned'); } public function testFirstByContainsSucceedsWhenADocumentIsNotFound(): void { $doc = Find::firstByContains(ThrowawayDb::TABLE, ['value' => 'indigo'], TestDocument::class); - $this->assertTrue($doc->isEmpty(), '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')] public function testFirstByJsonPathSucceedsWhenADocumentIsFound(): void { $doc = Find::firstByJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ == 10)', TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals('two', $doc->get()->id, 'The incorrect document was returned'); } @@ -178,7 +178,7 @@ class FindTest extends TestCase public function testFirstByJsonPathSucceedsWhenMultipleDocumentsAreFound(): void { $doc = Find::firstByJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ > 10)', TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertContains($doc->get()->id, ['four', 'five'], 'An incorrect document was returned'); } @@ -186,6 +186,6 @@ class FindTest extends TestCase public function testFirstByJsonPathSucceedsWhenADocumentIsNotFound(): void { $doc = Find::firstByJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ > 100)', TestDocument::class); - $this->assertTrue($doc->isEmpty(), 'There should not have been a document returned'); + $this->assertTrue($doc->isNone(), 'There should not have been a document returned'); } } diff --git a/tests/integration/postgresql/PatchTest.php b/tests/integration/postgresql/PatchTest.php index 467ddf4..2dc4dfe 100644 --- a/tests/integration/postgresql/PatchTest.php +++ b/tests/integration/postgresql/PatchTest.php @@ -39,7 +39,7 @@ class PatchTest extends TestCase { Patch::byId(ThrowawayDb::TABLE, 'one', ['num_value' => 44]); $doc = Find::byId(ThrowawayDb::TABLE, 'one', TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals(44, $doc->get()->num_value, 'The updated document is not correct'); } @@ -71,7 +71,7 @@ class PatchTest extends TestCase { Patch::byContains(ThrowawayDb::TABLE, ['value' => 'another'], ['num_value' => 12]); $tryDoc = Find::firstByContains(ThrowawayDb::TABLE, ['value' => 'another'], TestDocument::class); - $this->assertNotFalse($tryDoc->isDefined(), 'There should have been a document returned'); + $this->assertNotFalse($tryDoc->isSome(), 'There should have been a document returned'); $doc = $tryDoc->get(); $this->assertEquals('two', $doc->id, 'An incorrect document was returned'); $this->assertEquals(12, $doc->num_value, 'The document was not patched'); diff --git a/tests/integration/postgresql/RemoveFieldsTest.php b/tests/integration/postgresql/RemoveFieldsTest.php index e32f94c..3f956f5 100644 --- a/tests/integration/postgresql/RemoveFieldsTest.php +++ b/tests/integration/postgresql/RemoveFieldsTest.php @@ -39,7 +39,7 @@ class RemoveFieldsTest extends TestCase { RemoveFields::byId(ThrowawayDb::TABLE, 'two', ['sub', 'value']); $tryDoc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class); - $this->assertNotFalse($tryDoc->isDefined(), 'There should have been a document returned'); + $this->assertNotFalse($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->assertNull($doc->sub, 'Sub-document should have been null'); @@ -63,7 +63,7 @@ class RemoveFieldsTest extends TestCase { RemoveFields::byFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 17)], ['sub']); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 17)], TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertNull($doc->get()->sub, 'Sub-document should have been null'); } diff --git a/tests/integration/sqlite/CustomTest.php b/tests/integration/sqlite/CustomTest.php index 7d47d27..a34b2ad 100644 --- a/tests/integration/sqlite/CustomTest.php +++ b/tests/integration/sqlite/CustomTest.php @@ -34,7 +34,7 @@ class CustomTest extends TestCase ThrowawayDb::destroy($this->dbName); } - public function testRunQuerySucceedsWithAValidQuery() + public function testRunQuerySucceedsWithAValidQuery(): void { $stmt = &Custom::runQuery('SELECT data FROM ' . ThrowawayDb::TABLE . ' LIMIT 1', []); try { @@ -44,7 +44,7 @@ class CustomTest extends TestCase } } - public function testRunQueryFailsWithAnInvalidQuery() + public function testRunQueryFailsWithAnInvalidQuery(): void { $this->expectException(DocumentException::class); $stmt = &Custom::runQuery('GRAB stuff FROM over_there UNTIL done', []); @@ -55,7 +55,7 @@ class CustomTest extends TestCase } } - public function testListSucceedsWhenDataIsFound() + public function testListSucceedsWhenDataIsFound(): void { $list = Custom::list(Query::selectFromTable(ThrowawayDb::TABLE), [], new DocumentMapper(TestDocument::class)); $this->assertNotNull($list, 'The document list should not be null'); @@ -64,7 +64,7 @@ class CustomTest extends TestCase $this->assertEquals(5, $count, 'There should have been 5 documents in the list'); } - public function testListSucceedsWhenNoDataIsFound() + public function testListSucceedsWhenNoDataIsFound(): void { $list = Custom::list(Query::selectFromTable(ThrowawayDb::TABLE) . " WHERE data->>'num_value' > :value", [':value' => 100], new DocumentMapper(TestDocument::class)); @@ -72,7 +72,7 @@ class CustomTest extends TestCase $this->assertFalse($list->hasItems(), 'There should have been no documents in the list'); } - public function testArraySucceedsWhenDataIsFound() + public function testArraySucceedsWhenDataIsFound(): void { $array = Custom::array(Query::selectFromTable(ThrowawayDb::TABLE) . " WHERE data->>'sub' IS NOT NULL", [], new DocumentMapper(TestDocument::class)); @@ -80,7 +80,7 @@ class CustomTest extends TestCase $this->assertCount(2, $array, 'There should have been 2 documents in the array'); } - public function testArraySucceedsWhenNoDataIsFound() + public function testArraySucceedsWhenNoDataIsFound(): void { $array = Custom::array(Query::selectFromTable(ThrowawayDb::TABLE) . " WHERE data->>'value' = :value", [':value' => 'not there'], new DocumentMapper(TestDocument::class)); @@ -92,7 +92,7 @@ class CustomTest extends TestCase { $doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id", [':id' => 'one'], new DocumentMapper(TestDocument::class)); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals('one', $doc->get()->id, 'The incorrect document was returned'); } @@ -100,24 +100,24 @@ class CustomTest extends TestCase { $doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id", [':id' => 'eighty'], new DocumentMapper(TestDocument::class)); - $this->assertTrue($doc->isEmpty(), '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(): void { Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); $remaining = Count::all(ThrowawayDb::TABLE); $this->assertEquals(0, $remaining, 'There should be no documents remaining in the table'); } - public function testNonQuerySucceedsWhenNoDataMatchesWhereClause() + public function testNonQuerySucceedsWhenNoDataMatchesWhereClause(): void { Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE . " WHERE data->>'num_value' > :value", [':value' => 100]); $remaining = Count::all(ThrowawayDb::TABLE); $this->assertEquals(5, $remaining, 'There should be 5 documents remaining in the table'); } - public function testScalarSucceeds() + public function testScalarSucceeds(): void { $value = Custom::scalar("SELECT 5 AS it", [], new CountMapper()); $this->assertEquals(5, $value, 'The scalar value was not returned correctly'); diff --git a/tests/integration/sqlite/DocumentTest.php b/tests/integration/sqlite/DocumentTest.php index f7767df..b0b8f01 100644 --- a/tests/integration/sqlite/DocumentTest.php +++ b/tests/integration/sqlite/DocumentTest.php @@ -40,7 +40,7 @@ class DocumentTest extends TestCase { Document::insert(ThrowawayDb::TABLE, ['id' => 'turkey', 'sub' => ['foo' => 'gobble', 'bar' => 'gobble']]); $tryDoc = Find::byId(ThrowawayDb::TABLE, 'turkey', TestDocument::class); - $this->assertTrue($tryDoc->isDefined(), '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('', $doc->value, 'The value was incorrect'); @@ -59,14 +59,14 @@ class DocumentTest extends TestCase Document::insert(ThrowawayDb::TABLE, ['id' => 0, 'value' => 'new', 'num_value' => 8]); $doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE, [], new ArrayMapper()); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $obj = json_decode($doc->get()['data']); $this->assertEquals(1, $obj->id, 'The ID 1 should have been auto-generated'); Document::insert(ThrowawayDb::TABLE, ['id' => 0, 'value' => 'again', 'num_value' => 7]); $doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = 2", [], new ArrayMapper()); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $obj = json_decode($doc->get()['data']); $this->assertEquals(2, $obj->id, 'The ID 2 should have been auto-generated'); } finally { @@ -82,7 +82,7 @@ class DocumentTest extends TestCase Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Document::insert(ThrowawayDb::TABLE, ['id' => 7, 'value' => 'new', 'num_value' => 8]); $doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE, [], new ArrayMapper()); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $obj = json_decode($doc->get()['data']); $this->assertEquals(7, $obj->id, 'The ID 7 should have been stored'); } finally { @@ -98,7 +98,7 @@ class DocumentTest extends TestCase Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Document::insert(ThrowawayDb::TABLE, ['id' => '', 'num_value' => 5]); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 5)], TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertNotEmpty($doc->get()->id, 'The ID should have been auto-generated'); } finally { Configuration::$autoId = AutoId::None; @@ -114,7 +114,7 @@ class DocumentTest extends TestCase $uuid = AutoId::generateUUID(); Document::insert(ThrowawayDb::TABLE, ['id' => $uuid, 'value' => 'uuid', 'num_value' => 12]); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 12)], TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals($uuid, $doc->get()->id, 'The ID should not have been changed'); } finally { Configuration::$autoId = AutoId::None; @@ -130,7 +130,7 @@ class DocumentTest extends TestCase Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Document::insert(ThrowawayDb::TABLE, ['id' => '', 'value' => 'new', 'num_value' => 8]); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 8)], TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals(6, strlen($doc->get()->id), 'The ID should have been auto-generated and had 6 characters'); } finally { @@ -147,7 +147,7 @@ class DocumentTest extends TestCase Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Document::insert(ThrowawayDb::TABLE, ['id' => 'my-key', 'value' => 'old', 'num_value' => 3]); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 3)], TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals('my-key', $doc->get()->id, 'The ID should not have been changed'); } finally { Configuration::$autoId = AutoId::None; @@ -159,7 +159,7 @@ class DocumentTest extends TestCase { Document::insert(ThrowawayDb::TABLE, new TestDocument('turkey', sub: new SubDocument('gobble', 'gobble'))); $tryDoc = Find::byId(ThrowawayDb::TABLE, 'turkey', TestDocument::class); - $this->assertNotFalse($tryDoc->isDefined(), '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('', $doc->value, 'The value was incorrect'); @@ -178,12 +178,12 @@ class DocumentTest extends TestCase Document::insert(ThrowawayDb::TABLE, new NumDocument(value: 'taco')); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'taco')], NumDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals(1, $doc->get()->id, 'The ID 1 should have been auto-generated'); Document::insert(ThrowawayDb::TABLE, new NumDocument(value: 'burrito')); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'burrito')], NumDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals(2, $doc->get()->id, 'The ID 2 should have been auto-generated'); } finally { Configuration::$autoId = AutoId::None; @@ -198,7 +198,7 @@ class DocumentTest extends TestCase Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Document::insert(ThrowawayDb::TABLE, new NumDocument(64, 'large')); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'large')], NumDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals(64, $doc->get()->id, 'The ID 64 should have been stored'); } finally { Configuration::$autoId = AutoId::None; @@ -213,7 +213,7 @@ class DocumentTest extends TestCase Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Document::insert(ThrowawayDb::TABLE, new TestDocument(value: 'something', num_value: 9)); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EX('value')], TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertNotEmpty($doc->get()->id, 'The ID should have been auto-generated'); } finally { Configuration::$autoId = AutoId::None; @@ -229,7 +229,7 @@ class DocumentTest extends TestCase $uuid = AutoId::generateUUID(); Document::insert(ThrowawayDb::TABLE, new TestDocument($uuid, num_value: 14)); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 14)], TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals($uuid, $doc->get()->id, 'The ID should not have been changed'); } finally { Configuration::$autoId = AutoId::None; @@ -245,7 +245,7 @@ class DocumentTest extends TestCase Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Document::insert(ThrowawayDb::TABLE, new TestDocument(num_value: 55)); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 55)], TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals(40, strlen($doc->get()->id), 'The ID should have been auto-generated and had 40 characters'); } finally { @@ -262,7 +262,7 @@ class DocumentTest extends TestCase Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []); Document::insert(ThrowawayDb::TABLE, new TestDocument('my-key', num_value: 3)); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 3)], TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals('my-key', $doc->get()->id, 'The ID should not have been changed'); } finally { Configuration::$autoId = AutoId::None; @@ -279,14 +279,14 @@ class DocumentTest extends TestCase { Document::save(ThrowawayDb::TABLE, new TestDocument('test', sub: new SubDocument('a', 'b'))); $doc = Find::byId(ThrowawayDb::TABLE, 'one', TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); } public function testSaveSucceedsWhenADocumentIsUpdated(): void { Document::save(ThrowawayDb::TABLE, new TestDocument('two', num_value: 44)); $tryDoc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class); - $this->assertTrue($tryDoc->isDefined(), '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->assertNull($doc->sub, 'The sub-document should have been null'); @@ -296,7 +296,7 @@ class DocumentTest extends TestCase { Document::update(ThrowawayDb::TABLE, 'one', new TestDocument('one', 'howdy', 8, new SubDocument('y', 'z'))); $tryDoc = Find::byId(ThrowawayDb::TABLE, 'one', TestDocument::class); - $this->assertTrue($tryDoc->isDefined(), '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(8, $doc->num_value, 'The numeric value was incorrect'); @@ -309,6 +309,6 @@ class DocumentTest extends TestCase { Document::update(ThrowawayDb::TABLE, 'two-hundred', new TestDocument('200')); $doc = Find::byId(ThrowawayDb::TABLE, 'two-hundred', TestDocument::class); - $this->assertTrue($doc->isEmpty(), 'There should not have been a document returned'); + $this->assertTrue($doc->isNone(), 'There should not have been a document returned'); } } diff --git a/tests/integration/sqlite/FindTest.php b/tests/integration/sqlite/FindTest.php index b6f836b..ed3f175 100644 --- a/tests/integration/sqlite/FindTest.php +++ b/tests/integration/sqlite/FindTest.php @@ -55,7 +55,7 @@ class FindTest extends TestCase public function testByIdSucceedsWhenADocumentIsFound(): void { $doc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals('two', $doc->get()->id, 'An incorrect document was returned'); } @@ -64,7 +64,7 @@ class FindTest extends TestCase { Document::insert(ThrowawayDb::TABLE, ['id' => 18, 'value' => 'howdy']); $doc = Find::byId(ThrowawayDb::TABLE, 18, TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals('18', $doc->get()->id, 'An incorrect document was returned'); } @@ -72,7 +72,7 @@ class FindTest extends TestCase public function testByIdSucceedsWhenADocumentIsNotFound(): void { $doc = Find::byId(ThrowawayDb::TABLE, 'seventy-five', TestDocument::class); - $this->assertTrue($doc->isEmpty(), 'There should not have been a document returned'); + $this->assertTrue($doc->isNone(), 'There should not have been a document returned'); } public function testByFieldsSucceedsWhenDocumentsAreFound(): void @@ -107,21 +107,21 @@ class FindTest extends TestCase public function testFirstByFieldsSucceedsWhenADocumentIsFound(): void { $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'another')], TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals('two', $doc->get()->id, 'The incorrect document was returned'); } public function testFirstByFieldsSucceedsWhenMultipleDocumentsAreFound(): void { $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('sub.foo', 'green')], TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertContains($doc->get()->id, ['two', 'four'], 'An incorrect document was returned'); } public function testFirstByFieldsSucceedsWhenADocumentIsNotFound(): void { $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'absent')], TestDocument::class); - $this->assertTrue($doc->isEmpty(), 'There should not have been a document returned'); + $this->assertTrue($doc->isNone(), 'There should not have been a document returned'); } public function testFirstByContainsFails(): void diff --git a/tests/integration/sqlite/PatchTest.php b/tests/integration/sqlite/PatchTest.php index cd003b3..059b0cd 100644 --- a/tests/integration/sqlite/PatchTest.php +++ b/tests/integration/sqlite/PatchTest.php @@ -39,7 +39,7 @@ class PatchTest extends TestCase { Patch::byId(ThrowawayDb::TABLE, 'one', ['num_value' => 44]); $doc = Find::byId(ThrowawayDb::TABLE, 'one', TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertEquals(44, $doc->get()->num_value, 'The updated document is not correct'); } diff --git a/tests/integration/sqlite/RemoveFieldsTest.php b/tests/integration/sqlite/RemoveFieldsTest.php index 5972f3a..f0bdeb3 100644 --- a/tests/integration/sqlite/RemoveFieldsTest.php +++ b/tests/integration/sqlite/RemoveFieldsTest.php @@ -39,7 +39,7 @@ class RemoveFieldsTest extends TestCase { RemoveFields::byId(ThrowawayDb::TABLE, 'two', ['sub', 'value']); $tryDoc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class); - $this->assertTrue($tryDoc->isDefined(), '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->assertNull($doc->sub, 'Sub-document should have been null'); @@ -63,7 +63,7 @@ class RemoveFieldsTest extends TestCase { RemoveFields::byFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 17)], ['sub']); $doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 17)], TestDocument::class); - $this->assertTrue($doc->isDefined(), 'There should have been a document returned'); + $this->assertTrue($doc->isSome(), 'There should have been a document returned'); $this->assertNull($doc->get()->sub, 'Sub-document should have been null'); } diff --git a/tests/unit/ConfigurationTest.php b/tests/unit/ConfigurationTest.php index e32b48a..938fcdc 100644 --- a/tests/unit/ConfigurationTest.php +++ b/tests/unit/ConfigurationTest.php @@ -25,7 +25,7 @@ class ConfigurationTest extends TestCase } #[TestDox('ID field change succeeds')] - public function testIdFieldChangeSucceeds() + public function testIdFieldChangeSucceeds(): void { try { Configuration::$idField = 'EyeDee'; diff --git a/tests/unit/Mapper/StringMapperTest.php b/tests/unit/Mapper/StringMapperTest.php index a0805cc..e264a04 100644 --- a/tests/unit/Mapper/StringMapperTest.php +++ b/tests/unit/Mapper/StringMapperTest.php @@ -18,21 +18,21 @@ use PHPUnit\Framework\TestCase; #[TestDox('String Mapper (Unit tests)')] class StringMapperTest extends TestCase { - public function testMapSucceedsWhenFieldIsPresentAndString() + public function testMapSucceedsWhenFieldIsPresentAndString(): void { $result = ['test_field' => 'test_value']; $mapper = new StringMapper('test_field'); $this->assertEquals('test_value', $mapper->map($result), 'String value not returned correctly'); } - public function testMapSucceedsWhenFieldIsPresentAndNotString() + public function testMapSucceedsWhenFieldIsPresentAndNotString(): void { $result = ['a_number' => 6.7]; $mapper = new StringMapper('a_number'); $this->assertEquals('6.7', $mapper->map($result), 'Number value not returned correctly'); } - public function testMapSucceedsWhenFieldIsNotPresent() + public function testMapSucceedsWhenFieldIsNotPresent(): void { $mapper = new StringMapper('something_else'); $this->assertNull($mapper->map([]), 'Missing value not returned correctly'); diff --git a/tests/unit/Query/RemoveFieldsTest.php b/tests/unit/Query/RemoveFieldsTest.php index 2ab9da2..7ae6ccd 100644 --- a/tests/unit/Query/RemoveFieldsTest.php +++ b/tests/unit/Query/RemoveFieldsTest.php @@ -48,7 +48,7 @@ class RemoveFieldsTest extends TestCase } #[TestDox('By ID succeeds for PostgreSQL')] - public function testByIdSucceedsForPostgreSQL() + public function testByIdSucceedsForPostgreSQL(): void { Configuration::overrideMode(Mode::PgSQL); $this->assertEquals("UPDATE churro SET data = data - :bite::text[] WHERE data->>'id' = :id", @@ -56,7 +56,7 @@ class RemoveFieldsTest extends TestCase } #[TestDox('By ID succeeds for SQLite')] - public function testByIdSucceedsForSQLite() + public function testByIdSucceedsForSQLite(): void { Configuration::overrideMode(Mode::SQLite); $this->assertEquals("UPDATE quesadilla SET data = json_remove(data, :bite0) WHERE data->>'id' = :id", @@ -72,7 +72,7 @@ class RemoveFieldsTest extends TestCase } #[TestDox('By fields succeeds for PostgreSQL')] - public function testByFieldsSucceedsForPostgreSQL() + public function testByFieldsSucceedsForPostgreSQL(): void { Configuration::overrideMode(Mode::PgSQL); $this->assertEquals("UPDATE enchilada SET data = data - :sauce::text[] WHERE data->>'cheese' = :queso", @@ -82,7 +82,7 @@ class RemoveFieldsTest extends TestCase } #[TestDox('By fields succeeds for SQLite')] - public function testByFieldsSucceedsForSQLite() + public function testByFieldsSucceedsForSQLite(): void { Configuration::overrideMode(Mode::SQLite); $this->assertEquals( diff --git a/tests/unit/QueryTest.php b/tests/unit/QueryTest.php index f81b2f1..5d93fba 100644 --- a/tests/unit/QueryTest.php +++ b/tests/unit/QueryTest.php @@ -207,7 +207,7 @@ class QueryTest extends TestCase Query::save('test_tbl'), 'INSERT ON CONFLICT statement not constructed correctly'); } - public function testUpdateSucceeds() + public function testUpdateSucceeds(): void { $this->assertEquals("UPDATE testing SET data = :data WHERE data->>'id' = :id", Query::update('testing'), 'UPDATE statement not constructed correctly');