AspectMock icon indicating copy to clipboard operation
AspectMock copied to clipboard

How do I mock a protected property of a an object.

Open besrabasant opened this issue 8 years ago • 1 comments

Given

Class A {
     protected $x = false;

     public function methodA()
     {
             if($x){   return 'FOO';  }
             return 'BAR';
     }
}

My test is -

$a = new A();

\Aspectmock\Test::double($a,['x' => true]);

$this->assertEquals('BAR', $a->methodA() );

I get null.

How do I solve this?

besrabasant avatar Jun 14 '17 06:06 besrabasant

it's not connected to AspectMock, http://php.net/manual/en/reflectionproperty.setvalue.php

zuozp8 avatar Jun 26 '17 12:06 zuozp8