Simpletest mocks expect() question

Discussion of testing theory and practice, including methodologies (such as TDD, BDD, DDD, Agile, XP) and software - anything to do with testing goes here. (Formerly "The Testing Side of Development")

Moderator: General Moderators

Post Reply
georgeoc
Forum Contributor
Posts: 166
Joined: Wed Aug 09, 2006 4:21 pm
Location: London, UK

Simpletest mocks expect() question

Post by georgeoc »

Hi.

Is there a way that a mock can just check for *some* of the parameters passed to a particular method, rather than all of them? I have mocked a database connection, and I'm using it in my language file. When I run:

Code: Select all

$lang->install();
it will pass the language strings to the db like this:

Code: Select all

$this->_db->insert('lang_strings', array(/*very large array of strings*/));
In my test, I'd like to be able to use this:

Code: Select all

$mock_db->expect('insert', array('lang_strings'));
... or similar, and have the test pass. I understand that this is likely to break other uses of the expect() function, so I'm not sure what to do.

All I want my mock to check for is that the database table name ('lang_strings') is correct - testing each element of the large array seems pointless and will create dependency in the test. If it's not possible for the Mock to only take notice of the first parameter, how do you suggest I test the lang class sufficiently?

Many thanks!
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Yes you can do it, you use the Expectation classes.

Code: Select all

$mock_db->expect('insert', array('lang_strings', new IsAExpectation('array')));
Note that you may also want to consider mocking the language strings source so you don't have to pass that many things.
georgeoc
Forum Contributor
Posts: 166
Joined: Wed Aug 09, 2006 4:21 pm
Location: London, UK

Post by georgeoc »

Great - that's exactly what I was looking for.

Thanks!
Post Reply