Passed
Push — master ( 9ccabb...39bdf1 )
by Petr
07:56
created

ConnectTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 33
c 1
b 0
f 0
dl 0
loc 71
rs 10
wmc 5
1
<?php
2
3
namespace ArraysTests;
4
5
6
use CommonTestClass;
7
use kalanis\kw_connect\arrays;
8
use kalanis\kw_connect\core\ConnectException;
9
use kalanis\kw_connect\core\Interfaces\IOrder;
10
11
12
class ConnectTest extends CommonTestClass
13
{
14
    /**
15
     * @throws ConnectException
16
     */
17
    public function testConnector1()
18
    {
19
        $lib = new arrays\Connector($this->sourceRows()); // no PK
20
        $lib->setFiltering('pqr', arrays\Filters\Factory::ACTION_EXACT, true);
21
        $lib->setOrdering('jkl', IOrder::ORDER_DESC);
22
        $lib->setPagination(2, 2);
23
        $lib->fetchData();
24
        $this->assertEquals(4, $lib->getTotalCount());
25
    }
26
27
    /**
28
     * @throws ConnectException
29
     */
30
    public function testConnectorData1()
31
    {
32
        $lib = new arrays\Connector($this->sourceRows()); // no PK
33
        $lib->setOrdering('jkl', IOrder::ORDER_ASC);
34
        $lib->fetchData();
35
        $this->assertEquals(9, $lib->getTotalCount());
36
        $content = iterator_to_array($lib);
37
        $this->assertEquals('josh', $content[0]->getValue('def'));
38
        $this->assertEquals('ewan', $content[1]->getValue('def'));
39
        $this->assertEquals('dave', $content[2]->getValue('def'));
40
        $this->assertEquals('kami', $content[3]->getValue('def'));
41
    }
42
43
    /**
44
     * @throws ConnectException
45
     */
46
    public function testConnectorData2()
47
    {
48
        $lib = new arrays\Connector($this->sourceRows()); // no PK
49
        $lib->setOrdering('jkl', IOrder::ORDER_DESC);
50
        $lib->fetchData();
51
        $this->assertEquals(9, $lib->getTotalCount());
52
        $content = iterator_to_array($lib);
53
        $this->assertEquals('emil', $content[0]->getValue('def'));
54
        $this->assertEquals('wayne', $content[1]->getValue('def'));
55
        $this->assertEquals('john', $content[2]->getValue('def'));
56
        $this->assertEquals('chuck', $content[3]->getValue('def'));
57
    }
58
59
    /**
60
     * @throws ConnectException
61
     */
62
    public function testConnector2()
63
    {
64
        $lib = new arrays\Connector($this->sourceRows(), 'abc'); // with PK
65
        $lib->setFiltering('pqr', arrays\Filters\Factory::ACTION_MULTIPLE, [ // value
66
            [ // row with another filter -> filter type, value to compare
67
                arrays\Filters\Factory::ACTION_MULTIPLE, [ // another multiple with its inner filters as array in value
68
                    [arrays\Filters\Factory::ACTION_EXACT, false], // inner filters in multiple filter -> filter type, value to compare
69
                ]
70
            ],
71
        ]);
72
        $lib->setOrdering('jkl', IOrder::ORDER_ASC);
73
        $this->assertEquals(5, $lib->getTotalCount());
74
    }
75
76
    /**
77
     * @throws ConnectException
78
     */
79
    public function testConnector3()
80
    {
81
        $lib = new arrays\Connector([]); // empty source
82
        $this->assertEquals(0, $lib->getTotalCount());
83
    }
84
}
85