I am learning how to use mockery to run some unit test, and I'm not sure what to do to mock my database class. It consists of separate methods that can be connected in a circuit, like these two examples:
$db->select('someTblName',['fieldName'])
->where('fieldName', 'someValue')
->runQuery()
->fetch();
Other uses might be:
$db->select('someTblName')
->where('fieldName', 'someValue')
->where('fieldName', array('>=' , 'someValue')
->runQuery()
->fetch();
From reading some documents, I see that I can do something like: (for the first case)
$db = \Mockery::mock('Database');
$db->shouldReceive('select', 'where', 'runQuery', 'fetcth')
->with(??????)
->andReturn(null);
Now I'm wondering how to pass the “relevant parameters” to the methods? And, how I would make fun of the second scenario.
source
share