Passed
Push — master ( a93856...cd5d8d )
by Sven
01:47
created

StringUtilsTest::testConvertToBool()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
namespace Bedd\Common;
3
4
/**
5
 * StringUtilsTest
6
 */
7
class StringUtilsTest extends TestCase
8
{
9
    public function splitOnUpperCaseProvider()
10
    {
11
        return [
12
            ['hallo welt', ['hallo welt']],
13
            ['Hallo Welt', ['Hallo ', 'Welt']],
14
            ['WurstFingerTest', ['Wurst', 'Finger', 'Test']],
15
            ['Wurst_Finger_Test', ['Wurst_', 'Finger_', 'Test']],
16
            ['TOLLESACHE', ['T', 'O', 'L', 'L', 'E', 'S', 'A', 'C', 'H', 'E']],
17
        ];
18
    }
19
    /**
20
     * Test for Bedd\Common\StringUtils::splitOnUpperCase
21
     * @dataProvider splitOnUpperCaseProvider
22
     */
23
    public function testSplitOnUpperCase($input, $expected)
24
    {
25
        $this->assertEquals($expected, StringUtils::splitOnUpperCase($input));
26
    }
27
28
    public function splitOnLowerCaseProvider()
29
    {
30
        return [
31
            ['HALLO WELT', ['HALLO WELT']],
32
            ['hALLO wELT', ['hALLO ', 'wELT']],
33
            ['wURSTfINGERtEST', ['wURST', 'fINGER', 'tEST']],
34
            ['tollesache', ['t', 'o', 'l', 'l', 'e', 's', 'a', 'c', 'h', 'e']],
35
        ];
36
    }
37
    /**
38
     * Test for Bedd\Common\StringUtils::splitOnLowerCase
39
     * @dataProvider splitOnLowerCaseProvider
40
     */
41
    public function testSplitOnLowerrCase($input, $expected)
42
    {
43
        $this->assertEquals($expected, StringUtils::splitOnLowerCase($input));
44
    }
45
46
    public function startsWithProvider()
47
    {
48
        return [
49
            //positive
50
            ['', '', true],
51
            ['Hallo Welt', 'Hal', true],
52
            ['Hallo Welt', '', true],
53
            [' Hallo Welt', ' ', true],
54
            [123, '1', true],
55
            //negative
56
            ['', 'Welt', false],
57
            ['Hallo Welt', 'hallo', false],
58
            ['Hallo Welt', ' ', false],
59
        ];
60
    }
61
    /**
62
     * Test for Bedd\Common\StringUtils::startsWith
63
     * @dataProvider startsWithProvider
64
     */
65
    public function testStartsWith($string, $query, $expected)
66
    {
67
        $this->assertEquals($expected, StringUtils::startsWith($string, $query));
68
    }
69
70
    public function endsWithProvider()
71
    {
72
        return [
73
            //positive
74
            ['', '', true],
75
            ['Hallo Welt', 'Welt', true],
76
            ['Hallo Welt', '', true],
77
            ['Hallo Welt ', ' ', true],
78
            [123, '3', true],
79
            //negative
80
            ['', 'Welt', false],
81
            ['Hallo Welt', 'welt', false],
82
            ['Hallo Welt', ' ', false],
83
        ];
84
    }
85
    /**
86
     * Test for Bedd\Common\StringUtils::startsWith
87
     * @dataProvider endsWithProvider
88
     */
89
    public function testEndsWith($string, $query, $expected)
90
    {
91
        $this->assertEquals($expected, StringUtils::endsWith($string, $query));
92
    }
93
    
94
    public function convertToBoolProvider()
95
    {
96
        return [
97
            //true
98
            ['true', false, true],
99
            ['ja', false, true],
100
            ['YES', false, true],
101
            ['1', false, true],
102
            ['wurst', true, true],
103
            [null, true, true],
104
            //false
105
            ['false', true, false],
106
            ['nein', false, false],
107
            ['0', false, false],
108
            ['no', true, false],
109
            ['NO', true, false],
110
            [0, true, false],
111
        ];
112
    }
113
    /**
114
     * Test for Bedd\Common\StringUtils::convertToBool
115
     * @dataProvider convertToBoolProvider
116
     */
117
    public function testConvertToBool($string, $default, $expected)
118
    {
119
        $this->assertEquals($expected, StringUtils::convertToBool($string, $default));
120
    }
121
}
122