Exemplo n.º 1
0
 public function testCount()
 {
     $db = $this->getDb();
     $table = new SqlTable($db, 'Foo');
     // Count all
     $selection = new ReadSelectionBuilder($table);
     $db->expects($this->exactly(2))->method('query')->withConsecutive([$this->equalTo('SELECT COUNT(*) AS _count FROM {Foo}')], [$this->equalTo('SELECT COUNT(*) AS _count FROM (SELECT 1 FROM {Foo} GROUP BY a) AS _selection_count')])->willReturnCallback(function () {
         return $this->getResultSet([['_count' => 42]]);
     });
     $this->assertEquals(42, $selection->count());
     // Count groups
     $this->assertEquals(42, $selection->groupBy('a')->count());
 }
Exemplo n.º 2
0
 /**
  * Group by one or more columns.
  *
  * @param string|string[] $columns
  *            A single column name or a list of column
  *            names.
  * @param Expression|string $predicate
  *            Grouping predicate.
  * @return ReadSelectionBuilder A read selection.
  */
 public function groupBy($columns, $predicate = null)
 {
     $selection = new ReadSelectionBuilder($this->getSource());
     return $selection->groupBy($columns, $predicate);
 }