Skip to content

Commit

Permalink
added failling PdoStatementObjectType test
Browse files Browse the repository at this point in the history
  • Loading branch information
clxmstaab committed Mar 3, 2022
1 parent 6fb6b07 commit 27e8097
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/default/data/pdo-stmt-obj-type.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace PdoStmtObjectTypeTest;

use PDO;
use PDOStatement;
use function PHPStan\Testing\assertType;
use staabm\PHPStanDba\Tests\Fixture\MyRowClass;

class Foo
{
/**
* @return PDOStatement<array{email: string, 0: string, adaid: int<0, 4294967295>, 1: int<0, 4294967295>}>
*/
private function prepare(PDO $pdo): PDOStatement {
return $pdo->prepare('SELECT email, adaid FROM ada');
}

public function fetch(PDO $pdo)
{
$stmt = $this->prepare($pdo);
$stmt->execute();

assertType('PDOStatement<array{email: string, 0: string, adaid: int<0, 4294967295>, 1: int<0, 4294967295>}>', $stmt);

$all = $stmt->fetch(PDO::FETCH_NUM);
assertType('array{string, int<0, 4294967295>}|false', $all);

$all = $stmt->fetch(PDO::FETCH_ASSOC);
assertType('array{email: string, adaid: int<0, 4294967295>}|false', $all);

$all = $stmt->fetch(PDO::FETCH_COLUMN);
assertType('string|false', $all);
}
}

0 comments on commit 27e8097

Please sign in to comment.