मैं यूनिट परीक्षण और PHPUnit के लिए नया हूं।PHPUnit में दिए गए इंटरफ़ेस को लागू करने वाले नकली ऑब्जेक्ट पर अपरिभाषित विधि?
मुझे एक नकली की ज़रूरत है, जिस पर मेरा पूरा नियंत्रण है, ConfigurationInterface
इंटरफेस को कार्यान्वित करना। टेस्ट विषय ReportEventParamConverter
ऑब्जेक्ट और परीक्षण को मेरी ऑब्जेक्ट और इंटरफ़ेस के बीच बातचीत की जांच करनी चाहिए।
ReportEventParamConverter
वस्तु (यहाँ सरलीकृत):
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();
}
}
और इस तरह मैं इंटरफ़ेस उपहास करने के लिए कोशिश कर रहा हूँ है:
$cls = 'Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationInterface';
$mock = $this->getMock($mockCls);
मैं दो के लिए लौट आए मूल्यों अनुकरण करने की जरूरत है विधियां: getClass()
और getName()
। उदाहरण के लिए:
$mock->expects($this->any())
->method('getClass')
->will($this->returnValue('Some\Other\Class'))
;
जब मैं एक नया ReportEventParamConverter
और परीक्षण supports()
विधि बनाने के लिए, मैं निम्नलिखित PHPUnit त्रुटि मिलती है:
Fatal error: Call to undefined method Mock_ConfigurationInterface_21e9dccf::getClass().
$converter = new ReportEventParamConverter();
$this->assertFalse($converter->supports($mock));
क्या 'पैराम कनवर्टरइंटरफेस' में 'getClass()' विधि है? – hakre
@ हाकरा क्या मायने रखता है? – gremo
कृपया अपने प्रश्न में अधिक जानकारी जोड़ने के लिए प्रश्न का उत्तर दें। इससे कोई फर्क नहीं पड़ता। इसके अलावा, यह मेरी पहली धारणा होगी कि नकली के पास ऐसा कार्य क्यों नहीं है। तो कुछ बुनियादी डीबगिंग। – hakre