Skip to content

Commit 53e9eaa

Browse files
committed
fix tests for PHPStan 2.0
1 parent 723dfa3 commit 53e9eaa

File tree

3 files changed

+10
-25
lines changed

3 files changed

+10
-25
lines changed

tests/PHPStan/Rules/MySQLi/data/MySQLiRuleInvalidDataTest.php

+4-9
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function testDynamicSql(): void
139139
$stmt->execute();
140140
$stmt->get_result();
141141

142-
$stmt = $this->hideValueFromPhpstan(true)
142+
$stmt = $this->hideValueFromPhpstan('1')
143143
? $db->prepare('SELECT 1')
144144
: $db->prepare('SELECT 2, 3');
145145
$stmt->execute();
@@ -148,14 +148,14 @@ public function testDynamicSql(): void
148148
try {
149149
$db->query(
150150
'SELECT * FROM missing_table '
151-
. ($this->hideValueFromPhpstan(true) ? 'WHERE 1' : ' WHERE 2'),
151+
. ($this->hideValueFromPhpstan('1') ? 'WHERE 1' : ' WHERE 2'),
152152
);
153153
$this->fail('Exception expected');
154154
} catch (mysqli_sql_exception $e) {
155155
$this->assertSame(MariaDbErrorCodes::ER_NO_SUCH_TABLE, $e->getCode());
156156
}
157157

158-
$condition = $this->hideValueFromPhpstan(true);
158+
$condition = $this->hideValueFromPhpstan('1');
159159
$stmt = $db->prepare($condition ? 'SELECT ?' : 'SELECT ?, ?');
160160

161161
try {
@@ -168,12 +168,7 @@ public function testDynamicSql(): void
168168
$this->assertTrue(true);
169169
}
170170

171-
/**
172-
* @template T
173-
* @param T $value
174-
* @return T
175-
*/
176-
private function hideValueFromPhpstan(mixed $value): mixed
171+
private function hideValueFromPhpstan(string $value): string
177172
{
178173
return $value;
179174
}

tests/PHPStan/Rules/MySQLi/data/MySQLiWrapperRuleInvalidDataTest.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,7 @@ public function testDynamicSql(): void
8585
$this->assertTrue(true);
8686
}
8787

88-
/**
89-
* @template T
90-
* @param T $value
91-
* @return T
92-
*/
93-
private function hideValueFromPhpstan(mixed $value): mixed
88+
private function hideValueFromPhpstan(string $value): string
9489
{
9590
return $value;
9691
}

tests/PHPStan/Type/MySQLi/data/MySQLiTypeInferenceDataTest.php

+5-10
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ public function testFetchObject(): void
856856

857857
do {
858858
$row = $result->fetch_object(
859-
$this->hideValueFromPhpstan(true)
859+
$this->hideValueFromPhpstan('1')
860860
? CustomUniversalObjectCrate::class
861861
: \stdClass::class,
862862
);
@@ -931,7 +931,7 @@ public function testFetchColumn(): void
931931
$result = $db->query('SELECT id, price FROM mysqli_test');
932932

933933
do {
934-
$dynamicColumn = $this->hideValueFromPhpstan(0);
934+
$dynamicColumn = (int) $this->hideValueFromPhpstan('0');
935935
$value = $result->fetch_column($dynamicColumn);
936936

937937
if (function_exists('assertType')) {
@@ -966,7 +966,7 @@ public function testDynamicSql(): void
966966

967967
$rows = $db->query(
968968
'SELECT * FROM mysqli_test'
969-
. ($this->hideValueFromPhpstan(true) ? ' WHERE 1' : ' WHERE 2'),
969+
. ($this->hideValueFromPhpstan('1') ? ' WHERE 1' : ' WHERE 2'),
970970
)->fetch_all(MYSQLI_ASSOC);
971971

972972
foreach ($rows as $row) {
@@ -991,7 +991,7 @@ public function testDynamicSql(): void
991991
}
992992

993993
$rows = $db->query(
994-
$this->hideValueFromPhpstan(true) ? 'SELECT 1 id' : 'SELECT "aa" aa, 2 count',
994+
$this->hideValueFromPhpstan('1') ? 'SELECT 1 id' : 'SELECT "aa" aa, 2 count',
995995
)->fetch_all(MYSQLI_ASSOC);
996996

997997
foreach ($rows as $row) {
@@ -1086,12 +1086,7 @@ private function assertGettype(string|array $allowedTypes, mixed $value): void
10861086
$this->assertTrue(in_array($type, $allowedTypes, true), $message);
10871087
}
10881088

1089-
/**
1090-
* @template T
1091-
* @param T $value
1092-
* @return T
1093-
*/
1094-
private function hideValueFromPhpstan(mixed $value): mixed
1089+
private function hideValueFromPhpstan(string $value): string
10951090
{
10961091
return $value;
10971092
}

0 commit comments

Comments
 (0)