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
|
|
|
class ConvertCaseTransformerTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
public function testCaseModeUpperConstant () : void |
12
|
|
|
{ |
13
|
|
|
$expectedValue = MB_CASE_UPPER; |
14
|
|
|
$actualValue = ConvertCaseTransformer::CONVERT_CASE_MODE_UPPER; |
15
|
|
|
|
16
|
|
|
$this->assertEquals( $expectedValue, $actualValue ); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function testCaseModeLowerConstant () : void |
20
|
|
|
{ |
21
|
|
|
$expectedValue = MB_CASE_LOWER; |
22
|
|
|
$actualValue = ConvertCaseTransformer::CONVERT_CASE_MODE_LOWER; |
23
|
|
|
|
24
|
|
|
$this->assertEquals( $expectedValue, $actualValue ); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testCaseModeTitleConstant () : void |
28
|
|
|
{ |
29
|
|
|
$expectedValue = MB_CASE_TITLE; |
30
|
|
|
$actualValue = ConvertCaseTransformer::CONVERT_CASE_MODE_TITLE; |
31
|
|
|
|
32
|
|
|
$this->assertEquals( $expectedValue, $actualValue ); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testTransformRowModeUpperAllColumns () : void |
36
|
|
|
{ |
37
|
|
|
$transformer = new ConvertCaseTransformer(); |
38
|
|
|
$transformer->options( [ "columns" => [ "id", "name" ], "encoding" => "UTF-8", "mode" => ConvertCaseTransformer::CONVERT_CASE_MODE_UPPER ] ); |
39
|
|
|
|
40
|
|
|
$givenRow = new Row( [ "id" => 1, "name" => "John Doe" ] ); |
41
|
|
|
|
42
|
|
|
$transformer->transform( $givenRow ); |
43
|
|
|
|
44
|
|
|
$expectedRow = new Row( [ "ID" => 1, "NAME" => "John Doe" ] ); |
45
|
|
|
|
46
|
|
|
$this->assertEquals( $expectedRow, $givenRow ); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testTransformRowModeUpperSomeColumns () : void |
50
|
|
|
{ |
51
|
|
|
$transformer = new ConvertCaseTransformer(); |
52
|
|
|
$transformer->options( [ "columns" => [ "id" ], "encoding" => "UTF-8", "mode" => ConvertCaseTransformer::CONVERT_CASE_MODE_UPPER ] ); |
53
|
|
|
|
54
|
|
|
$givenRow = new Row( [ "id" => 1, "name" => "John Doe" ] ); |
55
|
|
|
|
56
|
|
|
$transformer->transform( $givenRow ); |
57
|
|
|
|
58
|
|
|
$expectedRow = new Row( [ "ID" => 1, "name" => "John Doe" ] ); |
59
|
|
|
|
60
|
|
|
$this->assertEquals( $expectedRow, $givenRow ); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|