public function testProxyProperty() { $obj = new Prototype(); $obj->a = Prototype::proxy(function ($property) { return $property->get(); }, function ($property, $newValue) { return $property->set($newValue); }, Prototype::normal(1)); $this->assertEquals(1, $obj->a); $obj->a = 2; $this->assertEquals(2, $obj->a); $obj->a = Prototype::proxy(function ($property) { return $property->get(); }, function ($property, $newValue) { return $property->set($newValue); }, 1); $this->assertEquals(1, $obj->a); $obj->a = 2; $this->assertEquals(2, $obj->a); $obj->a = 2; $obj->b = Prototype::proxy(function ($property) { return $this->a * $property->get(); }, function ($property, $newValue) { return $property->set($newValue); }, 1); $this->assertEquals(2, $obj->b); $obj->b = 3; $this->assertEquals(6, $obj->b); $obj->a = 3; $this->assertEquals(9, $obj->b); $obj->a = 2; $obj->b = Prototype::proxy(function ($property) { return $property->get(); }, function ($property, $newValue) { return $property->set($newValue - $this->a); }, 1); $this->assertEquals(1, $obj->b); $obj->b = 1; $this->assertEquals(-1, $obj->b); }