public function testPropertyKinds() { new _Aop(); # BEFORE $tpBeforeRead = _Aop::addBefore('read **\\Aop->tp', function ($jp, $options) { $this->object($jp)->isInstanceOf('\\Aop\\JoinPoint\\BeforePropertyReadJoinPoint')->string($jp->getPropertyName())->isEqualTo('tp')->string($jp->getClassName())->isEqualTo('tests\\units\\Aop\\Aop')->object($jp->getReflectionProperty())->isInstanceOf('\\ReflectionProperty')->array($options)->hasKey('opt1')->contains('val1')->string($options['opt1'])->isEqualTo('val1'); }, ['opt1' => 'val1']); $tpBeforeWrite = _Aop::addBefore('write **\\Aop->tp', function ($jp, $options) { $this->object($jp)->isInstanceOf('\\Aop\\JoinPoint\\BeforePropertyWriteJoinPoint')->string($jp->getPropertyName())->isEqualTo('tp')->string($jp->getClassName())->isEqualTo('tests\\units\\Aop\\Aop')->object($jp->getReflectionProperty())->isInstanceOf('\\ReflectionProperty')->array($options)->hasKey('opt1')->contains('val1')->string($options['opt1'])->isEqualTo('val1'); }, ['opt1' => 'val1']); $tpBefore = _Aop::addBefore('**\\Aop->tp', function ($jp, $options) { // The "PECL AOP extension" triggers the joinpoints write and read for this. // the desired normal behavior would trigger "<the kind>PropertyJoinPoint", // like AfterMethodJoinPoint encompassing the behaviors "throw" and "return". // $this->object($jp)->isInstanceOf('\Aop\JoinPoint\BeforePropertyJoinPoint'); $availables = ['Aop\\JoinPoint\\BeforePropertyReadJoinPoint', 'Aop\\JoinPoint\\BeforePropertyWriteJoinPoint', 'Aop\\JoinPoint\\BeforePropertyJoinPoint']; $this->object($jp)->array($availables)->contains($class = get_class($jp))->object($jp)->isInstanceOf($class)->string($jp->getPropertyName())->isEqualTo('tp')->string($jp->getClassName())->isEqualTo('tests\\units\\Aop\\Aop')->object($jp->getReflectionProperty())->isInstanceOf('\\ReflectionProperty')->array($options)->hasKey('opt1')->contains('val1')->string($options['opt1'])->isEqualTo('val1'); }, ['opt1' => 'val1']); $this->integer($tpBeforeRead)->isEqualTo(1)->integer($tpBeforeWrite)->isEqualTo(2)->integer($tpBefore)->isEqualTo(3); # AROUND $tpAroundRead = _Aop::addAround('read **\\Aop->tp', function ($jp, $options) { $this->object($jp)->isInstanceOf('\\Aop\\JoinPoint\\AroundPropertyReadJoinPoint')->string($jp->getPropertyName())->isEqualTo('tp')->string($jp->getClassName())->isEqualTo('tests\\units\\Aop\\Aop')->object($jp->getReflectionProperty())->isInstanceOf('\\ReflectionProperty')->array($options)->hasKey('opt1')->contains('val1')->string($options['opt1'])->isEqualTo('val1'); $jp->proceed(); }, ['opt1' => 'val1']); $tpAroundWrite = _Aop::addAround('write **\\Aop->tp', function ($jp, $options) { $this->object($jp)->isInstanceOf('\\Aop\\JoinPoint\\AroundPropertyWriteJoinPoint')->string($jp->getPropertyName())->isEqualTo('tp')->string($jp->getClassName())->isEqualTo('tests\\units\\Aop\\Aop')->object($jp->getReflectionProperty())->isInstanceOf('\\ReflectionProperty')->array($options)->hasKey('opt1')->contains('val1')->string($options['opt1'])->isEqualTo('val1'); $jp->proceed(); }, ['opt1' => 'val1']); $tpAround = _Aop::addAround('**\\Aop->tp', function ($jp, $options) { // The "PECL AOP extension" triggers the joinpoints write and read for this. // the desired normal behavior would trigger "<the kind>PropertyJoinPoint", // like AfterMethodJoinPoint encompassing the behaviors "throw" and "return". // $this->object($jp)->isInstanceOf('\Aop\JoinPoint\AroundPropertyJoinPoint'); $availables = ['Aop\\JoinPoint\\AroundPropertyReadJoinPoint', 'Aop\\JoinPoint\\AroundPropertyWriteJoinPoint', 'Aop\\JoinPoint\\AroundPropertyJoinPoint']; $this->object($jp)->array($availables)->contains($class = get_class($jp))->object($jp)->isInstanceOf($class)->string($jp->getPropertyName())->isEqualTo('tp')->string($jp->getClassName())->isEqualTo('tests\\units\\Aop\\Aop')->object($jp->getReflectionProperty())->isInstanceOf('\\ReflectionProperty')->array($options)->hasKey('opt1')->contains('val1')->string($options['opt1'])->isEqualTo('val1'); $jp->proceed(); }, ['opt1' => 'val1']); $this->integer($tpAroundRead)->isEqualTo(4)->integer($tpAroundWrite)->isEqualTo(5)->integer($tpAround)->isEqualTo(6); # AFTER $tpAfterRead = _Aop::addAfter('read **\\Aop->tp', function ($jp, $options) { $this->object($jp)->isInstanceOf('\\Aop\\JoinPoint\\AfterPropertyReadJoinPoint')->string($jp->getPropertyName())->isEqualTo('tp')->string($jp->getClassName())->isEqualTo('tests\\units\\Aop\\Aop')->object($jp->getReflectionProperty())->isInstanceOf('\\ReflectionProperty')->array($options)->hasKey('opt1')->contains('val1')->string($options['opt1'])->isEqualTo('val1'); }, ['opt1' => 'val1']); $tpAfterWrite = _Aop::addAfter('write **\\Aop->tp', function ($jp, $options) { $this->object($jp)->isInstanceOf('\\Aop\\JoinPoint\\AfterPropertyWriteJoinPoint')->string($jp->getPropertyName())->isEqualTo('tp')->string($jp->getClassName())->isEqualTo('tests\\units\\Aop\\Aop')->object($jp->getReflectionProperty())->isInstanceOf('\\ReflectionProperty')->array($options)->hasKey('opt1')->contains('val1')->string($options['opt1'])->isEqualTo('val1'); }, ['opt1' => 'val1']); $tpAfter = _Aop::addAfter('**\\Aop->tp', function ($jp, $options) { // The "PECL AOP extension" triggers the joinpoints write and read for this. // the desired normal behavior would trigger "<the kind>PropertyJoinPoint", // like AfterMethodJoinPoint encompassing the behaviors "throw" and "return". // $this->object($jp)->isInstanceOf('\Aop\JoinPoint\AfterPropertyJoinPoint'); $availables = ['Aop\\JoinPoint\\AfterPropertyReadJoinPoint', 'Aop\\JoinPoint\\AfterPropertyWriteJoinPoint', 'Aop\\JoinPoint\\AfterPropertyJoinPoint']; $this->object($jp)->array($availables)->contains($class = get_class($jp))->object($jp)->isInstanceOf($class)->string($jp->getPropertyName())->isEqualTo('tp')->string($jp->getClassName())->isEqualTo('tests\\units\\Aop\\Aop')->object($jp->getReflectionProperty())->isInstanceOf('\\ReflectionProperty')->array($options)->hasKey('opt1')->contains('val1')->string($options['opt1'])->isEqualTo('val1'); }, ['opt1' => 'val1']); $this->integer($tpAfterRead)->isEqualTo(7)->integer($tpAfterWrite)->isEqualTo(8)->integer($tpAfter)->isEqualTo(9); // triggers the kinds of property $this->tp = 'value'; $read = function () { return $this->tp; }; $read(); }