AnsweredAssumed Answered

Writting unittest for SugarQuery

Question asked by Shivam Tailor on Jun 6, 2019

How to write unitest for the function that using SugarQuery object?


function getAccounts() {
   $sugarQuery = new SugarQuery();
   $sugarQuery->joinTable('accounts_cstm', array('joinType' => 'LEFT', 'alias' => 'acc_c'))->on()->equalsField('', 'acc_c.id_c')->equals('accounts.deleted',0);
   $sugarQuery->where()->equals('acc_c.status_c', 'active');
   $sugarQuery->orderByRaw('acc_c.effective_date_c', 'DESC');
   $result = $sugarQuery->execute();
   return $result;


I found a code by which we can mock the SugarQuery object,

$sugarQuery = $this->createMock(SugarQuery::class);
            ->willReturn([['id' => 'id-1', 'name' => 'test name']]);

But don't know how to exactly replicate it using createMock method.