PorpaginasAdapterTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 35
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A it_iterates_slice() 0 16 1
A it_counts_total_number_of_results() 0 9 1
1
<?php
2
3
namespace Zenstruck\Porpaginas\Tests\Bridge\Pagerfanta;
4
5
use Pagerfanta\Pagerfanta;
6
use PHPUnit\Framework\TestCase;
7
use Zenstruck\Porpaginas\Arrays\ArrayResult;
8
use Zenstruck\Porpaginas\Bridge\Pagerfanta\PorpaginasAdapter;
9
10
class PorpaginasAdapterTest extends TestCase
11
{
12
    /**
13
     * @test
14
     */
15
    public function it_counts_total_number_of_results(): void
16
    {
17
        $pagerfanta = new Pagerfanta(
18
            new PorpaginasAdapter(
19
                new ArrayResult([1, 2, 3, 4])
20
            )
21
        );
22
23
        $this->assertEquals(4, $pagerfanta->getNbResults());
24
    }
25
26
    /**
27
     * @test
28
     */
29
    public function it_iterates_slice(): void
30
    {
31
        $pagerfanta = new Pagerfanta(
32
            new PorpaginasAdapter(
33
                new ArrayResult([1, 2, 3, 4])
34
            )
35
        );
36
37
        $pagerfanta->setMaxPerPage(2);
38
        $pagerfanta->setCurrentPage(1);
39
40
        $this->assertEquals([1, 2], \iterator_to_array($pagerfanta->getCurrentPageResults()));
41
42
        $pagerfanta->setCurrentPage(2);
43
44
        $this->assertEquals([3, 4], \iterator_to_array($pagerfanta->getCurrentPageResults()));
45
    }
46
}
47