Skip to content

Commit

Permalink
Added tests for paginator query builder with different service
Browse files Browse the repository at this point in the history
  • Loading branch information
dnapierata committed Jul 18, 2017
1 parent bbd7753 commit 6fa4749
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/_data/models/Robos.php
@@ -0,0 +1,27 @@
<?php

namespace Phalcon\Test\Models;

use Phalcon\Mvc\Model;

/**
* Robos
*
* "Robôs" is robots in portuguese
*
* @author David Napierata
*
* @package Phalcon\Test\Models
*/
class Robos extends Model
{
public function getSource()
{
return 'robots';
}

public function initialize()
{
$this->setConnectionService('dbTwo');
}
}
38 changes: 38 additions & 0 deletions tests/unit/Paginator/Adapter/QueryBuilderTest.php
Expand Up @@ -5,6 +5,7 @@
use Helper\ModelTrait;
use Phalcon\Di;
use Phalcon\Paginator\Adapter\QueryBuilder;
use Phalcon\Test\Models\Robos;
use Phalcon\Test\Models\Stock;
use Phalcon\Test\Module\UnitTest;

Expand Down Expand Up @@ -132,4 +133,41 @@ function () {
}
);
}

/**
* Tests query builder pagination with having and group with a different db service than 'db'
*
* @author David Napierata
* @since 2017-07-18
*/
public function testIssue12957()
{
$this->specify(
"Query builder paginator doesn't work correctly with a different db service",
function () {
$modelsManager = $this->setUpModelsManager();
$di = $modelsManager->getDI();
$di->set(
'dbTwo',
$di->get('db')
);
$builder = $modelsManager->createBuilder()
->columns("COUNT(*) as robos_count")
->from(['Robos' => Robos::class])
->groupBy('type')
->having('MAX(Robos.year) > 1970');

$paginate = (new QueryBuilder(
[
"builder" => $builder,
"limit" => 1,
"page" => 2
]
))->getPaginate();

expect($paginate->total_pages)->equals(2);
expect($paginate->total_items)->equals(2);
}
);
}
}

0 comments on commit 6fa4749

Please sign in to comment.