Permalink
Browse files

- Added handling for setting / getting non-defined properties

- Checked behavior in case of error
- Removed readme
  • Loading branch information...
1 parent 45e7c52 commit b812148cffb4ad0e6dfefb19fb7270624eadf75c @shostakovich committed Oct 23, 2011
Showing with 52 additions and 5 deletions.
  1. +14 −2 Decapsulator.php
  2. +0 −3 README
  3. +38 −0 test/DecapsulatorTest.php
View
@@ -12,12 +12,24 @@ public function __construct($subject)
public function __set($name, $value)
{
- $this->setProperty($name, $value);
+ try{
+ $this->setProperty($name, $value);
+ }
+ catch(ReflectionException $e)
+ {
+ $this->subject->$name = $value;
+ }
}
public function __get($name)
{
- return $this->getProperty($name);
+ try{
+ return $this->getProperty($name);
+ }
+ catch(ReflectionException $e)
+ {
+ return NULL;
+ }
}
public function __call($name, $params)
View
3 README
@@ -1,3 +0,0 @@
-== InspectorProxy ==
-
-InspectorProxy exposes protected + private methods and properties.
View
@@ -8,6 +8,9 @@
$t = new lime_test();
+/**
+ * Variables
+ */
$t->is($proxy->private_var, "foo", "Gets private property on subject");
$t->is($proxy->protected_var, "foo", "Gets protected property on subject");
$t->is($proxy->public_var, "foo", "Gets public property on subject");
@@ -26,6 +29,14 @@
$proxy->setStatic("protected_static", "bar");
$t->is($proxy->getStatic("protected_static"), "bar", "Sets a static property");
+$t->is($proxy->doesnotexist, NULL, "Returns NULL for a property that does not exist");
+$proxy->doesnotexist = "bar";
+$t->is($proxy->doesnotexist, "bar", "Can set a property that does not exist");
+
+
+/**
+ * Methods
+ */
$t->is($proxy->privateMethod("foo", "bar"), "foobar", "Calls private method");
$t->is($proxy->protectedMethod("foo", "bar"), "foobar", "Calls proteced method");
$t->is($proxy->publicMethod("foo", "bar"), "foobar", "Calls public method");
@@ -35,3 +46,30 @@
$t->is($proxy->callStatic("protectedStaticMethod", array("foo", "bar")), "foobar", "Calls protected static method");
$t->is($proxy->callStatic("publicStaticMethod", array("foo", "bar")), "foobar", "Calls public static method");
+/**
+ * Errors
+ */
+
+try{
+ $proxy->fooBar();
+ $t->fail("Calling an undefined method did not fails");
+}catch(Exception $e)
+{
+ $t->pass("Calling an undefined method fails");
+}
+
+try{
+ $proxy->setStatic("foo", true);
+ $t->fail("Setting an undefined static property did not fails");
+}catch(Exception $e)
+{
+ $t->pass("Setting an undefined static property fails");
+}
+
+try{
+ $proxy->getStatic("foo");
+ $t->fail("Getting an undefined static property did not fails");
+}catch(Exception $e)
+{
+ $t->pass("Getting an undefined static property fails");
+}

0 comments on commit b812148

Please sign in to comment.