ConvertCaseTransformerTest   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 149
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 72
c 2
b 0
f 0
dl 0
loc 149
rs 10
wmc 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A testTransformRowModeUpperAllColumns() 0 16 1
A testCaseModeTitleConstant() 0 6 1
A testCaseModeLowerConstant() 0 6 1
A setUp() 0 8 1
A testTransformRowModeLowerAllColumns() 0 16 1
A testCaseModeUpperConstant() 0 6 1
A testTransformRowModeLowerSomeColumns() 0 16 1
A testTransformRowModeUpperSomeColumns() 0 16 1
A testTransformRowModeTitleSomeColumns() 0 16 1
A testTransformRowModeTitleAllColumns() 0 16 1
1
<?php
2
3
namespace Coco\SourceWatcher\Tests\Core\Transformers;
4
5
use Coco\SourceWatcher\Core\Row;
6
use Coco\SourceWatcher\Core\Transformers\ConvertCaseTransformer;
7
use PHPUnit\Framework\TestCase;
8
9
/**
10
 * Class ConvertCaseTransformerTest
11
 *
12
 * @package Coco\SourceWatcher\Tests\Core\Transformers
13
 */
14
class ConvertCaseTransformerTest extends TestCase
15
{
16
    public string $columnsIndex;
17
18
    public string $encodingIndex;
19
    public string $encodingUTF_8;
20
21
    public string $johnDoe;
22
23
    public function setUp () : void
24
    {
25
        $this->columnsIndex = "columns";
26
27
        $this->encodingIndex = "encoding";
28
        $this->encodingUTF_8 = "UTF-8";
29
30
        $this->johnDoe = "John Doe";
31
    }
32
33
    public function testCaseModeUpperConstant () : void
34
    {
35
        $expectedValue = MB_CASE_UPPER;
36
        $actualValue = ConvertCaseTransformer::CONVERT_CASE_MODE_UPPER;
37
38
        $this->assertEquals( $expectedValue, $actualValue );
39
    }
40
41
    public function testCaseModeLowerConstant () : void
42
    {
43
        $expectedValue = MB_CASE_LOWER;
44
        $actualValue = ConvertCaseTransformer::CONVERT_CASE_MODE_LOWER;
45
46
        $this->assertEquals( $expectedValue, $actualValue );
47
    }
48
49
    public function testCaseModeTitleConstant () : void
50
    {
51
        $expectedValue = MB_CASE_TITLE;
52
        $actualValue = ConvertCaseTransformer::CONVERT_CASE_MODE_TITLE;
53
54
        $this->assertEquals( $expectedValue, $actualValue );
55
    }
56
57
    public function testTransformRowModeUpperAllColumns () : void
58
    {
59
        $transformer = new ConvertCaseTransformer();
60
        $transformer->options( [
61
            $this->columnsIndex => [ "id", "name" ],
62
            $this->encodingIndex => $this->encodingUTF_8,
63
            "mode" => ConvertCaseTransformer::CONVERT_CASE_MODE_UPPER
64
        ] );
65
66
        $givenRow = new Row( [ "id" => 1, "name" => $this->johnDoe ] );
67
68
        $transformer->transform( $givenRow );
69
70
        $expectedRow = new Row( [ "ID" => 1, "NAME" => $this->johnDoe ] );
71
72
        $this->assertEquals( $expectedRow, $givenRow );
73
    }
74
75
    public function testTransformRowModeUpperSomeColumns () : void
76
    {
77
        $transformer = new ConvertCaseTransformer();
78
        $transformer->options( [
79
            $this->columnsIndex => [ "id" ],
80
            $this->encodingIndex => $this->encodingUTF_8,
81
            "mode" => ConvertCaseTransformer::CONVERT_CASE_MODE_UPPER
82
        ] );
83
84
        $givenRow = new Row( [ "id" => 1, "name" => $this->johnDoe ] );
85
86
        $transformer->transform( $givenRow );
87
88
        $expectedRow = new Row( [ "ID" => 1, "name" => $this->johnDoe ] );
89
90
        $this->assertEquals( $expectedRow, $givenRow );
91
    }
92
93
    public function testTransformRowModeLowerAllColumns () : void
94
    {
95
        $transformer = new ConvertCaseTransformer();
96
        $transformer->options( [
97
            $this->columnsIndex => [ "ID", "NAME" ],
98
            $this->encodingIndex => $this->encodingUTF_8,
99
            "mode" => ConvertCaseTransformer::CONVERT_CASE_MODE_LOWER
100
        ] );
101
102
        $givenRow = new Row( [ "ID" => 1, "NAME" => $this->johnDoe ] );
103
104
        $transformer->transform( $givenRow );
105
106
        $expectedRow = new Row( [ "id" => 1, "name" => $this->johnDoe ] );
107
108
        $this->assertEquals( $expectedRow, $givenRow );
109
    }
110
111
    public function testTransformRowModeLowerSomeColumns () : void
112
    {
113
        $transformer = new ConvertCaseTransformer();
114
        $transformer->options( [
115
            $this->columnsIndex => [ "ID" ],
116
            $this->encodingIndex => $this->encodingUTF_8,
117
            "mode" => ConvertCaseTransformer::CONVERT_CASE_MODE_LOWER
118
        ] );
119
120
        $givenRow = new Row( [ "ID" => 1, "NAME" => $this->johnDoe ] );
121
122
        $transformer->transform( $givenRow );
123
124
        $expectedRow = new Row( [ "id" => 1, "NAME" => $this->johnDoe ] );
125
126
        $this->assertEquals( $expectedRow, $givenRow );
127
    }
128
129
    public function testTransformRowModeTitleAllColumns () : void
130
    {
131
        $transformer = new ConvertCaseTransformer();
132
        $transformer->options( [
133
            $this->columnsIndex => [ "id", "name" ],
134
            $this->encodingIndex => $this->encodingUTF_8,
135
            "mode" => ConvertCaseTransformer::CONVERT_CASE_MODE_TITLE
136
        ] );
137
138
        $givenRow = new Row( [ "id" => 1, "name" => $this->johnDoe ] );
139
140
        $transformer->transform( $givenRow );
141
142
        $expectedRow = new Row( [ "Id" => 1, "Name" => $this->johnDoe ] );
143
144
        $this->assertEquals( $expectedRow, $givenRow );
145
    }
146
147
    public function testTransformRowModeTitleSomeColumns () : void
148
    {
149
        $transformer = new ConvertCaseTransformer();
150
        $transformer->options( [
151
            $this->columnsIndex => [ "id" ],
152
            $this->encodingIndex => $this->encodingUTF_8,
153
            "mode" => ConvertCaseTransformer::CONVERT_CASE_MODE_TITLE
154
        ] );
155
156
        $givenRow = new Row( [ "id" => 1, "name" => $this->johnDoe ] );
157
158
        $transformer->transform( $givenRow );
159
160
        $expectedRow = new Row( [ "Id" => 1, "name" => $this->johnDoe ] );
161
162
        $this->assertEquals( $expectedRow, $givenRow );
163
    }
164
}
165