/**
  * Prepares a pager based on the finder
  * The pager is initialized (it knows how many pages it contains)
  * But it won't be populated until you call getResults() on it
  *
  * @param integer $page The current page (1 by default)
  * @param integer $maxPerPage The maximum number of results per page (10 by default)
  *
  * @return sfDoctrineFinderPager The initialized pager object
  */
 public function paginate($page = 1, $maxPerPage = 10)
 {
     // Children of sfDoctrinePager don't have a $class property, so we need to guess it
     $pager = new sfDoctrineFinderPager($this->class, $maxPerPage);
     $pager->setFinder($this);
     $pager->setPage($page);
     $pager->init();
     return $pager;
 }
$articles = $pager->getResults();
$t->is(count($articles), 2, 'sfDoctrineFinder::paginate() returns a pager object from which items can be retrieved');
$t->isa_ok(@$articles[0], 'DArticle', 'sfDoctrineFinder::paginate() returns a pager object from which items can be retrieved');

$pager = sfDoctrineFinder::from('DArticle')->
  where('Title', 'like', 'tt%')->
  paginate(1, 2);
  
$t->is($pager->getNbResults(), 4, 'sfDoctrineFinder::paginate() sfDoctrineFinder::paginate() uses the internal conditions');
$t->is($pager->getLastPage(), 2, 'sfDoctrineFinder::paginate() sfDoctrineFinder::paginate() uses the internal conditions');
$t->is($pager->getFirstIndice(), 1, 'sfDoctrineFinder::paginate() sfDoctrineFinder::paginate() uses the internal conditions');

$t->diag('sfDoctrineFinderPager issues with GroupBy');
$finder = sfDoctrineFinder::from('DArticle')->groupBy('Title');
$pager = new sfDoctrineFinderPager('DArticle', 2);
$pager->setFinder($finder);
$pager->init();
//$t->is($finder->getLatestQuery(), 'SELECT COUNT(DISTINCT d.id) AS num_results FROM d_article d', 'sfDoctrineFinderPager::init() removes groupBy clauses and issues a count()');
$t->skip('sfDoctrineFinderPager::init() removes groupBy clauses and issues a count() (bug in sfDoctrinePager)');
$pager->getResults();
$t->is($finder->getLatestQuery(), 'SELECT d.id AS d__id, d.title AS d__title, d.category_id AS d__category_id FROM d_article d GROUP BY d.title LIMIT 2', 'sfDoctrineFinderPager::getResults() does not remove groupBy clauses and issues a select()');

$t->diag('sfDoctrineFinderPager issues with object finders classes');
class DArticleFinder extends sfDoctrineFinder
{
  protected $class = 'DArticle';
}
$finder = new DArticleFinder();
try
{
  $pager = $finder->paginate();