Exemplo n.º 1
0
 /**
  * @test
  */
 public function shouldSubstituteParams()
 {
     //given
     $pdoStatement = Mock::mock();
     $pdo = Mock::mock();
     $db = Mock::mock('Ouzo\\Db');
     $db->_dbHandle = $pdo;
     Mock::when($pdo)->query(Mock::anyArgList())->thenReturn($pdoStatement);
     Mock::when($pdo)->quote("bob")->thenReturn("'bob'");
     Mock::when($pdoStatement)->fetchAll(Mock::anyArgList())->thenReturn(array());
     $modelQueryBuilder = new ModelQueryBuilder(SimpleModel::metaInstance(), $db);
     //when
     $modelQueryBuilder->where(array('name' => 'bob'))->options(array(Options::EMULATE_PREPARES => true))->fetchAll();
     //then
     Mock::verify($pdo)->query("SELECT simple_models.name AS _simple_models_name, simple_models.id AS _simple_models_id FROM simple_models WHERE name = 'bob'");
 }
Exemplo n.º 2
0
 /**
  * @test
  */
 public function shouldNotTryToDeleteIfEmptyInClause()
 {
     //given
     $mockDb = Mock::create('\\Ouzo\\Db');
     $builder = new ModelQueryBuilder(new Product(), $mockDb);
     //when
     $affectedRows = $builder->where(array('name' => array()))->deleteAll();
     //then
     $this->assertEquals(0, $affectedRows);
     //no interaction with db
     Mock::verify($mockDb)->neverReceived();
 }
Exemplo n.º 3
0
 public static function notExists(ModelQueryBuilder $queryBuilder)
 {
     return new ExistsClause($queryBuilder->getQuery(), true);
 }