1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
<?php
declare(strict_types=1);
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\ORM\Tools\Pagination\Paginator;
use Doctrine\Tests\Models\DDC117\DDC117Article;
use Doctrine\Tests\Models\DDC117\DDC117ArticleDetails;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit\Framework\Attributes\Group;
use RuntimeException;
#[Group('DDC-1685')]
class DDC1685Test extends OrmFunctionalTestCase
{
private Paginator $paginator;
protected function setUp(): void
{
$this->useModelSet('ddc117');
parent::setUp();
$this->_em->createQuery('DELETE FROM Doctrine\Tests\Models\DDC117\DDC117ArticleDetails ad')->execute();
$article = new DDC117Article('Foo');
$this->_em->persist($article);
$this->_em->flush();
$articleDetails = new DDC117ArticleDetails($article, 'Very long text');
$this->_em->persist($articleDetails);
$this->_em->flush();
$dql = 'SELECT ad FROM Doctrine\Tests\Models\DDC117\DDC117ArticleDetails ad';
$query = $this->_em->createQuery($dql);
$query->setMaxResults(1);
$this->paginator = new Paginator($query);
}
public function testPaginateCount(): void
{
self::assertCount(1, $this->paginator);
}
public function testPaginateIterate(): void
{
foreach ($this->paginator as $ad) {
self::assertInstanceOf(DDC117ArticleDetails::class, $ad);
}
}
public function testPaginateCountNoOutputWalkers(): void
{
$this->paginator->setUseOutputWalkers(false);
self::assertCount(1, $this->paginator);
}
public function testPaginateIterateNoOutputWalkers(): void
{
$this->paginator->setUseOutputWalkers(false);
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Paginating an entity with foreign key as identifier only works when using the Output Walkers. Call Paginator#setUseOutputWalkers(true) before iterating the paginator.');
foreach ($this->paginator as $ad) {
self::assertInstanceOf(DDC117ArticleDetails::class, $ad);
}
}
}
|