From 86b3343b6f0b69c52773f8aeabb66c322464af1b Mon Sep 17 00:00:00 2001
From: Chris Boden <cboden@gmail.com>
Date: Sun, 29 Apr 2012 19:21:29 -0400
Subject: [PATCH] [WAMP] unit tests and fix

Increases code coverage on WAMP
Fixed a bug found while writing tests
---
 .../WAMP/Command/Action/CallError.php         |  1 +
 .../WAMP/Command/Action/CallErrorTest.php     | 72 +++++++++++++++++++
 .../WAMP/Command/Action/CallResultTest.php    | 46 ++++++++++++
 .../WAMP/Command/Action/EventTest.php         |  0
 .../WAMP/WAMPServerComponentTest.php          | 47 ------------
 5 files changed, 119 insertions(+), 47 deletions(-)
 create mode 100644 tests/Ratchet/Tests/Component/WAMP/Command/Action/CallErrorTest.php
 create mode 100644 tests/Ratchet/Tests/Component/WAMP/Command/Action/CallResultTest.php
 create mode 100644 tests/Ratchet/Tests/Component/WAMP/Command/Action/EventTest.php

diff --git a/src/Ratchet/Component/WAMP/Command/Action/CallError.php b/src/Ratchet/Component/WAMP/Command/Action/CallError.php
index 373e1fa..4aafbee 100644
--- a/src/Ratchet/Component/WAMP/Command/Action/CallError.php
+++ b/src/Ratchet/Component/WAMP/Command/Action/CallError.php
@@ -43,6 +43,7 @@ class CallError extends SendMessage {
 
         if (null !== $details) {
             $data[] = $details;
+            $this->_details = $details;
         }
 
         return $this->setMessage(json_encode($data));
diff --git a/tests/Ratchet/Tests/Component/WAMP/Command/Action/CallErrorTest.php b/tests/Ratchet/Tests/Component/WAMP/Command/Action/CallErrorTest.php
new file mode 100644
index 0000000..5d93349
--- /dev/null
+++ b/tests/Ratchet/Tests/Component/WAMP/Command/Action/CallErrorTest.php
@@ -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());
+    }
+}
\ No newline at end of file
diff --git a/tests/Ratchet/Tests/Component/WAMP/Command/Action/CallResultTest.php b/tests/Ratchet/Tests/Component/WAMP/Command/Action/CallResultTest.php
new file mode 100644
index 0000000..a931d4b
--- /dev/null
+++ b/tests/Ratchet/Tests/Component/WAMP/Command/Action/CallResultTest.php
@@ -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());
+    }
+}
\ No newline at end of file
diff --git a/tests/Ratchet/Tests/Component/WAMP/Command/Action/EventTest.php b/tests/Ratchet/Tests/Component/WAMP/Command/Action/EventTest.php
new file mode 100644
index 0000000..e69de29
diff --git a/tests/Ratchet/Tests/Component/WAMP/WAMPServerComponentTest.php b/tests/Ratchet/Tests/Component/WAMP/WAMPServerComponentTest.php
index c784e6c..7e44885 100644
--- a/tests/Ratchet/Tests/Component/WAMP/WAMPServerComponentTest.php
+++ b/tests/Ratchet/Tests/Component/WAMP/WAMPServerComponentTest.php
@@ -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() {
         return array(
             array('http://example.com', array('one', 'two'))