Skip to content

Commit

Permalink
Refactoring for re-release of 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ActuallyConnor committed Sep 27, 2024
1 parent 06a4555 commit 17a2c21
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 73 deletions.
44 changes: 9 additions & 35 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,18 @@
# Change Log

## 2.0.1

### Changed

- `README.md` updates

## 2.0.0

### Changed

- Refactor method signature for `Pseudo\Pdo::mock()`
- Change `Pseudo\Pdo::mock(string $sql, $params = null, $expectedResults = null)`

## 1.0.3

### Fixed

- Repairing `composer.json`

### Chore

- Dropping dead code

## 1.0.2

### Chore

- Restructuring exceptions directory

## 1.0.1

### Fixed

- Add support for `Pseudo\PdoStatement::getIterator()`

## 1.0.0

### Changed

- Library forked from [jimbosjb/pseudo](https://github.com/jimbojsb/pseudo)
- Connor take ownership
- Update entire library to be compatible for PHP 8.x
- `README.md` updates
- Restructuring exceptions directory
- Add support for `Pseudo\PdoStatement::getIterator()`
- Dropping dead code
- Repairing `composer.json`
- Rename `PdoException` class to `PseudoPdoException`
- Rename `Exception` class to `PseudoException`
- Refactor method signature for `Pseudo\Pdo::mock()`
- Change `Pseudo\Pdo::mock(string $sql, $params = null, $expectedResults = null)`
7 changes: 0 additions & 7 deletions src/Exceptions/PdoException.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Pseudo\Exceptions;

class Exception extends \Exception
class PseudoException extends \Exception
{

}
7 changes: 7 additions & 0 deletions src/Exceptions/PseudoPdoException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
namespace Pseudo\Exceptions;

class PseudoPdoException extends \PDOException
{

}
12 changes: 6 additions & 6 deletions src/Pdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Pseudo;

use InvalidArgumentException;
use Pseudo\Exceptions\Exception;
use Pseudo\Exceptions\PseudoException;
use RuntimeException;

class Pdo extends \PDO
Expand All @@ -23,7 +23,7 @@ public function __construct(
}

/**
* @throws Exception
* @throws PseudoException
*/
public function prepare($query, $options = null) : PdoStatement
{
Expand Down Expand Up @@ -83,7 +83,7 @@ public function exec($statement) : false|int
* @param mixed ...$fetchModeArgs
*
* @return PdoStatement
* @throws Exception
* @throws PseudoException
*/
public function query(string $query, ?int $fetchMode = null, mixed ...$fetchModeArgs) : PdoStatement
{
Expand All @@ -97,14 +97,14 @@ public function query(string $query, ?int $fetchMode = null, mixed ...$fetchMode
return $statement;
}

throw new Exception('Unable to convert query to PdoStatement');
throw new PseudoException('Unable to convert query to PdoStatement');
}

/**
* @param null $name
*
* @return false|string
* @throws Exception
* @throws PseudoException
*/
public function lastInsertId($name = null) : false|string
{
Expand All @@ -119,7 +119,7 @@ public function lastInsertId($name = null) : false|string

/**
* @return Result|false
* @throws Exception
* @throws PseudoException
*/
private function getLastResult() : Result|false
{
Expand Down
6 changes: 3 additions & 3 deletions src/PdoStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use ArrayIterator;
use Iterator;
use Pseudo\Exceptions\Exception;
use Pseudo\Exceptions\PseudoException;
use ReflectionClass;
use ReflectionException;
use stdClass;
Expand Down Expand Up @@ -64,7 +64,7 @@ public function execute(array $params = null) : bool
$this->queryLog->addQuery($this->statement);

return $success;
} catch (Exception) {
} catch (PseudoException) {
return false;
}
}
Expand Down Expand Up @@ -216,7 +216,7 @@ public function errorInfo() : array

/**
* @return int
* @throws Exception
* @throws PseudoException
*/
public function columnCount() : int
{
Expand Down
16 changes: 8 additions & 8 deletions src/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Pseudo;

use Pseudo\Exceptions\Exception;
use Pseudo\Exceptions\PseudoException;

class Result
{
Expand All @@ -28,7 +28,7 @@ public function __construct($rows = null, $params = null)
}

/**
* @throws Exception
* @throws PseudoException
*/
public function addRow(array $row, $params = null) : void
{
Expand Down Expand Up @@ -71,12 +71,12 @@ public function getRows(array $params = [])
}
}

throw new Exception("Cannot get rows with parameters on a non-parameterized result");
throw new PseudoException("Cannot get rows with parameters on a non-parameterized result");
} else {
if (!$this->isParameterized && isset($this->rows)) {
return $this->rows;
}
throw new Exception("Cannot get rows without parameters on a parameterized result");
throw new PseudoException("Cannot get rows without parameters on a parameterized result");
}
}

