Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop php 8.0 support #12

Merged
merged 5 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ updates:
timezone: "Canada/Eastern"

#######################################
# Github Actions
# GitHub Actions
#######################################
- package-ecosystem: "github-actions"
directory: "/"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
php-versions: [ '8.0', '8.1', '8.2', '8.3', '8.4' ]
php-versions: [ '8.1', '8.2', '8.3', '8.4' ]

steps:
- uses: actions/checkout@v4
Expand All @@ -34,7 +34,7 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
php-versions: [ '8.0', '8.1', '8.2', '8.3', '8.4' ]
php-versions: [ '8.1', '8.2', '8.3', '8.4' ]

steps:
- uses: actions/checkout@v4
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ class ObjectsModelTest extends \PHPUnit\Framework\TestCase {

### 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
The internal storage of mocks and results are associative 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
Expand All @@ -127,7 +127,7 @@ 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,
Pseudo internals currently target PHP 8.1 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
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
}
],
"require": {
"php": ">=8.0",
"php": ">=8.1",
"ext-pdo": "*",
"ext-ctype": "*"
},
"require-dev": {
"phpunit/phpunit": "^9.6|^10.5|^11.3",
"phpunit/php-code-coverage": "^9.2|^10.1|^11.0",
"phpunit/phpunit": "^10.5|^11.3",
"phpunit/php-code-coverage": "^10.1|^11.0",
"phpstan/phpstan": "^2.0",
"saggre/phpdocumentor-markdown": "^0.1.4"
},
Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ class ObjectsModelTest extends \PHPUnit\Framework\TestCase {

### 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
The internal storage of mocks and results are associatove 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
Expand Down
4 changes: 3 additions & 1 deletion src/Exceptions/PseudoException.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php
namespace Pseudo\Exceptions;

class PseudoException extends \Exception
use Exception;

class PseudoException extends Exception
{

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

class PseudoPdoException extends \PDOException
use PDOException;

class PseudoPdoException extends PDOException
{

}
8 changes: 2 additions & 6 deletions src/Pdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@ class Pdo extends \PDO
private bool $inTransaction = false;
private QueryLog $queryLog;

/**
* @param ResultCollection|null $collection
*/
public function __construct(
ResultCollection $collection = null
) {
public function __construct(?ResultCollection $collection = null)
{
$this->mockedQueries = $collection ?? new ResultCollection();
$this->queryLog = new QueryLog();
}
Expand Down
16 changes: 8 additions & 8 deletions src/PdoStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class PdoStatement extends \PDOStatement
* @param QueryLog|null $queryLog
* @param string $statement
*/
public function __construct(mixed $result = null, QueryLog $queryLog = null, string $statement = '')
public function __construct(mixed $result = null, ?QueryLog $queryLog = null, string $statement = '')
{
if (!($result instanceof Result)) {
$result = new Result();
Expand Down Expand Up @@ -62,7 +62,7 @@ public function setResult(Result|bool $result): void
* @return bool
* @throws LogicException
*/
public function execute(array $params = null): bool
public function execute(?array $params = null): bool
{
$params = array_merge((array)$params, $this->boundParams);
$this->result->setParams($params, !empty($this->boundParams));
Expand Down Expand Up @@ -277,12 +277,12 @@ public function columnCount(): int

/**
* @param int $mode
* @param null $className
* @param mixed ...$params
* @param mixed ...$args
*
* @return bool|int
* @return true
* @throws PseudoException
*/
public function setFetchMode($mode, $className = null, ...$params): bool|int
public function setFetchMode($mode, ...$args): bool
{
$r = new ReflectionClass(new Pdo());
$constants = $r->getConstants();
Expand All @@ -298,10 +298,10 @@ public function setFetchMode($mode, $className = null, ...$params): bool|int
if (in_array($mode, $allowedConstantVals)) {
$this->fetchMode = $mode;

return 1;
return true;
}

return false;
throw new PseudoException("Invalid fetch mode");
}

/**
Expand Down
25 changes: 12 additions & 13 deletions tests/Unit/PdoClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ public function testBeginTransaction() : void
public function testTransactionStates()
{
$p = new Pdo();
$this->assertEquals($p->inTransaction(), false);
$this->assertFalse($p->inTransaction());

$this->assertEquals($p->beginTransaction(), true);
$this->assertEquals($p->inTransaction(), true);
$this->assertTrue($p->beginTransaction());
$this->assertTrue($p->inTransaction());

$this->assertEquals($p->commit(), true);
$this->assertEquals($p->inTransaction(), false);
$this->assertEquals($p->rollBack(), false);
$this->assertTrue($p->commit());
$this->assertFalse($p->inTransaction());
$this->assertFalse($p->rollBack());

$p->beginTransaction();
$this->assertEquals($p->beginTransaction(), false);
$this->assertEquals($p->inTransaction(), true);
$this->assertEquals($p->rollBack(), true);
$this->assertEquals($p->commit(), false);
$this->assertFalse($p->beginTransaction());
$this->assertTrue($p->inTransaction());
$this->assertTrue($p->rollBack());
$this->assertFalse($p->commit());
}

public function testMock()
Expand Down Expand Up @@ -79,7 +79,7 @@ public function testMock()
$p->mock($sql3, $params3, $result1);
$p->mock($sql3, $params4, $result2);

$this->assertEquals(3, count($p->getMockedQueries()));
$this->assertCount(3, $p->getMockedQueries());
}


Expand All @@ -95,7 +95,7 @@ public function testQueryReturnsMockedResults()
);
$p->mock("SELECT * FROM test WHERE foo='bar'", null, $expectedRows);
$result = $p->query("SELECT * FROM test WHERE foo='bar'");
$this->assertEquals($expectedRows->getRows(), $result->fetchAll(PDO::FETCH_ASSOC));
$this->assertEquals($expectedRows->getRows(), $result->fetchAll(\PDO::FETCH_ASSOC));
}

public function testMockQueryDoesNotExist() : void
Expand Down Expand Up @@ -200,7 +200,6 @@ public function testSave()
{
$r = new ResultCollection();
$r->addQuery("SELECT 1", null, [[1]]);
$serialized = serialize($r);
if (file_exists('testsave')) {
unlink('testsave');
}
Expand Down
36 changes: 19 additions & 17 deletions tests/Unit/PdoStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
namespace Pseudo\UnitTest;

use Iterator;
use PDO;
use PHPUnit\Framework\TestCase;
use Pseudo\Pdo;
use Pseudo\Exceptions\PseudoException;
use Pseudo\PdoStatement;
use Pseudo\QueryLog;
use Pseudo\Result;
Expand Down Expand Up @@ -41,7 +42,7 @@ public function testFetchAllWithFetchAssoc()
$r = new Result([$rows]);
$s = new PdoStatement();
$s->setResult($r);
$fetchResult = $s->fetchAll(Pdo::FETCH_ASSOC);
$fetchResult = $s->fetchAll(PDO::FETCH_ASSOC);
$this->assertEquals([$rows], $fetchResult);
}

Expand All @@ -60,7 +61,7 @@ public function testFetchAllWithFetchNum()
$r = new Result([$rows]);
$s = new PdoStatement();
$s->setResult($r);
$fetchResult = $s->fetchAll(Pdo::FETCH_NUM);
$fetchResult = $s->fetchAll(PDO::FETCH_NUM);
$this->assertEquals($expectedFetchResult, $fetchResult);
}

Expand All @@ -79,7 +80,7 @@ public function testFetchAllWithFetchObj()
$r = new Result([$rows]);
$s = new PdoStatement();
$s->setResult($r);
$fetchResult = $s->fetchAll(Pdo::FETCH_OBJ);
$fetchResult = $s->fetchAll(PDO::FETCH_OBJ);
$this->assertEquals($expectedFetchResult, $fetchResult);
}

Expand Down Expand Up @@ -163,10 +164,11 @@ public function testColumnCountWhenZeo(): void
public function testSetFetchMode()
{
$p = new PdoStatement();
$success = $p->setFetchMode(Pdo::FETCH_ASSOC);
$success = $p->setFetchMode(PDO::FETCH_ASSOC);
$this->assertEquals(1, $success);
$success = $p->setFetchMode(456);
$this->assertEquals(false, $success);

$this->expectException(PseudoException::class);
$p->setFetchMode(456);
}

public function testFetch()
Expand All @@ -184,12 +186,12 @@ public function testFetch()
$p = new PdoStatement($r);

$data = $p->fetch();
$this->assertEquals(false, $data);
$this->assertFalse($data);

$r->addRow($row1);
$r->addRow($row2);

$p->setFetchMode(Pdo::FETCH_ASSOC);
$p->setFetchMode(PDO::FETCH_ASSOC);
$this->assertEquals($row1, $p->fetch());
$this->assertEquals($row2, $p->fetch());
}
Expand All @@ -214,7 +216,7 @@ public function testFetchCol()
$r->addRow($row1);
$r->addRow($row2);

$p->setFetchMode(\Pdo::FETCH_COLUMN);
$p->setFetchMode(PDO::FETCH_COLUMN);
$this->assertEquals($col1, $p->fetch());
$this->assertEquals($col2, $p->fetch());
}
Expand All @@ -229,14 +231,14 @@ public function testFetchWithBoundColumns()
$r->addRow($row1);
$p = new PdoStatement($r);
$p->bindColumn(2, $test);
$p->fetch(Pdo::FETCH_BOUND);
$p->fetch(PDO::FETCH_BOUND);
$this->assertEquals('bar', $test);
unset($test);

$r->reset();
$p = new PdoStatement($r);
$p->bindColumn('foo', $test);
$p->fetch(Pdo::FETCH_BOUND);
$p->fetch(PDO::FETCH_BOUND);
$this->assertEquals('bar', $test);
}

Expand Down Expand Up @@ -281,15 +283,15 @@ public function testExecute()
$queryLog = new QueryLog();
$s = new PdoStatement($r, $queryLog, 'SELECT * FROM test');

$this->assertEquals(true, $s->execute($params1));
$this->assertEquals(false, $s->execute());
$this->assertTrue($s->execute($params1));
$this->assertFalse($s->execute());
}

public function testBindParam()
{
$param = 'foo';
$s = new PdoStatement();
$this->assertEquals(true, $s->bindParam(1, $param));
$this->assertTrue($s->bindParam(1, $param));
$param = 'bar';
$this->assertEquals([1 => 'bar'], $s->getBoundParams());
}
Expand All @@ -298,7 +300,7 @@ public function testBindValue()
{
$param = 'foo';
$s = new PdoStatement();
$this->assertEquals(true, $s->bindValue(1, $param));
$this->assertTrue($s->bindValue(1, $param));
$this->assertEquals([1 => 'foo'], $s->getBoundParams());
}

Expand All @@ -314,7 +316,7 @@ public function testFetchColumn()
$s = new PdoStatement($r);

$this->assertEquals('bar', $s->fetchColumn(1));
$this->assertEquals(false, $s->fetchColumn(0));
$this->assertFalse($s->fetchColumn());
}

public function testGetIterator(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/QueryLogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function testAddQuery()
$queryLog = new QueryLog();
$queryLog->addQuery($sql);
$queries = $queryLog->getQueries();
$this->assertEquals(1, count($queries));
$this->assertCount(1, $queries);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Consider standardizing count assertions across test files

The codebase shows mixed usage of count assertions:

  • assertEquals($count, $obj->count()) in ResultCollectionTest
  • assertCount() in ResultTest, QueryLogTest, and PdoClassTest

Consider updating the remaining count assertion in ResultCollectionTest.php to use assertCount for consistency with the rest of the codebase:

  • tests/Unit/ResultCollectionTest.php: Replace assertEquals(1, $results->count()) with assertCount(1, $results)
🔗 Analysis chain

LGTM! Improved assertion clarity

The change from assertEquals(1, count($queries)) to assertCount(1, $queries) is a good improvement as it:

  • Makes the assertion's intent clearer
  • Uses the more specific PHPUnit assertion method
  • Provides better failure messages

Let's check if there are similar patterns in other test files that could benefit from this improvement:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find similar assertEquals(n, count()) patterns in tests that could be replaced with assertCount
# Expected results: List of test files containing the pattern to help standardize assertions

rg -l 'assertEquals\s*\(\s*\d+\s*,\s*count\s*\(' tests/

Length of output: 57


Script:

#!/bin/bash
# Let's try a broader search for assertEquals with count, including variations
rg -U 'assertEquals.*count\(' tests/ -A 2

# Also search for assertCount usage to understand current practices
rg -U 'assertCount' tests/ -A 2

Length of output: 1011

$this->assertTrue($queries[0]->isEqualTo($sql));
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/ResultCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testAddQuery(): void
$results = new ResultCollection();
$results->addQuery("SELECT * FROM ?", ['table'], [['test']]);

$this->assertEquals($results->count(), 1);
$this->assertEquals(1, $results->count());
}

public function testGetResultBool(): void
Expand Down
3 changes: 1 addition & 2 deletions tests/Unit/ResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testNextRow()

$this->assertEquals($row1, $r->nextRow());
$this->assertEquals($row2, $r->nextRow());
$this->assertEquals(false, $r->nextRow());
$this->assertFalse($r->nextRow());
}

public function testAddRow()
Expand Down Expand Up @@ -97,7 +97,6 @@ public function testEmptyRowProvided(): void

public function testSetAffectedRowCount(): void
{
$query = "SELECT * FROM test";
$rows = [['id' => 1], ['id' => 2], ['id' => 3]];
$result = new Result($rows);
$result->setAffectedRowCount(count($rows));
Expand Down
Loading