Passed
Push — master ( e90ce7...2823ca )
by Kyle
02:25 queued 11s
created

testLengthWithoutSuffixesEmptyStringWithConfiguredSubtractSuffix()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of PHP Mess Detector.
4
 *
5
 * Copyright (c) Manuel Pichler <[email protected]>.
6
 * All rights reserved.
7
 *
8
 * Licensed under BSD License
9
 * For full copyright and license information, please see the LICENSE file.
10
 * Redistributions of files must retain the above copyright notice.
11
 *
12
 * @author Manuel Pichler <[email protected]>
13
 * @copyright Manuel Pichler. All rights reserved.
14
 * @license https://opensource.org/licenses/bsd-license.php BSD License
15
 * @link http://phpmd.org/
16
 */
17
18
namespace PHPMD\Utility;
19
20
use PHPMD\AbstractTest;
21
use PHPMD\Utility\Strings;
22
23
/**
24
 * Test cases for the Strings utility class.
25
 *
26
 * @coversDefaultClass  \PHPMD\Utility\Strings
27
 */
28
class StringsTest extends AbstractTest
29
{
30
    /**
31
     * Tests the lengthWithoutSuffixes() method with an empty string
32
     *
33
     * @return void
34
     */
35
    public function testLengthWithoutSuffixesEmptyString()
36
    {
37
        static::assertSame(0, Strings::lengthWithoutSuffixes('', array()));
38
    }
39
40
    /**
41
     * Tests the lengthWithoutSuffixes() method with an empty string with list of suffixes
42
     *
43
     * @return void
44
     */
45
    public function testLengthWithoutSuffixesEmptyStringWithConfiguredSubtractSuffix()
46
    {
47
        static::assertSame(0, Strings::lengthWithoutSuffixes('', array('Foo', 'Bar')));
48
    }
49
50
    /**
51
     * Tests the lengthWithoutSuffixes() method with a string not in the list of suffixes
52
     *
53
     * @return void
54
     */
55
    public function testLengthWithoutSuffixesStringWithoutSubtractSuffixMatch()
56
    {
57
        static::assertSame(8, Strings::lengthWithoutSuffixes('UnitTest', array('Foo', 'Bar')));
58
    }
59
60
    /**
61
     * Tests the lengthWithoutSuffixes() method with a string in the list of suffixes
62
     *
63
     * @return void
64
     */
65
    public function testLengthWithoutSuffixesStringWithSubtractSuffixMatch()
66
    {
67
        static::assertSame(4, Strings::lengthWithoutSuffixes('UnitBar', array('Foo', 'Bar')));
68
    }
69
70
    /**
71
     * Tests the lengthWithoutSuffixes() method with a string that should match only once for two potential matches
72
     *
73
     * @return void
74
     */
75
    public function testLengthWithoutSuffixesStringWithDoubleSuffixMatchSubtractOnce()
76
    {
77
        static::assertSame(7, Strings::lengthWithoutSuffixes('UnitFooBar', array('Foo', 'Bar')));
78
    }
79
80
    /**
81
     * Tests the lengthWithoutSuffixes() method that a Prefix should not be matched
82
     *
83
     * @return void
84
     */
85
    public function testLengthWithoutSuffixesStringWithPrefixMatchShouldNotSubtract()
86
    {
87
        static::assertSame(11, Strings::lengthWithoutSuffixes('FooUnitTest', array('Foo', 'Bar')));
88
    }
89
90
    /**
91
     * Tests the splitToList() method with an empty separator
92
     *
93
     * @expectedException \InvalidArgumentException
94
     *
95
     * @return void
96
     */
97
    public function testSplitToListEmptySeparatorThrowsException()
98
    {
99
        Strings::splitToList('UnitTest', '');
100
    }
101
102
    /**
103
     * Tests the splitToList() method with an empty string
104
     *
105
     * @return void
106
     */
107
    public function testSplitToListEmptyString()
108
    {
109
        static::assertSame(array(), Strings::splitToList('', ','));
110
    }
111
112
    /**
113
     * Tests the splitToList() method with a non-matching separator
114
     *
115
     * @return void
116
     */
117
    public function testSplitToListStringWithoutMatchingSeparator()
118
    {
119
        static::assertSame(array('UnitTest'), Strings::splitToList('UnitTest', ','));
120
    }
121
122
    /**
123
     * Tests the splitToList() method with a matching separator
124
     *
125
     * @return void
126
     */
127
    public function testSplitToListStringWithMatchingSeparator()
128
    {
129
        static::assertSame(array('Unit', 'Test'), Strings::splitToList('Unit,Test', ','));
130
    }
131
132
    /**
133
     * Tests the splitToList() method with trailing whitespace
134
     *
135
     * @return void
136
     */
137
    public function testSplitToListStringTrimsLeadingAndTrailingWhitespace()
138
    {
139
        static::assertSame(array('Unit', 'Test'), Strings::splitToList('Unit , Test', ','));
140
    }
141
142
    /**
143
     * Tests the splitToList() method that it removes empty strings from list
144
     *
145
     * @return void
146
     */
147
    public function testSplitToListStringRemoveEmptyStringValues()
148
    {
149
        static::assertSame(array('Foo'), Strings::splitToList('Foo,,,', ','));
150
    }
151
152
    /**
153
     * Tests the splitToList() method that it does not remove zero values from list
154
     *
155
     * @return void
156
     */
157
    public function testSplitToListStringShouldNotRemoveAZeroValue()
158
    {
159
        static::assertSame(array('0', '1', '2'), Strings::splitToList('0,1,2', ','));
160
    }
161
}
162