Example #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());
 }
Example #2
0
 /**
  * Count number of records in selection.
  *
  * @return int Number of records.
  */
 public function count()
 {
     $selection = new ReadSelectionBuilder($this->getSource());
     return $selection->count();
 }