CanvasTest::testInsertY()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 28

Duplication

Lines 28
Ratio 100 %

Importance

Changes 0
Metric Value
dl 28
loc 28
rs 9.472
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
namespace Mathielen\ReportWriteEngine\Engine;
3
4
class CanvasTest extends \PHPUnit_Framework_TestCase
5
{
6
7
    public function testCanvas()
8
    {
9
        $canvas = new Canvas();
10
        $canvas[1][0] = 'a';
11
        $canvas[2][0] = 'X';
12
        $canvas[3][0] = 'Y';
13
        $canvas[4][0] = 'c';
14
15
        $canvasB = new Canvas();
16
        $canvasB[1][0] = 'b';
17
18
        $canvas->insert($canvasB, 2, 0, 2);
19
20
        $this->assertEquals([
21
            1 => ['a'],
22
            2 => ['b'],
23
            3 => ['c'],
24
            4 => ['c'] //TODO fix me! must be removed
25
        ], $canvas->getArrayCopy());
26
    }
27
28
    public function testCanvasVertical()
29
    {
30
        $canvas = new Canvas();
31
        $canvas[1][0] = '0';
32
        $canvas[2][1] = 'X';
33
        $canvas[2][2] = 'Y';
34
        $canvas[1][3] = '4';
35
        $canvas[1][4] = '5';
36
37
        $canvasB = new Canvas();
38
        $canvasB[1][0] = '1';
39
        $canvasB[1][1] = '2';
40
        $canvasB[1][2] = '3';
41
42
        $canvas->insert($canvasB, 1, 1, 1, 2);
43
44
        $this->assertEquals([
45
            1 => [0, 1, 2, 3, 5],
46
            2 => [1 => 'X', 2 => 'Y']
47
        ], $canvas->getArrayCopy());
48
    }
49
50
    /**
51
     * @dataProvider getInsertYData
52
     */
53 View Code Duplication
    public function testInsertY($y, $h, array $expectedData)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
    {
55
        $from = [
56
            0 => [
57
                0 => 'A',
58
                1 => 'B',
59
                2 => 'C'
60
            ],
61
            1 => [
62
                0 => 'D',
63
                1 => 'E',
64
                2 => 'F'
65
            ]
66
        ];
67
        $from = new Canvas(null, $from);
68
69
        $to = [
70
            0 => [
71
                0 => 'X',
72
                1 => 'Y',
73
                2 => 'Z'
74
            ]
75
        ];
76
        $to = new Canvas(null, $to);
77
78
        $from->insert($to, $y, 0, $h, 0);
79
        $this->assertEquals($expectedData, $from->getArrayCopy());
80
    }
81
82
    public function getInsertYData()
83
    {
84
        return [
85
            [
86
                1, 0,
87
                [
88
                    0 => [
89
                        0 => 'A',
90
                        1 => 'B',
91
                        2 => 'C'
92
                    ],
93
                    1 => [
94
                        0 => 'X',
95
                        1 => 'Y',
96
                        2 => 'Z'
97
                    ],
98
                    2 => [
99
                        0 => 'D',
100
                        1 => 'E',
101
                        2 => 'F'
102
                    ]
103
                ]
104
            ],
105
            [
106
                2, 0,
107
                [
108
                    0 => [
109
                        0 => 'A',
110
                        1 => 'B',
111
                        2 => 'C'
112
                    ],
113
                    1 => [
114
                        0 => 'D',
115
                        1 => 'E',
116
                        2 => 'F'
117
                    ],
118
                    2 => [
119
                        0 => 'X',
120
                        1 => 'Y',
121
                        2 => 'Z'
122
                    ],
123
                ]
124
            ],
125
            [
126
                0, 2,
127
                [
128
                    0 => [
129
                        0 => 'X',
130
                        1 => 'Y',
131
                        2 => 'Z'
132
                    ],
133
                ]
134
            ]
135
        ];
136
    }
137
138
    /**
139
     * @dataProvider getInsertXData
140
     */
141 View Code Duplication
    public function testInsertX($x, $w, array $expectedData)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
142
    {
143
        $from = [
144
            0 => [
145
                0 => 'A',
146
                1 => 'B',
147
                2 => 'C'
148
            ],
149
            1 => [
150
                0 => 'D',
151
                1 => 'E',
152
                2 => 'F'
153
            ]
154
        ];
155
        $from = new Canvas(null, $from);
156
157
        $to = [
158
            0 => [
159
                0 => 'X',
160
                1 => 'Y',
161
                2 => 'Z'
162
            ]
163
        ];
164
        $to = new Canvas(null, $to);
165
166
        $from->insert($to, 0, $x, 0, $w);
167
168
        $this->assertEquals($expectedData, $from->getArrayCopy());
169
    }
170
171
    public function getInsertXData()
172
    {
173
        return [
174
            [
175
                1, 0,
176
                [
177
                    0 => [
178
                        0 => 'A',
179
                        1 => 'X',
180
                        2 => 'Y',
181
                        3 => 'Z',
182
                    ],
183
                    1 => [
184
                        0 => 'D',
185
                        1 => 'E',
186
                        2 => 'F'
187
                    ]
188
                ]
189
            ],
190
            [
191
                2, 0,
192
                [
193
                    0 => [
194
                        0 => 'A',
195
                        1 => 'B',
196
                        2 => 'X',
197
                        3 => 'Y',
198
                        4 => 'Z',
199
                    ],
200
                    1 => [
201
                        0 => 'D',
202
                        1 => 'E',
203
                        2 => 'F'
204
                    ]
205
                ]
206
            ]
207
        ];
208
    }
209
210
}
211