client = $client; } protected function tcpStreamInitializer(ParametersInterface $parameters) { return $this->client; } }; $this->expectException(StreamInitException::class); $this->expectExceptionMessage('Error while switching to encrypted communication [tls:'); // Mimics Laravel: warnings become exceptions unless silenced with @. // Restored in finally, before PHPUnit loads classes that may emit deprecations. set_error_handler(static function ($level, $message, $file = '', $line = 0) { if (error_reporting() & $level) { throw new ErrorException($message, 0, $level, $file, $line); } return false; }); $errorReporting = error_reporting(E_ALL); try { $factory->createStream(new Parameters(['scheme' => 'tls'])); } finally { error_reporting($errorReporting); restore_error_handler(); fclose($server); } } }