Passed
Push — master ( 62264f...226050 )
by Petr
08:16
created

FuncColumnTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 10
c 0
b 0
f 0
dl 0
loc 31
rs 10
1
<?php
2
3
namespace coreTests\Columns;
4
5
6
use CommonTestClass;
7
use kalanis\kw_connect\arrays\Row;
8
use kalanis\kw_connect\core\ConnectException;
9
use kalanis\kw_table\core\Table\Columns;
10
11
12
class FuncColumnTest extends CommonTestClass
13
{
14
    /**
15
     * @throws ConnectException
16
     */
17
    public function testFunc(): void
18
    {
19
        $lib = new Columns\Func('name', [$this, 'columnCallback'], ['x' => 'ytzz']);
20
        $this->assertEquals('>==> defytzz', $lib->getValue($this->getRow()));
21
    }
22
23
    /**
24
     * @throws ConnectException
25
     */
26
    public function testEscFunc(): void
27
    {
28
        $lib = new Columns\EscFunc('name', [$this, 'columnCallback']);
29
        $this->assertEquals('>==> def', $lib->getValue($this->getRow()));
30
    }
31
32
    protected function getRow(): Row
33
    {
34
        return new Row(['id' => 2, 'name' => 'def', 'desc' => '<lang_to_"convert">', 'size' => 456, 'enabled' => 0]);
35
    }
36
37
    public function columnCallback(...$params): string
38
    {
39
        $first = reset($params);
40
        $next = next($params);
41
        $next = (false !== $next) ? $next : '';
42
        return '>==> ' . strval($first) . strval($next);
43
    }
44
}
45