From 3b4be4c2245eafbc801a251ad5cf84ecfd898834 Mon Sep 17 00:00:00 2001 From: heap-s Date: Tue, 3 Sep 2024 05:16:56 -0700 Subject: [PATCH] fix: changes to SensitiveParameter test --- tests/Db/Driver/PDO/PDODriverTest.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/Db/Driver/PDO/PDODriverTest.php b/tests/Db/Driver/PDO/PDODriverTest.php index 5eceecc3a..bf489a7d9 100644 --- a/tests/Db/Driver/PDO/PDODriverTest.php +++ b/tests/Db/Driver/PDO/PDODriverTest.php @@ -65,14 +65,20 @@ public function testGetUsername(): void public function testSensitiveParameter(): void { + if (PHP_VERSION_ID < 80200) { + $this->markTestSkipped('SensitiveParameterValue is not available in PHP < 8.2'); + } + $dsn = 'sqlite::memory:'; try { - $fn = static function(#[\SensitiveParameter] string $password): void { - }; - $fn(null); - } catch (\Throwable $e) { - $trace = $e->getTrace()[0]; - $valid = isset($trace['args']) && $trace['args'][0] instanceof \SensitiveParameterValue; - var_dump($valid); + new PDODriver($dsn, password: null); + } catch (\TypeError $e) { + $this->assertTrue($e->getTrace()[0]['args'][2] instanceof \SensitiveParameterValue); } + $pdoDriver = new PDODriver($dsn); + try { + $pdoDriver->password(null); + } catch (\TypeError $e) { + $this->assertTrue($e->getTrace()[0]['args'][0] instanceof \SensitiveParameterValue); + } } }