From af35aab345b6bc511138dd9b9b1f9a7bcd44dc55 Mon Sep 17 00:00:00 2001
From: Chris Boden <cboden@gmail.com>
Date: Sun, 6 May 2012 14:27:14 -0400
Subject: [PATCH] True errors

---
 .../Resource/AbstractConnectionDecorator.php  |  7 ----
 .../AbstractConnectionDecoratorTest.php       | 40 ++++++++++++++++++-
 2 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/src/Ratchet/Resource/AbstractConnectionDecorator.php b/src/Ratchet/Resource/AbstractConnectionDecorator.php
index 3ae5472..c4ea479 100644
--- a/src/Ratchet/Resource/AbstractConnectionDecorator.php
+++ b/src/Ratchet/Resource/AbstractConnectionDecorator.php
@@ -22,14 +22,7 @@ abstract class AbstractConnectionDecorator implements ConnectionInterface {
         $this->wrappedConn->$name = $value;
     }
  
-    /**
-     * @todo trigger_error() instead - Have it the same as if called from a POPO
-     */
     public function __get($name) {
-        if (!$this->__isset($name)) {
-            throw new \InvalidArgumentException("Attribute '{$name}' not found in Connection {$this->getID()}");
-        }
- 
         return $this->wrappedConn->$name;
     }
  
diff --git a/tests/Ratchet/Tests/Resource/AbstractConnectionDecoratorTest.php b/tests/Ratchet/Tests/Resource/AbstractConnectionDecoratorTest.php
index 46cf6d7..5333093 100644
--- a/tests/Ratchet/Tests/Resource/AbstractConnectionDecoratorTest.php
+++ b/tests/Ratchet/Tests/Resource/AbstractConnectionDecoratorTest.php
@@ -103,7 +103,45 @@ class AbstractConnectionDecoratorTest extends \PHPUnit_Framework_TestCase {
         $this->assertSame($this->l1, $conn);
     }
 
+    public function testWrapperCanStoreSelfInDecorator() {
+        $this->mock->decorator = $this->l1;
+
+        $this->assertSame($this->l1, $this->l2->decorator);
+    }
+
+    public function testDecoratorRecursion() {
+        $this->mock->decorator = new \stdClass;
+        $this->mock->decorator->conn = $this->l1;
+
+        $this->assertSame($this->l1, $this->mock->decorator->conn);
+        $this->assertSame($this->l1, $this->l1->decorator->conn);
+        $this->assertSame($this->l1, $this->l2->decorator->conn);
+    }
+
+    public function testDecoratorRecursionLevel2() {
+        $this->mock->decorator = new \stdClass;
+        $this->mock->decorator->conn = $this->l2;
+
+        $this->assertSame($this->l2, $this->mock->decorator->conn);
+        $this->assertSame($this->l2, $this->l1->decorator->conn);
+        $this->assertSame($this->l2, $this->l2->decorator->conn);
+
+        // just for fun
+        $this->assertSame($this->l2, $this->l2->decorator->conn->decorator->conn->decorator->conn);
+    }
+
     public function testWarningGettingNothing() {
-        $this->markTestSkipped('Functionality not in class yet');
+        $this->setExpectedException('PHPUnit_Framework_Error');
+        $var = $this->mock->nonExistant;
+    }
+
+    public function testWarningGettingNothingLevel1() {
+        $this->setExpectedException('PHPUnit_Framework_Error');
+        $var = $this->l1->nonExistant;
+    }
+
+    public function testWarningGettingNothingLevel2() {
+        $this->setExpectedException('PHPUnit_Framework_Error');
+        $var = $this->l2->nonExistant;
     }
 }
\ No newline at end of file