Passed
Pull Request — 2.6 (#7803)
by
unknown
07:11
created

GH7805Test::testPaginationWithFunction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 18
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\ORM\Functional\Ticket;
6
7
use Doctrine\ORM\Tools\Pagination\Paginator;
8
use Doctrine\Tests\Models\CMS\CmsArticle;
9
use Doctrine\Tests\OrmFunctionalTestCase;
10
use function count;
11
use function iterator_to_array;
12
13
class GH7805Test extends OrmFunctionalTestCase
14
{
15
    protected function setUp()
16
    {
17
        $this->useModelSet('cms');
18
        parent::setUp();
19
    }
20
21
    public function testPaginationWithFunction()
22
    {
23
        $article = new CmsArticle();
24
25
        $article->topic   = 'Test ORDER BY with Function';
26
        $article->text    = 'This test fails on MySQL if ORDER BY part is not added to SELECT.';
27
        $article->version = 1;
28
29
        $this->_em->persist($article);
30
        $this->_em->flush();
31
32
        $query = $this->_em->createQuery('SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a ORDER BY SQRT(a.version) ASC');
33
        $query->setFirstResult(0);
34
        $query->setMaxResults(1);
35
36
        $paginator = new Paginator($query, true);
37
        $paginator->setUseOutputWalkers(false);
38
        $this->assertEquals(1, count(iterator_to_array($paginator)));
39
    }
40
41
    public function testPaginationWithSimpleArithmetic()
42
    {
43
        $article = new CmsArticle();
44
45
        $article->topic   = 'Test ORDER BY with SimpleArithmetic';
46
        $article->text    = 'This test fails on MySQL if ORDER BY part is not added to SELECT.';
47
        $article->version = 1;
48
49
        $this->_em->persist($article);
50
        $this->_em->flush();
51
52
        $query = $this->_em->createQuery('SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a ORDER BY a.version + 0 ASC');
53
        $query->setFirstResult(0);
54
        $query->setMaxResults(1);
55
56
        $paginator = new Paginator($query, true);
57
        $paginator->setUseOutputWalkers(false);
58
        $this->assertEquals(1, count(iterator_to_array($paginator)));
59
    }
60
}
61