Skip to content

Commit

Permalink
fix tests for PHPStan 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
schlndh committed Sep 20, 2024
1 parent 723dfa3 commit 53e9eaa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 25 deletions.
13 changes: 4 additions & 9 deletions tests/PHPStan/Rules/MySQLi/data/MySQLiRuleInvalidDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function testDynamicSql(): void
$stmt->execute();
$stmt->get_result();

$stmt = $this->hideValueFromPhpstan(true)
$stmt = $this->hideValueFromPhpstan('1')
? $db->prepare('SELECT 1')
: $db->prepare('SELECT 2, 3');
$stmt->execute();
Expand All @@ -148,14 +148,14 @@ public function testDynamicSql(): void
try {
$db->query(
'SELECT * FROM missing_table '
. ($this->hideValueFromPhpstan(true) ? 'WHERE 1' : ' WHERE 2'),
. ($this->hideValueFromPhpstan('1') ? 'WHERE 1' : ' WHERE 2'),
);
$this->fail('Exception expected');
} catch (mysqli_sql_exception $e) {
$this->assertSame(MariaDbErrorCodes::ER_NO_SUCH_TABLE, $e->getCode());
}

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

try {
Expand All @@ -168,12 +168,7 @@ public function testDynamicSql(): void
$this->assertTrue(true);
}

/**
* @template T
* @param T $value
* @return T
*/
private function hideValueFromPhpstan(mixed $value): mixed
private function hideValueFromPhpstan(string $value): string
{
return $value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,7 @@ public function testDynamicSql(): void
$this->assertTrue(true);
}

/**
* @template T
* @param T $value
* @return T
*/
private function hideValueFromPhpstan(mixed $value): mixed
private function hideValueFromPhpstan(string $value): string
{
return $value;
}
Expand Down
15 changes: 5 additions & 10 deletions tests/PHPStan/Type/MySQLi/data/MySQLiTypeInferenceDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ public function testFetchObject(): void

do {
$row = $result->fetch_object(
$this->hideValueFromPhpstan(true)
$this->hideValueFromPhpstan('1')
? CustomUniversalObjectCrate::class
: \stdClass::class,
);
Expand Down Expand Up @@ -931,7 +931,7 @@ public function testFetchColumn(): void
$result = $db->query('SELECT id, price FROM mysqli_test');

do {
$dynamicColumn = $this->hideValueFromPhpstan(0);
$dynamicColumn = (int) $this->hideValueFromPhpstan('0');
$value = $result->fetch_column($dynamicColumn);

if (function_exists('assertType')) {
Expand Down Expand Up @@ -966,7 +966,7 @@ public function testDynamicSql(): void

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

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

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

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

/**
* @template T
* @param T $value
* @return T
*/
private function hideValueFromPhpstan(mixed $value): mixed
private function hideValueFromPhpstan(string $value): string
{
return $value;
}
Expand Down

0 comments on commit 53e9eaa

Please sign in to comment.