Completed
Push — master ( 384b33...e90045 )
by Dmitry
02:56
created

ConverterTest::validateArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

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 4
nc 1
nop 1
1
<?php
2
3
namespace Test;
4
5
use Basis\Converter;
6
use Basis\Test;
7
8
class ConverterTest extends Test
9
{
10
    public function testArrays()
11
    {
12
        $this->validateArray([]);
13
        $this->validateArray(['name' => 'tester']);
14
        $this->validateArray(['name' => null]);
15
        $this->validateArray(['config' => []]);
16
        $this->validateArray(['config' => ['a' => 1]]);
17
        $this->validateArray(['config' => ['a' => null]]);
18
        $this->validateArray(['config' => ['a' => null, 'b' => [1]]]);
19
        $this->validateArray(['config' => ['a' => null, 'b' => [null]]]);
20
    }
21
22
    private function validateArray($array)
23
    {
24
        $object = $this->app->get(Converter::class)->toObject($array);
25
        $candidate = $this->app->get(Converter::class)->toArray($object);
26
        $this->assertSame($array, $candidate);
27
    }
28
29
    public function testStrings()
30
    {
31
        $converter = $this->app->get(Converter::class);
32
        $this->assertSame($converter, $this->app->get(Converter::class));
33
34
        $this->assertSame('a', $converter->toCamelCase('a'));
35
        $this->assertSame('A', $converter->toCamelCase('a', true));
36
37
        $this->assertSame('personState', $converter->toCamelCase('person_state'));
38
        $this->assertSame('PersonState', $converter->toCamelCase('person_state', true));
39
40
        $this->assertSame('person_role', $converter->toUnderscore('personRole'));
41
        $this->assertSame('person_role', $converter->toUnderscore('PersonRole'));
42
43
        $this->assertSame('test', $converter->toObject(['test' => 'test'])->test);
44
        $this->assertSame(['gateway', 'audit'], $converter->toObject([
45
            'names' => ['gateway', 'audit']
46
        ])->names);
47
    }
48
}
49