Completed
Push — master ( c8728b...09f7f1 )
by Denis
01:22
created

SimpleTest::testCorrectBuilding()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 8 and the first side effect is on line 6.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
use PHPUnit\Framework\TestCase;
4
use dekor\ArrayToTextTable;
5
6
include __DIR__ . '/../src/ArrayToTextTable.php';
7
8
class SimpleTest extends TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
{
10
    /**
11
     * @dataProvider getCases
12
     */
13
    public function testCorrectBuilding($data, $expectResult)
14
    {
15
        $builder = new dekor\ArrayToTextTable($data);
16
17
        $this->assertEquals($expectResult, $builder->render());
18
    }
19
20
    public function getCases()
21
    {
22
        return [
23
            [
24
                'data' => [
25
                    [
26
                        'id' => 1,
27
                        'name' => 'Denis Koronets',
28
                        'role' => 'php developer',
29
                    ],
30
                    [
31
                        'id' => 2,
32
                        'name' => 'Maxim Ambroskin',
33
                        'role' => 'java developer',
34
                    ],
35
                    [
36
                        'id' => 3,
37
                        'name' => 'Andrew Sikorsky',
38
                        'role' => 'php developer',
39
                    ]
40
                ],
41
                'expected' =>
42
                    '+----+-----------------+----------------+' . PHP_EOL .
43
                    '| id | name            | role           |' . PHP_EOL .
44
                    '+----+-----------------+----------------+' . PHP_EOL .
45
                    '| 1  | Denis Koronets  | php developer  |' . PHP_EOL .
46
                    '| 2  | Maxim Ambroskin | java developer |' . PHP_EOL .
47
                    '| 3  | Andrew Sikorsky | php developer  |' . PHP_EOL .
48
                    '+----+-----------------+----------------+',
49
            ],
50
            [
51
                'data' => [
52
                    [
53
                        'singleColumn' => 'test value',
54
                    ],
55
                ],
56
                'expected' =>
57
                    '+--------------+' . PHP_EOL .
58
                    '| singleColumn |' . PHP_EOL .
59
                    '+--------------+' . PHP_EOL .
60
                    '| test value   |' . PHP_EOL .
61
                    '+--------------+',
62
            ],
63
            [
64
                'data' => [
65
                    [
66
                        'id' => 1,
67
                        'name' => 'Денис Коронец',
68
                        'role' => 'Тест кириллических символов',
69
                    ],
70
                ],
71
                'expected' =>
72
                    '+----+---------------+-----------------------------+' . PHP_EOL .
73
                    '| id | name          | role                        |' . PHP_EOL .
74
                    '+----+---------------+-----------------------------+' . PHP_EOL .
75
                    '| 1  | Денис Коронец | Тест кириллических символов |' . PHP_EOL .
76
                    '+----+---------------+-----------------------------+',
77
            ],
78
            [
79
                'data' => [
80
                    [
81
                        'id' => 1,
82
                        'name' => 'Денис Коронец',
83
                        'role' => 'Тест кириллических символов',
84
                    ],
85
                    '---',
86
                    [
87
                        'id' => 2,
88
                        'name' => 'Артем Малеев',
89
                        'role' => 'Тест кириллических символов 2',
90
                    ],
91
                ],
92
                'expected' =>
93
                    '+----+---------------+-------------------------------+' . PHP_EOL .
94
                    '| id | name          | role                          |' . PHP_EOL .
95
                    '+----+---------------+-------------------------------+' . PHP_EOL .
96
                    '| 1  | Денис Коронец | Тест кириллических символов   |' . PHP_EOL .
97
                    '+----+---------------+-------------------------------+' . PHP_EOL .
98
                    '| 2  | Артем Малеев  | Тест кириллических символов 2 |' . PHP_EOL .
99
                    '+----+---------------+-------------------------------+',
100
            ],
101
        ];
102
    }
103
}