I'm new to unit testing and PHPUnit.
I need a mock, on which I have a full control, implementing ConfigurationInterface interface. Test subject is ReportEventParamConverter object and test must check the interaction between my object and the interface.
ReportEventParamConverter object (here simplified):
class ReportEventParamConverter implements ParamConverterInterface
{
/**
* @param Request $request
* @param ConfigurationInterface $configuration
*/
function apply(Request $request, ConfigurationInterface $configuration)
{
$request->attributes->set($configuration->getName(), $reportEvent);
}
/**
* @param ConfigurationInterface $configuration
* @return bool
*/
function supports(ConfigurationInterface $configuration)
{
return 'My\Namespaced\Class' === $configuration->getClass();
}
}
And this is the way I'm trying to mock the interface:
$cls = 'Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationInterface';
$mock = $this->getMock($mockCls);
I need to simulate the returned values for two methods: getClass() and getName(). For example:
$mock->expects($this->any())
->method('getClass')
->will($this->returnValue('Some\Other\Class'))
;
When i create a new ReportEventParamConverter and test supports() method, i get the following PHPUnit error:
Fatal error: Call to undefined method Mock_ConfigurationInterface_21e9dccf::getClass().
$converter = new ReportEventParamConverter();
$this->assertFalse($converter->supports($mock));
ParamConverterInterfacehas thegetClass()method?getClass()is never invoked on anyParamConverterInterfaceinstance.supports()method, isn't it?