Skip to content

Commit 1eb1261

Browse files
committed
Add factory methods to create stub error responses
1 parent 7cdef26 commit 1eb1261

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"rybakit/msgpack": "^0.7",
1818
"rybakit/phpunit-extras": "^0.2",
1919
"symfony/expression-language": "^3.3|^4|^5",
20-
"tarantool/client": "^0.7|^0.8"
20+
"tarantool/client": "^0.8"
2121
},
2222
"require-dev": {
2323
"php": "^7.1.3",

src/Client/TestDoubleFactory.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,25 @@ public static function createEmptyResponse() : Response
3232
{
3333
return self::createResponseFromData([null]);
3434
}
35+
36+
public static function createErrorResponse(string $errorMessage = '', int $errorCode = 0) : Response
37+
{
38+
return self::createResponse(
39+
[Keys::ERROR_24 => $errorMessage],
40+
[Keys::CODE => Response::TYPE_ERROR + $errorCode]
41+
);
42+
}
43+
44+
public static function createErrorResponseFromStack(array $errorStack) : Response
45+
{
46+
$errorMessage = $errorStack[0][Keys::ERROR_MESSAGE] ?? '';
47+
$errorCode = $errorStack[0][Keys::ERROR_CODE] ?? 0;
48+
49+
return self::createResponse([
50+
Keys::ERROR_24 => $errorMessage,
51+
Keys::ERROR => [Keys::ERROR_STACK => $errorStack],
52+
], [
53+
Keys::CODE => Response::TYPE_ERROR + $errorCode,
54+
]);
55+
}
3556
}

0 commit comments

Comments
 (0)