Test Failed
Branch master (9acec7)
by Agel_Nash
02:58
created

DLAbstract   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
dl 0
loc 62
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A fixDebugSQL() 0 11 3
B mockDocLister() 0 36 2
1
<?php namespace DocLister\Tests\DL;
2
3
use DocLister\Tests\ModxAbstract;
4
5
abstract class DLAbstract extends ModxAbstract
6
{
7
    /** @var \DocLister */
8
    protected $DL = null;
9
10
11
    public function setUp()
12
    {
13
        parent::setUp();
14
15
        $this->DL = $this->mockDocLister();
16
    }
17
18
    protected function mockDocLister($controller = null, array $cfg = array())
19
    {
20
        $cfg = array_merge(array('debug' => 0), $cfg);
21
        if (empty($controller)) {
22
            /** @var \DocLister|\PHPUnit_Framework_MockObject_MockObject $DL */
23
            $DL = $this->getMockForAbstractClass('DocLister', array($this->modx, $cfg));
24
            $DL->expects($this->any())
25
                ->method('getUrl')
26
                ->will($this->returnValue('url'));
27
28
            $DL->expects($this->any())
29
                ->method('getDocs')
30
                ->will($this->returnValue(array()));
31
32
            $DL->expects($this->any())
33
                ->method('_render')
34
                ->will($this->returnValue('example text'));
35
36
            $DL->expects($this->any())
37
                ->method('getChildrenCount')
38
                ->will($this->returnValue(0));
39
40
            $DL->expects($this->any())
41
                ->method('getChildrenFolder')
42
                ->will($this->returnValue(0));
43
        } else {
44
            /** @var \DocLister|\PHPUnit_Framework_MockObject_MockObject $DL */
45
            $DL = $this->getMock($controller . 'DocLister', array('sanitarData'), array($this->modx, $cfg));
46
        }
47
48
        /** Чтобы в debug хранились не экранированные результаты */
49
        $DL->expects($this->any())
50
            ->method('sanitarData')
51
            ->will($this->returnArgument(0));
52
53
        return $DL;
54
    }
55
56
    protected function fixDebugSQL($data)
57
    {
58
        if (is_array($data)) {
59
            foreach ($data as &$val) {
60
                $val = $this->fixDebugSQL($val);
61
            }
62
        } else {
63
            $data = preg_replace('/\s+/', ' ', $data);
64
        }
65
66
        return $data;
67
    }
68
}