Passed
Push — master ( 696880...94f8a0 )
by WEBEWEB
03:25
created

DataTablesLoopTest::testIsLast()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 5
c 3
b 1
f 0
dl 0
loc 9
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the jquery-datatables-bundle package.
5
 *
6
 * (c) 2022 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\JQuery\DataTablesBundle\Tests\Model;
13
14
use WBW\Bundle\JQuery\DataTablesBundle\Entity\DataTablesEntityInterface;
15
use WBW\Bundle\JQuery\DataTablesBundle\Model\DataTablesLoop;
16
use WBW\Bundle\JQuery\DataTablesBundle\Tests\AbstractTestCase;
17
18
/**
19
 * DataTables loop test.
20
 *
21
 * @author webeweb <https://github.com/webeweb>
22
 * @package WBW\Bundle\JQuery\DataTablesBundle\Tests\Model
23
 */
24
class DataTablesLoopTest extends AbstractTestCase {
25
26
    /**
27
     * Entities.
28
     *
29
     * @var object[]|null
30
     */
31
    private $entities;
32
33
    protected function setUp(): void {
34
        parent::setUp();
35
36
        // Set an entities mock.
37
        $this->entities = [
38
            $this->getMockBuilder(DataTablesEntityInterface::class)->getMock(), // 0
39
            $this->getMockBuilder(DataTablesEntityInterface::class)->getMock(), // 1
40
            $this->getMockBuilder(DataTablesEntityInterface::class)->getMock(), // 2
41
            $this->getMockBuilder(DataTablesEntityInterface::class)->getMock(), // 3
42
            $this->getMockBuilder(DataTablesEntityInterface::class)->getMock(), // 4
43
            $this->getMockBuilder(DataTablesEntityInterface::class)->getMock(), // 5
44
            $this->getMockBuilder(DataTablesEntityInterface::class)->getMock(), // 6
45
            $this->getMockBuilder(DataTablesEntityInterface::class)->getMock(), // 7
46
            $this->getMockBuilder(DataTablesEntityInterface::class)->getMock(), // 8
47
        ];
48
    }
49
50
    /**
51
     * Test isFirst()
52
     *
53
     * @return void
54
     */
55
    public function testIsFirst(): void {
56
57
        $entities = array_slice($this->entities, 0,2);
0 ignored issues
show
Bug introduced by
It seems like $this->entities can also be of type null; however, parameter $array of array_slice() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
        $entities = array_slice(/** @scrutinizer ignore-type */ $this->entities, 0,2);
Loading history...
58
59
        $obj = new DataTablesLoop($entities);
60
61
        $this->assertTrue($obj->isFirst());
62
        $this->assertFalse($obj->isLast());
63
    }
64
65
    /**
66
     * Test isLast()
67
     *
68
     * @return void
69
     */
70
    public function testIsLast(): void {
71
72
        $entities = array_slice($this->entities, 0,2);
0 ignored issues
show
Bug introduced by
It seems like $this->entities can also be of type null; however, parameter $array of array_slice() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

72
        $entities = array_slice(/** @scrutinizer ignore-type */ $this->entities, 0,2);
Loading history...
73
74
        $obj = new DataTablesLoop($entities);
75
        $obj->next();
76
77
        $this->assertTrue($obj->isLast());
78
        $this->assertFalse($obj->isFirst());
79
    }
80
81
    /**
82
     * Test next()
83
     *
84
     * @return void
85
     */
86
    public function testNext(): void {
87
88
        $obj = new DataTablesLoop($this->entities);
0 ignored issues
show
Bug introduced by
It seems like $this->entities can also be of type null; however, parameter $entities of WBW\Bundle\JQuery\DataTa...blesLoop::__construct() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

88
        $obj = new DataTablesLoop(/** @scrutinizer ignore-type */ $this->entities);
Loading history...
89
90
        $obj->next();
91
        $this->assertEquals(2, $obj->getIndex());
92
        $this->assertEquals(1, $obj->getIndex0());
93
        $this->assertEquals(8, $obj->getRevIndex());
94
        $this->assertEquals(7, $obj->getRevIndex0());
95
    }
96
97
    /**
98
     * Test __construct()
99
     *
100
     * @return void
101
     */
102
    public function test__construct(): void {
103
104
        $obj = new DataTablesLoop($this->entities);
0 ignored issues
show
Bug introduced by
It seems like $this->entities can also be of type null; however, parameter $entities of WBW\Bundle\JQuery\DataTa...blesLoop::__construct() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

104
        $obj = new DataTablesLoop(/** @scrutinizer ignore-type */ $this->entities);
Loading history...
105
106
        $this->assertEquals($this->entities, $obj->getEntities());
107
        $this->assertEquals(1, $obj->getIndex());
108
        $this->assertEquals(0, $obj->getIndex0());
109
        $this->assertEquals(9, $obj->getLength());
110
        $this->assertEquals(9, $obj->getRevIndex());
111
        $this->assertEquals(8, $obj->getRevIndex0());
112
    }
113
}
114