Skip to content

Instantly share code, notes, and snippets.

@settermjd
Last active December 29, 2015 01:58
Show Gist options
  • Save settermjd/7596618 to your computer and use it in GitHub Desktop.
Save settermjd/7596618 to your computer and use it in GitHub Desktop.
I'm having trouble mocking "$select->where->greaterThanOrEqualTo" with Zend\Db\Sql. Hope someone can shed light on this.
/*
* Here's the function call.
* $searchCriteria is an instance of \Zend\InputFilter\InputFilter
*/
$select->where->greaterThanOrEqualTo(
"EventDate", new \Zend\Db\Sql\Expression(
"STR_TO_DATE('" . $searchCriteria->getValue("startDate") ."','%m-%d-%Y')"
)
);
// Here's my attempt to mock
$mockWhere = \Mockery::mock('Zend\Db\Sql\Where');
$mockWhere->shouldReceive('greaterThanOrEqualTo')->with(
"EventDate",
new \Zend\Db\Sql\Expression("STR_TO_DATE('" . $searchCriteria->getValue("startDate") ."','%m-%d-%Y')"
))->andReturn($mockWhere);
$mockSql = \Mockery::mock('Zend\Db\Sql\Select');
$mockSql->shouldReceive('select')->andReturn($mockSql);
$mockSql->shouldReceive('__get')->with('where')->andReturn($mockWhere);
// The error that I receive is: Fatal error: Call to a member function greaterThanOrEqualTo() on a non-object
@settermjd
Copy link
Author

What I thought I'd need to do is to mock the Where object, which is returned through the __get method on the Select object. But it never seems to work. Not sure how to proceed.

@settermjd
Copy link
Author

After a good chat on IRC and reading over https://github.com/padraic/mockery#php-magic-methods, I realise I've taken the wrong path and likely won't be able to test this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment