From c807cdd275e6ad5448bddcbb40c05b62e9ca4cac Mon Sep 17 00:00:00 2001 From: Erik Norgren Date: Thu, 13 Apr 2017 13:12:55 +0200 Subject: [PATCH] Added support for regular rpc calls with body. --- src/Context/ApiContext.php | 41 +++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/Context/ApiContext.php b/src/Context/ApiContext.php index 75a02c3..4b2fabe 100644 --- a/src/Context/ApiContext.php +++ b/src/Context/ApiContext.php @@ -565,7 +565,46 @@ public function iRemoveATypeWithIdFromRelationParentTypeWithId($type, $typeId, $ */ public function iSendAActionWithMethod($action, $method) { - $this->sendRpcAction('/' . $action, $method); + $this->iSendAActionWithMethodAndValues($action, $method, new TableNode([])); + } + + /** + * @When I send a :action action with method :method and values: + * + * @param $action + * @param $method + * @param TableNode $values + */ + public function iSendAActionWithMethodAndValues($action, $method, TableNode $values) + { + $body = []; + + foreach ($values->getRows() as list ($key, $values)) { + $body[$key] = $this->convertValueToAlias($values); + } + + $this->sendRpcAction(sprintf('/%s', $action), $method, $body); + } + + /** + * @When I send a :action action with method :method and body: + * + * @param $action + * @param $method + * @param PyStringNode $string + */ + public function iSendAActionWithMethodAndBody($action, $method, PyStringNode $string) + { + // Make sure the developer provided valid json + Assertions::assertJson($string->getRaw()); + + $data = json_decode($string, true); + + foreach ($data as $key => $value) { + $body[$key] = $this->convertValueToAlias($value); + } + + $this->sendRpcAction(sprintf('/%s', $action), $method, $body); } /**