Skip to content

Instantly share code, notes, and snippets.

@settermjd settermjd/where-mock.php
Last active Dec 29, 2015

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

commented Nov 22, 2013

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

This comment has been minimized.

Copy link
Owner Author

commented Nov 22, 2013

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
You can’t perform that action at this time.