hasAny() public method

Checks if the specified table contains any record matching specified SQL
public hasAny ( Model $Model, string $sql ) : boolean
$Model Model Model to search
$sql string SQL WHERE clause (condition only, not the "WHERE" part)
return boolean True if the table has a matching record, else false
Example #1
0
 /**
  * test hasAny()
  *
  * @return void
  */
 public function testHasAny()
 {
     $this->Dbo = $this->getMock('Mysql', array('connect', '_execute', 'execute', 'value'));
     $this->Model = $this->getMock('TestModel', array('getDataSource'));
     $this->Model->expects($this->any())->method('getDataSource')->will($this->returnValue($this->Dbo));
     $this->Dbo->expects($this->at(0))->method('value')->with('harry')->will($this->returnValue("'harry'"));
     $this->Dbo->expects($this->at(1))->method('execute')->with('SELECT COUNT(`TestModel`.`id`) AS count FROM `test_models` AS `TestModel` WHERE `TestModel`.`name` = \'harry\'');
     $this->Dbo->expects($this->at(2))->method('execute')->with('SELECT COUNT(`TestModel`.`id`) AS count FROM `test_models` AS `TestModel` WHERE 1 = 1');
     $this->Dbo->hasAny($this->Model, array('TestModel.name' => 'harry'));
     $this->Dbo->hasAny($this->Model, array());
 }