Expand Down Expand Up @@ -134,14 +134,14 @@ public function getInsertId() : int
/**
* @param $errorCode
*
* @throws Exception
* @throws PseudoException
*/
public function setErrorCode($errorCode) : void
{
if (ctype_alnum($errorCode) && strlen($errorCode) == 5) {
$this->errorCode = $errorCode;
} else {
throw new Exception("Error codes must be in ANSI SQL standard format");
throw new PseudoException("Error codes must be in ANSI SQL standard format");
}
}

Expand Down Expand Up @@ -213,12 +213,12 @@ private function initializeParameterizedRows(string $parameterKey, array $row) :
}

/**
* @throws Exception
* @throws PseudoException
*/
private function addNonParameterizedRow(array $row) : void
{
if ($this->isParameterized) {
throw new Exception("Cannot mix parameterized and non-parameterized rowsets");
throw new PseudoException("Cannot mix parameterized and non-parameterized rowsets");
}

$this->rows[] = $row;
Expand Down
6 changes: 3 additions & 3 deletions src/ResultCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Pseudo;

use Countable;
use Pseudo\Exceptions\Exception;
use Pseudo\Exceptions\PseudoException;

class ResultCollection implements Countable
{
Expand Down Expand Up @@ -36,7 +36,7 @@ public function exists($sql): bool
}

/**
* @throws Exception
* @throws PseudoException
*/
public function getResult(string|ParsedQuery $query): Result
{
Expand All @@ -49,7 +49,7 @@ public function getResult(string|ParsedQuery $query): Result
} else {
$message = "Attempting an operation on an un-mocked query is not allowed, the raw query: "
. $query->getRawQuery();
throw new Exception($message);
throw new PseudoException($message);
}
}
}
6 changes: 3 additions & 3 deletions tests/Unit/PdoClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Pseudo\UnitTest;

use PHPUnit\Framework\TestCase;
use Pseudo\Exceptions\Exception;
use Pseudo\Exceptions\PseudoException;
use Pseudo\Pdo;
use Pseudo\PdoStatement;
use Pseudo\Result;
Expand Down Expand Up @@ -102,7 +102,7 @@ public function testMockQueryDoesNotExist() : void
{
$pdo = new Pdo();

$this->expectException(Exception::class);
$this->expectException(PseudoException::class);
$pdo->query('SELECT * FROM users');
}

Expand Down Expand Up @@ -212,7 +212,7 @@ public function testDebuggingRawQueries()
$p = new Pdo();
try {
$p->prepare('SELECT 123');
} catch (Exception $e) {
} catch (PseudoException $e) {
$message = $e->getMessage();
}
$this->assertMatchesRegularExpression('/SELECT 123/', $message);
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/ResultCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
namespace Pseudo\UnitTest;

use PHPUnit\Framework\TestCase;
use Pseudo\Exceptions\Exception;
use Pseudo\Exceptions\PseudoException;
use Pseudo\ResultCollection;

class ResultCollectionTest extends TestCase
{
public function testGetResultWithoutMocking()
{
$r = new ResultCollection();
$this->expectException(Exception::class);
$this->expectException(PseudoException::class);
$r->getResult("SELECT 1");
}

Expand All @@ -21,7 +21,7 @@ public function testDebuggingRawQueries()
$r = new ResultCollection();
try {
$r->getResult('SELECT 123');
} catch (Exception $e) {
} catch (PseudoException $e) {
$message = $e->getMessage();
}
$this->assertMatchesRegularExpression('/SELECT 123/', $message);
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/ResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Pseudo\UnitTest;

use PHPUnit\Framework\TestCase;
use Pseudo\Exceptions\Exception;
use Pseudo\Exceptions\PseudoException;
use Pseudo\Result;

class ResultTest extends TestCase
Expand All @@ -13,7 +13,7 @@ public function testSetErrorCode()
$r = new Result;
$r->setErrorCode("HY000");
$this->assertEquals("HY000", $r->getErrorCode());
$this->expectException(Exception::class);
$this->expectException(PseudoException::class);
$r->setErrorCode("121");
}

Expand Down Expand Up @@ -82,7 +82,7 @@ public function testSetParametersNotParameterized() : void
$result = new Result();
$result->setParams(['param']);

$this->expectException(Exception::class);
$this->expectException(PseudoException::class);
$result->getRows();
}

Expand Down Expand Up @@ -132,7 +132,7 @@ public function testFailToAddNonParameterizedRowToParameterizedResults() : void
$result = new Result();
$result->setParams(['param'], true);

$this->expectException(Exception::class);
$this->expectException(PseudoException::class);
$result->addRow([['id' => 1], ['id' => 2], ['id' => 3]]);
}
}

0 comments on commit 17a2c21

Please sign in to comment.