From 5b8196832d8da66f69b3e834fc9cc6e3610a0976 Mon Sep 17 00:00:00 2001 From: Connor Smyth Date: Sat, 12 Oct 2024 10:18:51 -0400 Subject: [PATCH] Building better documentation (#5) --- .gitignore | 1 + README.md | 17 + composer.json | 3 +- docs/Home.md | 44 ++ .../Pseudo/Exceptions/LogicException.md | 18 + .../Pseudo/Exceptions/PseudoException.md | 18 + .../Pseudo/Exceptions/PseudoPdoException.md | 18 + docs/classes/Pseudo/ParsedQuery.md | 147 ++++ docs/classes/Pseudo/Pdo.md | 443 +++++++++++ docs/classes/Pseudo/PdoStatement.md | 606 +++++++++++++++ docs/classes/Pseudo/QueryLog.md | 237 ++++++ docs/classes/Pseudo/Result.md | 709 ++++++++++++++++++ docs/classes/Pseudo/ResultCollection.md | 149 ++++ docs/index.md | 134 ---- docs/pdo.md | 233 ------ mkdocs.yaml | 7 +- phpdoc.dist.xml | 10 + src/QueryLog.php | 2 +- 18 files changed, 2425 insertions(+), 371 deletions(-) create mode 100644 docs/Home.md create mode 100644 docs/classes/Pseudo/Exceptions/LogicException.md create mode 100644 docs/classes/Pseudo/Exceptions/PseudoException.md create mode 100644 docs/classes/Pseudo/Exceptions/PseudoPdoException.md create mode 100644 docs/classes/Pseudo/ParsedQuery.md create mode 100644 docs/classes/Pseudo/Pdo.md create mode 100644 docs/classes/Pseudo/PdoStatement.md create mode 100644 docs/classes/Pseudo/QueryLog.md create mode 100644 docs/classes/Pseudo/Result.md create mode 100644 docs/classes/Pseudo/ResultCollection.md delete mode 100644 docs/index.md delete mode 100644 docs/pdo.md create mode 100644 phpdoc.dist.xml diff --git a/.gitignore b/.gitignore index 3708301..3d47ce1 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ composer.lock .phpunit.result.cache .phpunit.cache /var/ +/.phpdoc/ diff --git a/README.md b/README.md index cb66808..8718ef7 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,23 @@ Find the package on [packagist.org](https://packagist.org/packages/pseudo/pseudo https://pseudo-pdo.org +### Documentation Generation + +This project uses [readthedocs](https://readthedocs.io) and [mkdocs](https://mkdocs.org) + +To load the local documentation page setup mkdocs locally and run: +```shell +$ mkdocs serve +``` + +You can edit the `mkdocs.yaml` file to change the pages that show up in the sidebar. + +To generate the docs, setup [phpDocumentor](https://phpdoc.org/) locally and then run: + +```shell +$ phpdoc --directory=src --target=docs --template="vendor/saggre/phpdocumentor-markdown/themes/markdown" +``` + ## Installation ``` diff --git a/composer.json b/composer.json index 4c0040f..5621698 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,8 @@ "require-dev": { "phpunit/phpunit": "^9.6|^10.5|^11.3", "phpunit/php-code-coverage": "^9.2|^10.1|^11.0", - "phpstan/phpstan": "^1.12" + "phpstan/phpstan": "^1.12", + "saggre/phpdocumentor-markdown": "^0.1.4" }, "autoload": { "psr-4": { diff --git a/docs/Home.md b/docs/Home.md new file mode 100644 index 0000000..42ef351 --- /dev/null +++ b/docs/Home.md @@ -0,0 +1,44 @@ + +*** + +# phpDocumentor + + + +This is an automatically generated documentation for **phpDocumentor**. + + +## Namespaces + + +### \Pseudo + +#### Classes + +| Class | Description | +|-------|-------------| +| [`ParsedQuery`](./classes/Pseudo/ParsedQuery.md) | | +| [`Pdo`](./classes/Pseudo/Pdo.md) | | +| [`PdoStatement`](./classes/Pseudo/PdoStatement.md) | | +| [`QueryLog`](./classes/Pseudo/QueryLog.md) | | +| [`Result`](./classes/Pseudo/Result.md) | | +| [`ResultCollection`](./classes/Pseudo/ResultCollection.md) | | + + + + +### \Pseudo\Exceptions + +#### Classes + +| Class | Description | +|-------|-------------| +| [`LogicException`](./classes/Pseudo/Exceptions/LogicException.md) | | +| [`PseudoException`](./classes/Pseudo/Exceptions/PseudoException.md) | | +| [`PseudoPdoException`](./classes/Pseudo/Exceptions/PseudoPdoException.md) | | + + + + +*** +> Automatically generated on 2024-10-12 diff --git a/docs/classes/Pseudo/Exceptions/LogicException.md b/docs/classes/Pseudo/Exceptions/LogicException.md new file mode 100644 index 0000000..8eac05f --- /dev/null +++ b/docs/classes/Pseudo/Exceptions/LogicException.md @@ -0,0 +1,18 @@ +*** + +# LogicException + + + + + +* Full name: `\Pseudo\Exceptions\LogicException` +* Parent class: [`\Pseudo\Exceptions\PseudoException`](./PseudoException.md) + + + + + + +*** +> Automatically generated on 2024-10-12 diff --git a/docs/classes/Pseudo/Exceptions/PseudoException.md b/docs/classes/Pseudo/Exceptions/PseudoException.md new file mode 100644 index 0000000..45e7497 --- /dev/null +++ b/docs/classes/Pseudo/Exceptions/PseudoException.md @@ -0,0 +1,18 @@ +*** + +# PseudoException + + + + + +* Full name: `\Pseudo\Exceptions\PseudoException` +* Parent class: [`Exception`](../../Exception.md) + + + + + + +*** +> Automatically generated on 2024-10-12 diff --git a/docs/classes/Pseudo/Exceptions/PseudoPdoException.md b/docs/classes/Pseudo/Exceptions/PseudoPdoException.md new file mode 100644 index 0000000..c17aba3 --- /dev/null +++ b/docs/classes/Pseudo/Exceptions/PseudoPdoException.md @@ -0,0 +1,18 @@ +*** + +# PseudoPdoException + + + + + +* Full name: `\Pseudo\Exceptions\PseudoPdoException` +* Parent class: [`PDOException`](../../PDOException.md) + + + + + + +*** +> Automatically generated on 2024-10-12 diff --git a/docs/classes/Pseudo/ParsedQuery.md b/docs/classes/Pseudo/ParsedQuery.md new file mode 100644 index 0000000..4e3a578 --- /dev/null +++ b/docs/classes/Pseudo/ParsedQuery.md @@ -0,0 +1,147 @@ +*** + +# ParsedQuery + + + + + +* Full name: `\Pseudo\ParsedQuery` + + + +## Properties + + +### rawQuery + + + +```php +private string $rawQuery +``` + + + + + + +*** + +### hash + + + +```php +private string $hash +``` + + + + + + +*** + +## Methods + + +### __construct + + + +```php +public __construct(string $query): mixed +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$query` | **string** | | + + + + + +*** + +### isEqualTo + + + +```php +public isEqualTo(\Pseudo\ParsedQuery|string $query): bool +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$query` | **\Pseudo\ParsedQuery|string** | | + + + + + +*** + +### getHash + + + +```php +public getHash(): string +``` + + + + + + + + + + + + +*** + +### getRawQuery + + + +```php +public getRawQuery(): string +``` + + + + + + + + + + + + +*** + + +*** +> Automatically generated on 2024-10-12 diff --git a/docs/classes/Pseudo/Pdo.md b/docs/classes/Pseudo/Pdo.md new file mode 100644 index 0000000..7cee80e --- /dev/null +++ b/docs/classes/Pseudo/Pdo.md @@ -0,0 +1,443 @@ +*** + +# Pdo + + + + + +* Full name: `\Pseudo\Pdo` +* Parent class: [`PDO`](../PDO.md) + + + +## Properties + + +### mockedQueries + + + +```php +private \Pseudo\ResultCollection $mockedQueries +``` + + + + + + +*** + +### inTransaction + + + +```php +private bool $inTransaction +``` + + + + + + +*** + +### queryLog + + + +```php +private \Pseudo\QueryLog $queryLog +``` + + + + + + +*** + +## Methods + + +### __construct + + + +```php +public __construct(\Pseudo\ResultCollection|null $collection = null): mixed +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$collection` | **\Pseudo\ResultCollection|null** | | + + + + + +*** + +### prepare + + + +```php +public prepare(string $query, array<int|string,mixed> $options = []): \Pseudo\PdoStatement +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$query` | **string** | | +| `$options` | **array** | | + + + + +**Throws:** + +- [`PseudoException`](./Exceptions/PseudoException.md) + +- [`Throwable`](../Throwable.md) + + + +*** + +### beginTransaction + + + +```php +public beginTransaction(): bool +``` + + + + + + + + + + + + +*** + +### commit + + + +```php +public commit(): bool +``` + + + + + + + + + + + + +*** + +### rollBack + + + +```php +public rollBack(): bool +``` + + + + + + + + + + + + +*** + +### inTransaction + + + +```php +public inTransaction(): bool +``` + + + + + + + + + + + + +*** + +### exec + + + +```php +public exec(mixed $statement): false|int +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$statement` | **mixed** | | + + + + + +*** + +### query + + + +```php +public query(string $query, int|null $fetchMode = null, mixed $fetchModeArgs): \Pseudo\PdoStatement +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$query` | **string** | | +| `$fetchMode` | **int|null** | | +| `$fetchModeArgs` | **mixed** | | + + + + +**Throws:** + +- [`\Pseudo\Exceptions\PseudoException|\Throwable`](./Exceptions/PseudoException|/Throwable.md) + + + +*** + +### lastInsertId + + + +```php +public lastInsertId(string|null $name = null): string|false +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$name` | **string|null** | | + + + + +**Throws:** + +- [`PseudoException`](./Exceptions/PseudoException.md) + +- [`Throwable`](../Throwable.md) + + + +*** + +### getLastResult + + + +```php +private getLastResult(): \Pseudo\Result|bool +``` + + + + + + + + + + + +**Throws:** + +- [`\Pseudo\Exceptions\PseudoException|\Throwable`](./Exceptions/PseudoException|/Throwable.md) + + + +*** + +### save + + + +```php +public save(string $filePath): void +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$filePath` | **string** | | + + + + + +*** + +### load + + + +```php +public load(string $filePath): void +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$filePath` | **string** | | + + + + +**Throws:** + +- [`PseudoException`](./Exceptions/PseudoException.md) + + + +*** + +### mock + + + +```php +public mock(string $sql, array<int|string,mixed>|null $params = null, mixed $expectedResults = null): void +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$sql` | **string** | | +| `$params` | **array|null** | | +| `$expectedResults` | **mixed** | | + + + + + +*** + +### getMockedQueries + + + +```php +public getMockedQueries(): \Pseudo\ResultCollection +``` + + + + + + + + + + + + +*** + + +*** +> Automatically generated on 2024-10-12 diff --git a/docs/classes/Pseudo/PdoStatement.md b/docs/classes/Pseudo/PdoStatement.md new file mode 100644 index 0000000..c8a9cf5 --- /dev/null +++ b/docs/classes/Pseudo/PdoStatement.md @@ -0,0 +1,606 @@ +*** + +# PdoStatement + + + + + +* Full name: `\Pseudo\PdoStatement` +* Parent class: [`PDOStatement`](../PDOStatement.md) + + + +## Properties + + +### result + + + +```php +private \Pseudo\Result $result +``` + + + + + + +*** + +### fetchMode + + + +```php +private int $fetchMode +``` + + + + + + +*** + +### boundParams + + + +```php +private array<int|string,mixed> $boundParams +``` + + + + + + +*** + +### boundColumns + + + +```php +private array<int|string,mixed> $boundColumns +``` + + + + + + +*** + +### queryLog + + + +```php +private \Pseudo\QueryLog $queryLog +``` + + + + + + +*** + +### statement + + + +```php +private string $statement +``` + + + + + + +*** + +## Methods + + +### __construct + + + +```php +public __construct(mixed $result = null, \Pseudo\QueryLog|null $queryLog = null, string $statement = ''): mixed +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$result` | **mixed** | | +| `$queryLog` | **\Pseudo\QueryLog|null** | | +| `$statement` | **string** | | + + + + + +*** + +### setResult + + + +```php +public setResult(\Pseudo\Result|bool $result): void +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$result` | **\Pseudo\Result|bool** | | + + + + + +*** + +### execute + + + +```php +public execute(array<int|string,mixed>|null $params = null): bool +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$params` | **array|null** | | + + + + +**Throws:** + +- [`LogicException`](./Exceptions/LogicException.md) + + + +*** + +### fetch + + + +```php +public fetch(mixed $mode = null, mixed $cursorOrientation = PDO::FETCH_ORI_NEXT, mixed $cursorOffset): mixed +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$mode` | **mixed** | | +| `$cursorOrientation` | **mixed** | | +| `$cursorOffset` | **mixed** | | + + + + + +*** + +### bindParam + + + +```php +public bindParam(mixed $param, mixed& $var, mixed $type = PDO::PARAM_STR, mixed $maxLength = null, mixed $driverOptions = null): bool +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$param` | **mixed** | | +| `$var` | **mixed** | | +| `$type` | **mixed** | | +| `$maxLength` | **mixed** | | +| `$driverOptions` | **mixed** | | + + + + + +*** + +### bindColumn + + + +```php +public bindColumn(mixed $column, mixed& $var, mixed $type = null, mixed $maxLength = null, mixed $driverOptions = null): bool +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$column` | **mixed** | | +| `$var` | **mixed** | | +| `$type` | **mixed** | | +| `$maxLength` | **mixed** | | +| `$driverOptions` | **mixed** | | + + + + + +*** + +### bindValue + + + +```php +public bindValue(mixed $param, mixed $value, mixed $type = PDO::PARAM_STR): bool +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$param` | **mixed** | | +| `$value` | **mixed** | | +| `$type` | **mixed** | | + + + + + +*** + +### rowCount + + + +```php +public rowCount(): int +``` + + + + + + + + + + + + +*** + +### fetchColumn + + + +```php +public fetchColumn(mixed $column): mixed +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$column` | **mixed** | | + + + + + +*** + +### fetchAll + + + +```php +public fetchAll(int $mode = PDO::FETCH_DEFAULT, mixed $args): array<int|string,mixed> +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$mode` | **int** | | +| `$args` | **mixed** | | + + + + +**Throws:** + +- [`PseudoException`](./Exceptions/PseudoException.md) + + + +*** + +### processFetchedRow + + + +```php +private processFetchedRow(array<int|string,mixed> $row, int|null $fetchMode): mixed +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$row` | **array** | | +| `$fetchMode` | **int|null** | | + + + + + +*** + +### fetchObject + + + +```php +public fetchObject(class-string|null $class = "stdClass", array<int|string,mixed> $constructorArgs = []): object|false +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$class` | **class-string|null** | | +| `$constructorArgs` | **array** | | + + + + +**Throws:** + +- [`ReflectionException`](../ReflectionException.md) + + + +*** + +### errorCode + + + +```php +public errorCode(): string|null +``` + + + + + + + + + + + + +*** + +### errorInfo + + + +```php +public errorInfo(): string[] +``` + + + + + + + + + + + + +*** + +### columnCount + + + +```php +public columnCount(): int +``` + + + + + + + + + + + +**Throws:** + +- [`PseudoException`](./Exceptions/PseudoException.md) + + + +*** + +### setFetchMode + + + +```php +public setFetchMode(int $mode, null $className = null, mixed $params): bool|int +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$mode` | **int** | | +| `$className` | **null** | | +| `$params` | **mixed** | | + + + + + +*** + +### getBoundParams + + + +```php +public getBoundParams(): array<int|string,mixed> +``` + + + + + + + + + + + + +*** + +### getIterator + + + +```php +public getIterator(): \Iterator +``` + + + + + + + + + + + +**Throws:** + +- [`PseudoException`](./Exceptions/PseudoException.md) + + + +*** + + +*** +> Automatically generated on 2024-10-12 diff --git a/docs/classes/Pseudo/QueryLog.md b/docs/classes/Pseudo/QueryLog.md new file mode 100644 index 0000000..9aa092d --- /dev/null +++ b/docs/classes/Pseudo/QueryLog.md @@ -0,0 +1,237 @@ +*** + +# QueryLog + + + + + +* Full name: `\Pseudo\QueryLog` +* This class implements: +[`\IteratorAggregate`](../IteratorAggregate.md), [`\ArrayAccess`](../ArrayAccess.md), [`\Countable`](../Countable.md) + + + +## Properties + + +### queries + + + +```php +private array<int|string,\Pseudo\ParsedQuery> $queries +``` + + + + + + +*** + +## Methods + + +### count + + + +```php +public count(): int +``` + + + + + + + + + + + + +*** + +### getIterator + + + +```php +public getIterator(): \Traversable +``` + + + + + + + + + + + + +*** + +### offsetExists + + + +```php +public offsetExists(mixed $offset): bool +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$offset` | **mixed** | | + + + + + +*** + +### offsetGet + + + +```php +public offsetGet(mixed $offset): \Pseudo\ParsedQuery +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$offset` | **mixed** | | + + + + + +*** + +### offsetSet + + + +```php +public offsetSet(mixed $offset, mixed $value): void +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$offset` | **mixed** | | +| `$value` | **mixed** | | + + + + + +*** + +### offsetUnset + + + +```php +public offsetUnset(mixed $offset): void +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$offset` | **mixed** | | + + + + + +*** + +### addQuery + + + +```php +public addQuery(string $sql): void +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$sql` | **string** | | + + + + + +*** + +### getQueries + + + +```php +public getQueries(): array<int|string,\Pseudo\ParsedQuery> +``` + + + + + + + + + + + + +*** + + +*** +> Automatically generated on 2024-10-12 diff --git a/docs/classes/Pseudo/Result.md b/docs/classes/Pseudo/Result.md new file mode 100644 index 0000000..00a3fd6 --- /dev/null +++ b/docs/classes/Pseudo/Result.md @@ -0,0 +1,709 @@ +*** + +# Result + + + + + +* Full name: `\Pseudo\Result` + + + +## Properties + + +### rows + + + +```php +private array<int|string,array<int|string,mixed>> $rows +``` + + + + + + +*** + +### executionResult + + + +```php +private ?bool $executionResult +``` + + + + + + +*** + +### isParameterized + + + +```php +private bool $isParameterized +``` + + + + + + +*** + +### errorCode + + + +```php +private string $errorCode +``` + + + + + + +*** + +### errorInfo + + + +```php +private string $errorInfo +``` + + + + + + +*** + +### affectedRowCount + + + +```php +private int $affectedRowCount +``` + + + + + + +*** + +### insertId + + + +```php +private int $insertId +``` + + + + + + +*** + +### rowOffset + + + +```php +private int $rowOffset +``` + + + + + + +*** + +### params + + + +```php +private array<int|string,mixed> $params +``` + + + + + + +*** + +## Methods + + +### __construct + + + +```php +public __construct(array<int|string,array<int|string,mixed>>|null $rows = null, array<int|string,mixed>|null $params = null, bool|null $executionResult = null): mixed +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$rows` | **array>|null** | | +| `$params` | **array|null** | | +| `$executionResult` | **bool|null** | | + + + + + +*** + +### addRow + + + +```php +public addRow(array<int|string,mixed> $row, array<int|string,mixed> $params = null): void +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$row` | **array** | | +| `$params` | **array** | | + + + + +**Throws:** + +- [`PseudoException`](./Exceptions/PseudoException.md) + + + +*** + +### setParams + + + +```php +public setParams(array<int|string,mixed> $params, bool $parameterize = false): void +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$params` | **array** | | +| `$parameterize` | **bool** | | + + + + + +*** + +### getRows + + + +```php +public getRows(array<int|string,mixed> $params = []): mixed +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$params` | **array** | | + + + + +**Throws:** + +- [`PseudoException`](./Exceptions/PseudoException.md) + + + +*** + +### getRowIfExists + +Returns the next row if it exists, otherwise returns false + +```php +private getRowIfExists(array<int|string,mixed> $rows): false|array<int|string,mixed> +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$rows` | **array** | Rows to get row from | + + +**Return Value:** + +Next row (false if it doesn't exist) + + + + +*** + +### nextRow + +Returns the next available row if it exists, otherwise returns false + +```php +public nextRow(): false|array<int|string,mixed> +``` + + + + + + + + + + + + +*** + +### setInsertId + + + +```php +public setInsertId(int $insertId): void +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$insertId` | **int** | | + + + + + +*** + +### getInsertId + + + +```php +public getInsertId(): int +``` + + + + + + + + + + + + +*** + +### setErrorCode + + + +```php +public setErrorCode(string $errorCode): void +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$errorCode` | **string** | | + + + + +**Throws:** + +- [`PseudoException`](./Exceptions/PseudoException.md) + + + +*** + +### getErrorCode + + + +```php +public getErrorCode(): string +``` + + + + + + + + + + + + +*** + +### setErrorInfo + + + +```php +public setErrorInfo(string $errorInfo): void +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$errorInfo` | **string** | | + + + + + +*** + +### getErrorInfo + + + +```php +public getErrorInfo(): string +``` + + + + + + + + + + + + +*** + +### setAffectedRowCount + + + +```php +public setAffectedRowCount(int $affectedRowCount): void +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$affectedRowCount` | **int** | | + + + + + +*** + +### getAffectedRowCount + + + +```php +public getAffectedRowCount(): int +``` + + + + + + + + + + + + +*** + +### isOrdinalArray + + + +```php +public isOrdinalArray(array<int|string,mixed> $arr): bool +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$arr` | **array** | | + + + + + +*** + +### reset + + + +```php +public reset(): void +``` + + + + + + + + + + + + +*** + +### hasExecutionResult + + + +```php +public hasExecutionResult(): bool +``` + + + + + + + + + + + + +*** + +### getExecutionResult + + + +```php +public getExecutionResult(): bool +``` + + + + + + + + + + + +**Throws:** + +- [`LogicException`](./Exceptions/LogicException.md) + + + +*** + +### stringifyParameterSet + + + +```php +private stringifyParameterSet(array<int|string,mixed> $params): string +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$params` | **array** | | + + + + + +*** + +### initializeParameterizedRows + + + +```php +private initializeParameterizedRows(string $parameterKey, array<int|string,mixed> $row): void +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$parameterKey` | **string** | | +| `$row` | **array** | | + + + + + +*** + +### addNonParameterizedRow + + + +```php +private addNonParameterizedRow(array<int|string,mixed> $row): void +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$row` | **array** | | + + + + +**Throws:** + +- [`PseudoException`](./Exceptions/PseudoException.md) + + + +*** + + +*** +> Automatically generated on 2024-10-12 diff --git a/docs/classes/Pseudo/ResultCollection.md b/docs/classes/Pseudo/ResultCollection.md new file mode 100644 index 0000000..1fdc820 --- /dev/null +++ b/docs/classes/Pseudo/ResultCollection.md @@ -0,0 +1,149 @@ +*** + +# ResultCollection + + + + + +* Full name: `\Pseudo\ResultCollection` +* This class implements: +[`\Countable`](../Countable.md) + + + +## Properties + + +### queries + + + +```php +private array<string,mixed> $queries +``` + + + + + + +*** + +## Methods + + +### count + + + +```php +public count(): int +``` + + + + + + + + + + + + +*** + +### addQuery + + + +```php +public addQuery(string $sql, array<int|string,mixed>|null $params = null, mixed|null $results = null): void +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$sql` | **string** | | +| `$params` | **array|null** | | +| `$results` | **mixed|null** | | + + + + + +*** + +### exists + + + +```php +public exists(string $sql): bool +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$sql` | **string** | | + + + + + +*** + +### getResult + + + +```php +public getResult(string|\Pseudo\ParsedQuery $query): \Pseudo\Result|bool +``` + + + + + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$query` | **string|\Pseudo\ParsedQuery** | | + + + + +**Throws:** + +- [`PseudoException`](./Exceptions/PseudoException.md) + +- [`Throwable`](../Throwable.md) + + + +*** + + +*** +> Automatically generated on 2024-10-12 diff --git a/docs/index.md b/docs/index.md deleted file mode 100644 index 2fc0af4..0000000 --- a/docs/index.md +++ /dev/null @@ -1,134 +0,0 @@ -# Pseudo - -## Introduction - -Pseudo is a system for mocking PHP's PDO database connections. When writing unit tests for PHP applications, one -frequently has the need to test code that interacts with a database. However, in the true spirit of a unit test, the -database should be abstracted, as we can assume with some degree of certainty that things like network links to the -database server, the database connection drivers, and the database server and software itself are "going to work", and -they are outside the scope of our unit tests. - -Enter Pseudo. Pseudo allows you to have "fake" interactions with a database that produce predefined results every time. -This has 2 main advantages over actually interacting with a database. First, it saves having to write data fixtures in -another format, ensuring the data schema availability, loading the fixtures in, and then later cleaing and resetting -them between tests. Second, and somewhat as a result of the first, tests can run *significantly* faster because they are -essentially talking to an in-memory object structure rather than incurring all the overhead of connecting and -interacting with an actual database. - -The general idea is that Pseudo implements all the classes in the PDO system by inheriting from them and then -overriding their methods. During your test, at the point where you would inject a PDO object into your data layer, you -can now inject a Pseudo\Pdo object transparently, giving yourself 100% flexibility to control what your application now -*thinks* is the database. In your unit test, you can express the mocks for your test in terms of SQL statements and -arrays of result data. - -Find the package on [packagist.org](https://packagist.org/packages/pseudo/pseudo) - -## Installation - -``` -composer require --dev pseudo/pseudo -``` - -### Usage - -#### Something you may want to test - -```php -pdo->prepare('SELECT id FROM objects WHERE foo = :foo'); - - $statement->execute(['foo' => 'bar']); - - $objects = $statement->fetchAll(); - - if (!$objects) { - throw new RuntimeException('Entity not found'); - } - - return $objects; - } -} -``` - -#### Tests with Pseudo - -```php -mock( - "SELECT id FROM objects WHERE foo = :foo'", - ['foo' => 'bar'], - [['id' => 1, 'foo' => 'bar']] - ); - - $objects = $objectsModel->getObjectsByFoo('bar'); - - $this->assertEquals([['id' => 1, 'foo' => 'bar']], $objects); - } -} -``` - -### Supported features - -The internal storage of mocks and results are associatve arrays. Pseudo attempts to implement as much of the standard -PDO feature set as possible, so varies different fetch modes, bindings, parameterized queries, etc all work as you'd -expect them to. - -### Not implemented / wish-list items - -* The transaction api is implemented to the point of managing current transaction state, but transactions have no actual - effect -* Anything related to scrolling cursors has not been implemented, and this includes the fetch modes that might require - them -* Pseudo can load and save serialized copies of it's mocked data, but in the future, it will be able to "record" a live - PDO connection to a real database and then use that data to create mocks from your actual data -* Pseudo isn't strict-mode compatible, which means tests might fail due to unexpected errors with signatures and - offsets, etc. (I'd happily accept a pull request to fix this!) - -## Tests - -Pseudo has a fairly robust test suite written with PHPUnit. If you'd like to run the tests, simply run -`./vendor/bin/phpunit` in the root folder. The tests have no external library dependencies (other than phpunit) and -should require no additional setup or bootstrapping to run. - -## Requirements - -Pseudo internals currently target PHP 8.0 and above. It has no external dependencies aside from the PDO extension, -which seems rather obvious. - -Pseudo is built and tested with error reporting set to ```E_ALL & ~(E_NOTICE | E_DEPRECATED | E_STRICT)```. If you are -running in a stricter error reporting mode, your tests will most likely fail due to strict mode method signature -violations. (This is on the known issues / to do list) - -## Contributing - -We are committed to a transparent development process and highly appreciate any contributions. Whether you are helping -us fix bugs, proposing new features, improving our documentation or spreading the word - we would love to have you as a -part of the community. Please refer to our contribution guidelines and code of conduct. - -- Bug Report: If you see an error message or encounter an issue while using Pseudo, please create a bug report. - -- Feature Request: If you have an idea or if there is a capability that is missing and would make development easier and - more robust, please submit a feature request. - -- Documentation Request: If you're reading the Pseudo docs and feel like you're missing something, please submit a - documentation request. - -## License - -The Pseudo is open-sourced software licensed under the MIT license. diff --git a/docs/pdo.md b/docs/pdo.md deleted file mode 100644 index 91dd895..0000000 --- a/docs/pdo.md +++ /dev/null @@ -1,233 +0,0 @@ -# `Pseudo/Pdo` Class Documentation - -The `Pdo` class extends the built-in `\PDO` class and is part of the `Pseudo` namespace. It is designed to allow for -mock query handling and provides additional functionality to manage transactions, query logging, and result mocking. - -## Namespace - -```php -namespace Pseudo; -``` - -## Dependencies - -- `InvalidArgumentException` -- `Pseudo\Exceptions\PseudoException` -- `Throwable` - -## Properties - -- `private ResultCollection $mockedQueries`: A collection of mocked query results. -- `private bool $inTransaction`: Tracks the transaction state. -- `private QueryLog $queryLog`: A log of executed queries. - -## Constructor - -#### `__construct(ResultCollection $collection = null)` - -Initializes the `Pdo` instance. - -- **Parameters:** - - `ResultCollection|null $collection`: An optional collection of mocked queries. If not provided, a new - `ResultCollection` is created. - -- **Example:** - ```php - $pdo = new Pdo($resultCollection); - ``` - -## Methods - -### prepare - -#### `prepare($query, $options = null): PdoStatement` - -Prepares a mock query and returns a `PdoStatement`. - -- **Parameters:** - - `$query`: The SQL query string. - - `$options`: Optional parameters. - -- **Returns:** `PdoStatement` -- **Throws:** `PseudoException`, `Throwable` - -- **Example:** - ```php - $stmt = $pdo->prepare("SELECT * FROM users"); - ``` - -### beginTransaction - -#### `beginTransaction(): bool` - -Starts a new transaction. - -- **Returns:** `bool` (`true` if a transaction is started, `false` if already in a transaction) - -- **Example:** - ```php - $pdo->beginTransaction(); - ``` - -### commit - -#### `commit(): bool` - -Commits the current transaction. - -- **Returns:** `bool` (`true` if the transaction is successfully committed, `false` if no active transaction) - -- **Example:** - ```php - $pdo->commit(); - ``` - -### rollback - -#### `rollBack(): bool` - -Rolls back the current transaction. - -- **Returns:** `bool` (`true` if the transaction is successfully rolled back, `false` if no active transaction) - -- **Example:** - ```php - $pdo->rollBack(); - ``` - -### inTransaction - -#### `inTransaction(): bool` - -Checks if there is an active transaction. - -- **Returns:** `bool` (`true` if in a transaction, `false` otherwise) - -- **Example:** - ```php - if ($pdo->inTransaction()) { - // Do something - } - ``` - -### exec - -#### `exec($statement): false|int` - -Executes an SQL statement and returns the number of affected rows. - -- **Parameters:** - - `$statement`: The SQL query string. - -- **Returns:** `int` (number of affected rows), `false` on failure - -- **Example:** - ```php - $affectedRows = $pdo->exec("DELETE FROM users WHERE id = 1"); - ``` - -### query - -#### `query(string $query, ?int $fetchMode = null, mixed ...$fetchModeArgs): PdoStatement` - -Executes an SQL query and returns a `PdoStatement`. - -- **Parameters:** - - `string $query`: The SQL query string. - - `?int $fetchMode`: Optional fetch mode. - - `mixed ...$fetchModeArgs`: Optional arguments for fetch mode. - -- **Returns:** `PdoStatement` -- **Throws:** `PseudoException`, `Throwable` - -- **Example:** - ```php - $stmt = $pdo->query("SELECT * FROM users"); - ``` - -### lastInsertId - -#### `lastInsertId($name = null): false|string` - -Returns the ID of the last inserted row, or `false` if no such ID exists. - -- **Parameters:** - - `$name`: Optional name of the sequence object. - -- **Returns:** `string` (the ID of the last inserted row), `false` on failure - -- **Example:** - ```php - $id = $pdo->lastInsertId(); - ``` - -### save - -#### `save(string $filePath): void` - -Saves the current mocked query collection to a file. - -- **Parameters:** - - `string $filePath`: The path to the file. - -- **Example:** - ```php - $pdo->save('queries.txt'); - ``` - -### load - -#### `load($filePath): void` - -Loads a mocked query collection from a file. - -- **Parameters:** - - `$filePath`: The path to the file. - -- **Example:** - ```php - $pdo->load('queries.txt'); - ``` - -### mock - -#### `mock(string $sql, ?array $params = null, mixed $expectedResults = null): void` - -Mocks a query and its expected result. - -- **Parameters:** - - `string $sql`: The SQL query string. - - `?array $params`: Optional query parameters. - - `mixed $expectedResults`: The expected result of the query. - -- **Example:** - ```php - $pdo->mock("SELECT * FROM users", null, $expectedResults); - ``` - -### getMockedQueries - -#### `getMockedQueries(): ResultCollection` - -Returns the current mocked queries collection. - -- **Returns:** `ResultCollection` - -- **Example:** - ```php - $mockedQueries = $pdo->getMockedQueries(); - ``` - -## Exceptions - -- **`PseudoException`:** Thrown when there is an issue with query handling or execution. - -## Usage Example - -```php -$pdo = new Pdo(); -$pdo->mock("SELECT * FROM users", null, [['id' => 1, 'name' => 'John Doe']]); - -$stmt = $pdo->query("SELECT * FROM users"); -$results = $stmt->fetchAll(); -``` diff --git a/mkdocs.yaml b/mkdocs.yaml index 477588e..bdfe76f 100644 --- a/mkdocs.yaml +++ b/mkdocs.yaml @@ -1,5 +1,8 @@ site_name: pseudo/pseudo nav: - - Home: index.md - - Pseudo\Pdo: pdo.md + - Home: Home.md + - Pseudo\Pdo: classes/Pseudo/Pdo.md + - Pseudo\PdoStatement: classes/Pseudo/PdoStatement.md + - Pseudo\Result: classes/Pseudo/Result.md + - Pseudo\ParsedQuery: classes/Pseudo/ParsedQuery.md theme: readthedocs diff --git a/phpdoc.dist.xml b/phpdoc.dist.xml new file mode 100644 index 0000000..c29939a --- /dev/null +++ b/phpdoc.dist.xml @@ -0,0 +1,10 @@ + + + phpDocumentor + + docs/.build + + diff --git a/src/QueryLog.php b/src/QueryLog.php index 4146dc7..ae59944 100644 --- a/src/QueryLog.php +++ b/src/QueryLog.php @@ -30,7 +30,7 @@ public function getIterator(): Traversable return new ArrayIterator($this->queries); } - public function offsetExists($offset): bool + public function offsetExists(mixed $offset): bool { return isset($this->queries[$offset]); }