Skip to content

Commit

Permalink
Correct spelling of options, add test for publish options. Fixes #9
Browse files Browse the repository at this point in the history
  • Loading branch information
mbonneau committed Mar 6, 2016
1 parent f9fbcb0 commit d04bb0c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/WampPost/WampPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private function handlePublishHttpPost(Request $request, Response $response) {
}

$argsKw = isset($json->argsKw) && is_object($json->argsKw) ? $json->argsKw : null;
$options = isset($json->options) && is_object($json->opitons) ? $json->options : null;
$options = isset($json->options) && is_object($json->options) ? $json->options : null;
$this->getSession()->publish($json->topic, $json->args, $argsKw, $options);
} else {
throw new \Exception("Invalid request: " . json_encode($json));
Expand Down
48 changes: 48 additions & 0 deletions tests/Functional/WampPostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

class WampPostTest extends TestCase
{
/**
* @var EventMessage[]
*/
private $_testTopicEvents = [];

private function runTestWith($method, $url, array $headers = [], $protocolVersion = '1.0', $body)
{
$router = $this->createTestRouter();
Expand All @@ -23,6 +28,14 @@ private function runTestWith($method, $url, array $headers = [], $protocolVersio
$session->register("procedure.that.errors", function () {
throw new WampErrorException("my.custom.error", [4,5,6], (object)["x"=>"y"], (object)["y"=>"z"]);
});

$this->_testTopicEvents = [];

// this subscription is here to test that options are working ("exclude_me")
$session->subscribe("wamppost.tests.nonexclude.topic", function ($args, $argsKw, $details, $pubId) {
$event = new EventMessage(0, $pubId, $details, $args, $argsKw, "wamppost.tests.nonexclude.topic");
$this->_testTopicEvents[] = $event;
});
});

$router->addInternalClient($wampPost);
Expand Down Expand Up @@ -78,6 +91,41 @@ function testPublishOnlyArgs()
);
}

function testPublishWithOptions()
{
/** @var Response $response */
list($response, $responseBody, $events) = $this->runTestWith(
"POST",
"http://127.0.0.1:18181/pub",
[],
'1.0',
json_encode(
[
"topic" => "wamppost.tests.nonexclude.topic",
"args" => [1, "two"],
"options" => [ "exclude_me" => false ]
]
)
);

$this->assertEquals($responseBody, "3\r\npub\r\n0\r\n\r\n");
$this->assertEquals(200, $response->getCode());

$this->assertEvents(
[
new EventMessage(0, 0, (object)["topic" => "wamppost.tests.nonexclude.topic"], [1, "two"], null, null,
"wamppost.tests.nonexclude.topic")
],
$events
);

$this->assertEquals(1, count($this->_testTopicEvents));
$this->assertEvents([
new EventMessage(0, 0, new \stdClass(), [1, "two"], null, null,
"wamppost.tests.nonexclude.topic")
], $this->_testTopicEvents);
}

function testPublishArgsArgsKw()
{
/** @var Response $response */
Expand Down

0 comments on commit d04bb0c

Please sign in to comment.