Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge pull request zendframework/zendframework#5857 from samsonasik/v…
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Apr 14, 2014
2 parents 4407fb8 + 42be340 commit 4d51c49
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Db/AbstractDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ public function setSelect(Select $select)
*/
public function getSelect()
{
if ($this->select instanceof Select) {
if ($this->select instanceof Select
&& ($this->getSchema() === null || $this->getTable() === '' || $this->getField() === '' || $this->getExclude() === null)) {
return $this->select;
}

Expand Down
35 changes: 35 additions & 0 deletions test/Db/RecordExistsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,39 @@ public function testGetSelect()
$this->assertNull($parameters['where1']);
$this->assertEquals($parameters['where2'], 'bar');
}

/**
* @cover Zend\Validator\Db\RecordExists::getSelect
* @group ZF2-4521
*/
public function testGetSelectWithSameValidatorTwice()
{
$validator = new RecordExists(
array(
'table' => 'users',
'schema' => 'my'
),
'field1',
array(
'field' => 'foo',
'value' => 'bar'
),
$this->getMockHasResult()
);
$select = $validator->getSelect();
$this->assertInstanceOf('Zend\Db\Sql\Select', $select);
$this->assertEquals('SELECT "my"."users"."field1" AS "field1" FROM "my"."users" WHERE "field1" = \'\' AND "foo" != \'bar\'', $select->getSqlString(new TrustingSql92Platform()));

// same validator instance with changing properties
$validator->setTable('othertable');
$validator->setSchema('otherschema');
$validator->setField('fieldother');
$validator->setExclude(array(
'field' => 'fieldexclude',
'value' => 'fieldvalueexclude',
));
$select = $validator->getSelect();
$this->assertInstanceOf('Zend\Db\Sql\Select', $select);
$this->assertEquals('SELECT "otherschema"."othertable"."fieldother" AS "fieldother" FROM "otherschema"."othertable" WHERE "fieldother" = \'\' AND "fieldexclude" != \'fieldvalueexclude\'', $select->getSqlString(new TrustingSql92Platform()));
}
}

0 comments on commit 4d51c49

Please sign in to comment.