Assuming I had something like:
class TestedClass{
public function foo( $value ){
return 'Tested ’ . $value;
}
}
class ToTest{
public function __construct(TestedClass $class)
{
$this->class = $class;
}
public function Baz($value){ return $this->class->foo($value); }
}
TestedClass has already been tested. I know that ‘Tested’ is correctly been assigned and returning fine.
Would/Should I be writting unit tests for ToTest() to check that TestedClass::foo() is being called correctly as well?
If so how would you mock up the depancy so you can check that the value is correct I tried:
$TestedClass = $this->getMockBuilder('\TestedClass')
->disableOriginalConstructor()
->getMock();
$TestedClass->expects($this->once())
->method('foo')
->will($this->returnValue('return'));
// pass the mock into tested object
$Test = new \ToTest($TestedClass);
// run test
$this->assertEquals($Test->debug('rnd'), 'Testedrnd');
What I want to be able to test is
a) The TestClass::Foo is called when calling ToTest::Baz
b) The value of that based on the parameter set in ToTest::Baz
Any pointers would be much appreciated.