Skip to content

Commit

Permalink
Merge pull request #204 from productsupcom/5.x
Browse files Browse the repository at this point in the history
5.x - fix broken return types
  • Loading branch information
harikt authored Feb 17, 2022
2 parents 27f1909 + c180876 commit 17215ae
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 18 deletions.
22 changes: 22 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# @see https://git-scm.com/docs/gitattributes
# when you composer-require this library with --prefer-dist the tests will not be part of the installed vendor code
# making your final package smaller in size and therefore faster to build and deploy

# git files
.github/ export-ignore
.gitattributes export-ignore
.gitignore export-ignore

# testing and other
tests/ export-ignore
phpunit.xml.dist export-ignore
phpunit.php export-ignore
composer.lock export-ignore
.scrutinizer.yml export-ignore

# code style
.editorconfig export-ignore

# license
LICENSE export-ignore
CONTRIBUTING.md export-ignore
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Alternatively, [download a release][], or clone this repository, then map the

## Dependencies

This package requires PHP 8.1 or later; it has been tested on PHP 8.1.
This package requires PHP 8.1 or later; it has also been tested on PHP 8.1.
We recommend using the latest available version of PHP as a matter of
principle.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"require-dev": {
"pds/skeleton": "~1.0",
"phpunit/phpunit": "~5.7|~9.5"
"phpunit/phpunit": "^9.5"
},
"autoload-dev": {
"psr-4": {
Expand Down
20 changes: 10 additions & 10 deletions src/AbstractExtendedPdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ public function errorInfo(): array
*
* @param string $statement The SQL statement to prepare and execute.
*
* @return int The number of affected rows.
* @return int|false The number of affected rows.
*
* @see http://php.net/manual/en/pdo.exec.php
*
*/
public function exec(string $statement): int
public function exec(string $statement): int|false
{
$this->connect();
$this->profiler->start(__FUNCTION__);
Expand Down Expand Up @@ -344,7 +344,7 @@ public function fetchObject(
array $values = [],
string $class = 'stdClass',
array $args = []
): object {
): object|false {
$sth = $this->perform($statement, $values);

if (! empty($args)) {
Expand Down Expand Up @@ -567,12 +567,12 @@ public function perform(string $statement, array $values = []): PDOStatement
* @param array $options Set these attributes on the returned
* PDOStatement.
*
* @return PDOStatement
* @return PDOStatement|false
*
* @see http://php.net/manual/en/pdo.prepare.php
*
*/
public function prepare(string $query, array $options = []): PDOStatement
public function prepare(string $query, array $options = []): PDOStatement|false
{
$this->connect();
$sth = $this->pdo->prepare($query, $options);
Expand Down Expand Up @@ -638,12 +638,12 @@ public function prepareWithValues(string $statement, array $values = []): PDOSta
*
* @param mixed ...$fetch_mode_args Optional fetch-related parameters.
*
* @return PDOStatement
* @return PDOStatement|false
*
* @see http://php.net/manual/en/pdo.query.php
*
*/
public function query(string $query, ?int $fetchMode = null, mixed ...$fetch_mode_args): PDOStatement
public function query(string $query, ?int $fetchMode = null, mixed ...$fetch_mode_args): PDOStatement|false
{
$this->connect();
$this->profiler->start(__FUNCTION__);
Expand All @@ -663,12 +663,12 @@ public function query(string $query, ?int $fetchMode = null, mixed ...$fetch_mod
*
* @param int $type A data type hint for the database driver.
*
* @return string The quoted value.
* @return string|false The quoted value or false if the driver does not support quoting in this way.
*
* @see http://php.net/manual/en/pdo.quote.php
*
*/
public function quote(string|int|array|float|null $value, int $type = self::PARAM_STR): string
public function quote(string|int|array|float|null $value, int $type = self::PARAM_STR): string|false
{
$this->connect();

Expand Down Expand Up @@ -697,7 +697,7 @@ public function quote(string|int|array|float|null $value, int $type = self::PARA
*/
public function quoteName(string $name): string
{
if (strpos($name, '.') === false) {
if (!str_contains($name, '.')) {
return $this->quoteSingleName($name);
}

Expand Down
4 changes: 2 additions & 2 deletions src/ExtendedPdoInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,15 @@ public function fetchGroup(
*
* @param array $args Arguments to pass to the object constructor.
*
* @return object
* @return object|false
*
*/
public function fetchObject(
string $statement,
array $values = [],
string $class = 'stdClass',
array $args = []
): object;
): object|false;

/**
*
Expand Down
11 changes: 7 additions & 4 deletions tests/ExtendedPdoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,6 @@ public function testFetchObject()
$stm = "SELECT id, name FROM pdotest WHERE id = ?";
$actual = $this->pdo->fetchObject($stm, [1]);

// in php <= 8 id is a string, in php >= 8.1 it is a int
// https://github.com/php/php-src/blob/PHP-8.1/UPGRADING#L131
$this->assertSame(1, $actual->id);
$this->assertSame('Anna', $actual->name);
}
Expand All @@ -313,8 +311,7 @@ public function testFetchObject_withCtorArgs()
'Aura\Sql\FakeObject',
['bar']
);
// in php <= 8 id is a string, in php >= 8.1 it is a int
// https://github.com/php/php-src/blob/PHP-8.1/UPGRADING#L131

$this->assertSame(1, $actual->id);
$this->assertSame('Anna', $actual->name);
$this->assertSame('bar', $actual->foo);
Expand All @@ -334,6 +331,12 @@ public function testFetchObjects()
$this->assertEquals($expect, $actual);
}

public function testFetchObjectWithNoResult()
{
$stm = "SELECT * FROM pdotest where 0";
$this->assertFalse($this->pdo->fetchObject($stm));
}

public function testYieldObjects()
{
$stm = "SELECT * FROM pdotest";
Expand Down

0 comments on commit 17215ae

Please sign in to comment.