Skip to content

Commit 20bd086

Browse files
Update test for phpstan 2.2 (#759)
1 parent 5e4d0b2 commit 20bd086

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

tests/Platform/QueryResultTypeWalkerFetchTypeMatrixTest.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@
5252
use PHPUnit\Framework\Constraint\IsIdentical;
5353
use Psr\Log\LoggerInterface;
5454
use Throwable;
55+
use function assert;
5556
use function class_exists;
5657
use function floor;
5758
use function getenv;
5859
use function in_array;
60+
use function is_string;
5961
use function method_exists;
6062
use function reset;
6163
use function sprintf;
@@ -65,6 +67,9 @@
6567
/**
6668
* This test ensures our query type inferring never differs from actual result types produced by PHP, Database drivers and Doctrine (with various versions and configurations).
6769
*
70+
* @phpstan-type Driver 'ibm_db2'|'mysqli'|'oci8'|'pdo_mysql'|'pdo_oci'|'pdo_pgsql'|'pdo_sqlite'|'pdo_sqlsrv'|'pgsql'|'sqlite3'|'sqlsrv'
71+
* @phpstan-import-type Params from DriverManager
72+
*
6873
* @group platform
6974
*/
7075
final class QueryResultTypeWalkerFetchTypeMatrixTest extends PHPStanTestCase
@@ -4433,6 +4438,7 @@ public static function provideCases(): iterable
44334438
}
44344439

44354440
/**
4441+
* @param Driver $driver
44364442
* @param mixed $expectedFirstResult
44374443
* @param array<string, mixed> $data
44384444
* @param self::STRINGIFY_* $stringification
@@ -4512,7 +4518,7 @@ private function performDriverTest(
45124518
}
45134519

45144520
/**
4515-
* @param array<string, mixed> $connectionParams
4521+
* @param Params $connectionParams
45164522
*/
45174523
private function createConnection(
45184524
array $connectionParams
@@ -4535,7 +4541,7 @@ private function createConnection(
45354541
$connection->executeQuery('USE foo');
45364542
}
45374543

4538-
if ($connectionParams['driver'] === 'pdo_mysql') {
4544+
if (isset($connectionParams['driver']) && $connectionParams['driver'] === 'pdo_mysql') {
45394545
$connection->executeQuery('SET GLOBAL max_connections = 1000');
45404546
}
45414547

@@ -4735,23 +4741,29 @@ private function assertInferredResultMatchesExpected(
47354741
}
47364742

47374743
/**
4738-
* @return array<string, mixed>
4744+
* @return Params
47394745
*/
47404746
private function getConnectionParamsForDriver(string $driver): array
47414747
{
47424748
switch ($driver) {
47434749
case 'pdo_mysql':
47444750
case 'mysqli':
4751+
$host = getenv('MYSQL_HOST');
4752+
assert(is_string($host));
4753+
47454754
return [
4746-
'host' => getenv('MYSQL_HOST'),
4755+
'host' => $host,
47474756
'user' => 'root',
47484757
'password' => 'secret',
47494758
'dbname' => 'foo',
47504759
];
47514760
case 'pdo_pgsql':
47524761
case 'pgsql':
4762+
$host = getenv('PGSQL_HOST');
4763+
assert(is_string($host));
4764+
47534765
return [
4754-
'host' => getenv('PGSQL_HOST'),
4766+
'host' => $host,
47554767
'user' => 'root',
47564768
'password' => 'secret',
47574769
'dbname' => 'foo',
@@ -4764,8 +4776,11 @@ private function getConnectionParamsForDriver(string $driver): array
47644776
];
47654777
case 'pdo_sqlsrv':
47664778
case 'sqlsrv':
4779+
$host = getenv('MSSQL_HOST');
4780+
assert(is_string($host));
4781+
47674782
return [
4768-
'host' => getenv('MSSQL_HOST'),
4783+
'host' => $host,
47694784
'user' => 'SA',
47704785
'password' => 'Secret.123',
47714786
// user database is created after connection

tests/Type/Doctrine/Query/QueryResultTypeWalkerHydrationModeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function test(Type $expectedType, string $dql, string $methodName, ?int $
114114
}
115115

116116
/**
117-
* @return iterable<string,array{Type,string,2?:string|null}>
117+
* @return iterable<string,array{Type,string,string,3?:int|null}>
118118
*/
119119
public static function getTestData(): iterable
120120
{

0 commit comments

Comments
 (0)