我正在学习如何使用模拟来运行一些单元测试,但我不确定如何模拟我的数据库类。它由可以像以下两个示例一样链接的单独方法组成:
$db->select('someTblName',['fieldName'])
->where('fieldName', 'someValue')
->runQuery()
->fetch(); //returns array or null
另一种用途可能是:
$db->select('someTblName')
->where('fieldName', 'someValue')
->where('fieldName', array('>=' , 'someValue')
->runQuery()
->fetch(); //returns array or null
通过阅读一些文档,我发现我可以做类似的事情:(对于第一种情况)
$db = \Mockery::mock('Database');
$db->shouldReceive('select', 'where', 'runQuery', 'fetcth')
->with(??????)
->andReturn(null);
现在我对如何将“相应”参数传递给方法感兴趣?而且,我将如何模拟第二种情况。