|
6 | 6 | use PHPStan\Analyser\ScopeFactory; |
7 | 7 | use PHPStan\Analyser\ValueDependencyCollector; |
8 | 8 | use PHPStan\Testing\PHPStanTestCase; |
| 9 | +use function restore_error_handler; |
| 10 | +use function set_error_handler; |
9 | 11 |
|
10 | 12 | class OpenSslCipherMethodsProviderTest extends PHPStanTestCase |
11 | 13 | { |
@@ -44,6 +46,36 @@ public function testIsSupportedCipherMethodTracksTheCipher(): void |
44 | 46 | ], $dependencies['dependents']['/project/src/Analysed.php']['analysis']); |
45 | 47 | } |
46 | 48 |
|
| 49 | + /** |
| 50 | + * Reading the ciphers out of the runtime means probing each one, and on PHP 8.0-8.4 |
| 51 | + * openssl_get_cipher_methods() reports algorithms openssl_cipher_iv_length() rejects with a |
| 52 | + * warning (php/php-src#19994) - 40 of 248 on PHP 8.4.23. `@` does not settle that: a user error |
| 53 | + * handler that does not consult error_reporting() is still called for a suppressed diagnostic. |
| 54 | + * See phpstan/phpstan#15176. |
| 55 | + * |
| 56 | + * Vacuous on a PHP where nothing is rejected, which is why the count is not asserted - only that |
| 57 | + * whatever the probe does stays inside it. |
| 58 | + */ |
| 59 | + public function testProbingTheRuntimeLeaksNoWarningThroughAnUnsuppressedHandler(): void |
| 60 | + { |
| 61 | + $leaked = []; |
| 62 | + set_error_handler(static function (int $errno, string $errstr) use (&$leaked): bool { |
| 63 | + // deliberately does not check error_reporting(), so the @ operator does not hide anything |
| 64 | + $leaked[] = $errstr; |
| 65 | + |
| 66 | + return true; |
| 67 | + }); |
| 68 | + |
| 69 | + try { |
| 70 | + $value = (new OpenSslCipherMethodsProvider())->getValue('aes-128-cbc'); |
| 71 | + } finally { |
| 72 | + restore_error_handler(); |
| 73 | + } |
| 74 | + |
| 75 | + $this->assertSame([], $leaked, 'Probing the runtime for supported ciphers must not emit warnings.'); |
| 76 | + $this->assertContains($value, ['supported', 'unsupported']); |
| 77 | + } |
| 78 | + |
47 | 79 | /** |
48 | 80 | * @param list<string> $supportedCipherMethods |
49 | 81 | */ |
|
0 commit comments