So I have this builder that runs a buildClass method which should be public, and it takes a couple of arguments.
In my test I want to remove those arguments completely and add something completely different using the Mock in PHPUnit.
So: from:
class ClassBuilder{
public function buildClass($id, $some, $vars){
$class = new Class($id, $some, $vars);
return self::getClass(db_Class, $class);
}
}
So you might get my idea here, I want to make a mock so it does the return function there.
$myClassStub->getMock("ClassBuilder");
$myClassStub->->expects($this->any())
->method("buildClass")
->with($this->anything(), $this->anything())
->will($this->returnCallback("getClass"));
But I have no idea how it works. This is how I thought it would be, but I have no clue where to put the arguments at all. Please help me out here, much appriciated.
/Marcus
You can just leave out the
->with($this->anything(), $this->anything())exepct if it is there to make sure that you pass at least 2 arguments into that function.Apart from you that I’ve understood is that you want to return a different class. In that case I’d suggest doing: