[WAMP] unit tests and fix

Increases code coverage on WAMP
Fixed a bug found while writing tests
This commit is contained in:
Chris Boden 2012-04-29 19:21:29 -04:00
parent 381dd7bab6
commit 86b3343b6f
5 changed files with 119 additions and 47 deletions

View File

@ -43,6 +43,7 @@ class CallError extends SendMessage {
if (null !== $details) { if (null !== $details) {
$data[] = $details; $data[] = $details;
$this->_details = $details;
} }
return $this->setMessage(json_encode($data)); return $this->setMessage(json_encode($data));

View File

@ -0,0 +1,72 @@
<?php
namespace Ratchet\Tests\Component\WAMP\Command\Action;
use Ratchet\Component\WAMP\Command\Action\CallError;
use Ratchet\Tests\Mock\Connection;
/**
* @covers Ratchet\Component\WAMP\Command\Action\CallError
*/
class CallErrorTest extends \PHPUnit_Framework_TestCase {
public function testCallError() {
$error = new CallError(new Connection);
$callId = uniqid();
$uri = 'http://example.com/end/point';
$error->setError($callId, $uri);
$resultString = $error->getMessage();
$this->assertEquals(array(4, $callId, $uri, ''), json_decode($resultString, true));
}
public function testDetailedCallError() {
$error = new CallError(new Connection);
$callId = uniqid();
$uri = 'http://example.com/end/point';
$desc = 'beep boop beep';
$detail = 'Error: Too much awesome';
$error->setError($callId, $uri, $desc, $detail);
$resultString = $error->getMessage();
$this->assertEquals(array(4, $callId, $uri, $desc, $detail), json_decode($resultString, true));
}
public function testGetId() {
$id = uniqid();
$error = new CallError(new Connection);
$error->setError($id, 'http://example.com');
$this->assertEquals($id, $error->getId());
}
public function testGetUri() {
$uri = 'http://example.com/end/point';
$error = new CallError(new Connection);
$error->setError(uniqid(), $uri);
$this->assertEquals($uri, $error->getUri());
}
public function testGetDescription() {
$desc = uniqid();
$error = new CallError(new Connection);
$error->setError(uniqid(), 'curie', $desc);
$this->assertEquals($desc, $error->getDescription());
}
public function testGetDetails() {
$detail = uniqid();
$error = new CallError(new Connection);
$this->assertNull($error->getDetails());
$error->setError(uniqid(), 'http://socketo.me', 'desc', $detail);
$this->assertEquals($detail, $error->getDetails());
}
}

View File

@ -0,0 +1,46 @@
<?php
namespace Ratchet\Tests\Component\WAMP\Command\Action;
use Ratchet\Component\WAMP\Command\Action\CallResult;
use Ratchet\Tests\Mock\Connection;
/**
* @covers Ratchet\Component\WAMP\Command\Action\CallResult
*/
class CallResultTest extends \PHPUnit_Framework_TestCase {
public function testGetMessage() {
$result = new CallResult(new Connection);
$callId = uniqid();
$data = array('hello' => 'world', 'herp' => 'derp');
$result->setResult($callId, $data);
$resultString = $result->getMessage();
$this->assertEquals(array(3, $callId, $data), json_decode($resultString, true));
}
public function testGetId() {
$id = uniqid();
$result = new CallResult(new Connection);
$result->setResult($id, array());
$this->assertEquals($id, $result->getId());
}
public function testGetData() {
$data = array(
'hello' => 'world'
, 'recursive' => array(
'the' => 'quick'
, 'brown' => 'fox'
)
, 'jumps'
);
$result = new CallResult(new Connection);
$result->setResult(uniqid(), $data);
$this->assertEquals($data, $result->getData());
}
}

View File

@ -124,53 +124,6 @@ class WAMPServerComponentTest extends \PHPUnit_Framework_TestCase {
} }
/**
* @covers Ratchet\Component\WAMP\Command\Action\CallResult
*/
public function testCallResponse() {
$result = new CallResult($this->newConn());
$callId = uniqid();
$data = array('hello' => 'world', 'herp' => 'derp');
$result->setResult($callId, $data);
$resultString = $result->getMessage();
$this->assertEquals(array(3, $callId, $data), json_decode($resultString, true));
}
/**
* @covers Ratchet\Component\WAMP\Command\Action\CallError
*/
public function testCallError() {
$error = new CallError($this->newConn());
$callId = uniqid();
$uri = 'http://example.com/end/point';
$error->setError($callId, $uri);
$resultString = $error->getMessage();
$this->assertEquals(array(4, $callId, $uri, ''), json_decode($resultString, true));
}
/**
* @covers Ratchet\Component\WAMP\Command\Action\CallError
*/
public function testDetailedCallError() {
$error = new CallError($this->newConn());
$callId = uniqid();
$uri = 'http://example.com/end/point';
$desc = 'beep boop beep';
$detail = 'Error: Too much awesome';
$error->setError($callId, $uri, $desc, $detail);
$resultString = $error->getMessage();
$this->assertEquals(array(4, $callId, $uri, $desc, $detail), json_decode($resultString, true));
}
public function eventProvider() { public function eventProvider() {
return array( return array(
array('http://example.com', array('one', 'two')) array('http://example.com', array('one', 'two'))