From fcbf3ce37ca8f90a3e36d524a3274ffc063a40e3 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 15:26:02 +0200 Subject: Adding upstream version 0.10.2+dfsg1. Signed-off-by: Daniel Baumann --- vendor/textalk/websocket/tests/mock/MockSocket.php | 79 ++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 vendor/textalk/websocket/tests/mock/MockSocket.php (limited to 'vendor/textalk/websocket/tests/mock/MockSocket.php') diff --git a/vendor/textalk/websocket/tests/mock/MockSocket.php b/vendor/textalk/websocket/tests/mock/MockSocket.php new file mode 100644 index 0000000..e12d6ed --- /dev/null +++ b/vendor/textalk/websocket/tests/mock/MockSocket.php @@ -0,0 +1,79 @@ +assertEquals($current['function'], $function); + foreach ($current['params'] as $index => $param) { + self::$asserter->assertEquals($param, $params[$index], json_encode([$current, $params])); + } + if (isset($current['error'])) { + $map = array_merge(['msg' => 'Error', 'type' => E_USER_NOTICE], (array)$current['error']); + trigger_error($map['msg'], $map['type']); + } + if (isset($current['return-op'])) { + return self::op($current['return-op'], $params, $current['return']); + } + if (isset($current['return'])) { + return $current['return']; + } + return call_user_func_array($function, $params); + } + + // Check if all expected calls are performed + public static function isEmpty(): bool + { + return empty(self::$queue); + } + + // Initialize call queue + public static function initialize($op_file, $asserter): void + { + $file = dirname(__DIR__) . "/scripts/{$op_file}.json"; + self::$queue = json_decode(file_get_contents($file), true); + self::$asserter = $asserter; + } + + // Special output handling + private static function op($op, $params, $data) + { + switch ($op) { + case 'chr-array': + // Convert int array to string + $out = ''; + foreach ($data as $val) { + $out .= chr($val); + } + return $out; + case 'file': + $content = file_get_contents(__DIR__ . "/{$data[0]}"); + return substr($content, $data[1], $data[2]); + case 'key-save': + preg_match('#Sec-WebSocket-Key:\s(.*)$#mUi', $params[1], $matches); + self::$stored['sec-websocket-key'] = trim($matches[1]); + return $data; + case 'key-respond': + $key = self::$stored['sec-websocket-key'] . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'; + $encoded = base64_encode(pack('H*', sha1($key))); + return str_replace('{key}', $encoded, $data); + } + return $data; + } +} -- cgit v1.2.3