/** * @group non-sqlite3 * @test */ public function selectShouldNotLockForUpdateByDefault() { // when $query = Query::select(); // then $this->assertFalse($query->lockForUpdate); }
/** * @test */ public function shouldHandleSubQueries() { //given Product::create(array('name' => 'prod1', 'description' => 'd')); Product::create(array('name' => 'prod1', 'description' => 'd')); Product::create(array('name' => 'prod2', 'description' => 'd')); $query = Query::select(array('count(*) AS c'))->from(Query::select(array('name', 'count(*) c'))->from('products')->groupBy('name')->where(array('description' => 'd')), 'sub')->where(array('c' => 2)); $executor = QueryExecutor::prepare(Db::getInstance(), $query); //when $result = $executor->fetch(); //then $this->assertEquals(array('c' => 1), $result); }
/** * @test */ public function shouldReturnGroupBy() { // given $query = Query::select(array('category', 'count(*)'))->table('products')->groupBy('category'); // when $sql = $this->_dialect->buildQuery($query); // then $this->assertEquals('SELECT category, count(*) FROM products GROUP BY category', $sql); }