Issues with mocking EE->TMPL->fetch_param
Hello there,
I'm writing some unit tests for a plugin that uses the fetch_param() method on the TMPL class, and having some troubles. Not entirely sure if it's a SimpleTest thing, but since the TMPL class is being mocked by Testee, I figured I'd ask here first.
At any rate, here's some code:
class TwitterTweetTemplateParams extends Testee_unit_test_case {
private $_params;
public function setUp(){
parent::setUp();
$this->_params = new TemplateParams($this->EE->TMPL);
}
public function testGetOptionTypeWithTagParam(){
$this->EE->TMPL->returns('fetch_param', 'option1', array('type'));
$this->assertIdentical('option1', $this->_params->getType());
}
}
and the class I'm testing contains a method like this:
function getType() {
return $this->_eeTemplate->fetch_param('type', 'option2');
}
but when my tests run, the Mocked TMPL class returns NULL for any fetch_param() call that includes the default parameter, causing my tests to fail.
Any advice here on how to get this working?
Support Staff 2 Posted by Stephen Lewis on 25 Jan, 2012 09:01 PM
Hi Douglas,
Your test syntax doesn't look like standard SimpleTest syntax to me, and I'm really not sure what this line means:
If you can give me a few more details on what
_eeTemplateis, and what you're trying to achieve, I should be able to help.Cheers,
Stephen
3 Posted by Douglas on 25 Jan, 2012 09:16 PM
Ah, apologies. The function in the second code snippet is the one I am trying to test against, not the actual SimpleTest assertion.
The getType() method below returns the value for the given plugin tag parameter from the EE Template class that's passed to the TemplateParams constructor.
Here's a complete version.
Support Staff 4 Posted by Stephen Lewis on 25 Jan, 2012 10:19 PM
Hi Douglas,
Is there a reason you're creating a new instance of the
EE_Templateclass, and passing it to your constructor?That's not to say it's impossible to test that, just that I don't understand why you're doing it, and thought it best to check that this isn't simply a misunderstanding regarding the typical usage of the
EE_Templateclass.Assuming this is what you're trying to achieve, I'd do something like this.
Cheers,
Stephen