Is there any way to set a class level variable within a mock object?
I have the mock object set similar to this:
$stub = $this->getMock('SokmeClass', array('method'));
$stub->expects($this->once())
->method('method')
->with($this->equalTo($arg1));
Win the real class there is a variable that needs to be set for it to work properly. How can I set that variable within a mock object?
With a module variable you can can either set the value directly or use mock.
Here is what works for me:
$stub = $this->getMock('SomeClass');
$stub->myvar = "Value";
Don't know why this works but it seems to for me. If you put the __get
magic method as one of the overridden methods e.g.
$mock = $this->getMock('Mail', array('__get'));
You can then you can successfully do
$mock->transport = 'smtp';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With