I have an interface that I want to make fun of, and make fun of the behavior of one of its methods.
So, I created a callback that very perversely behaves.
This test passes if I create a new object based on this interface, but I would like to make fun of the interface.
The cheated setUp method is fined, and the getVar ('testing') call in my callback returns a value. However, my statement fails because this value is not available.
It seems you can't do it in PHPUnit? If I'm not stupid.
A brief description of the code stream; The code in "getVar" calls a method that calls "setUp" in the added plugin. When it calls "setUp", it goes to "$ this". This is $ this, which I expect to pass by reference and which works with a "real" object.
class DefaultRendererTest extends \PHPUnit_Framework_TestCase
{
public function testSetGetVar()
{
$theme = $this->getMock('ThemeInterface');
$plugin = $this->getMock('PluginInterface');
$plugin->expects($this->once())
->method('setUp')
->will($this->returnCallback(function($r){
$r->setVar('testing', "fooBar");
}));
$renderer = new DefaultRenderer($theme, null);
$renderer->addPlugin($plugin);
$this->assertEquals('fooBar',$renderer->getVar('testing'));
}
}
For information, here is the interface, DefaultRenderer implements RendererInterface
interface PluginInterface
{
function setUp(RendererInterface $renderer);
}
source
share