1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
require __DIR__ . '/../src/Stringy.php'; |
4
|
|
|
|
5
|
|
|
use Stringy\Stringy as S; |
6
|
|
|
|
7
|
|
|
class StringyTestCase extends PHPUnit_Framework_TestCase |
|
|
|
|
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Asserts that a variable is of a Stringy instance. |
11
|
|
|
* |
12
|
|
|
* @param mixed $actual |
13
|
|
|
*/ |
14
|
|
|
public function assertStringy($actual) |
15
|
|
|
{ |
16
|
|
|
$this->assertInstanceOf('Stringy\Stringy', $actual); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
View Code Duplication |
public function testConstruct() |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
$stringy = new S('foo bar', 'UTF-8'); |
22
|
|
|
$this->assertStringy($stringy); |
23
|
|
|
$this->assertEquals('foo bar', (string) $stringy); |
24
|
|
|
$this->assertEquals('UTF-8', $stringy->getEncoding()); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testEmptyConstruct() |
28
|
|
|
{ |
29
|
|
|
$stringy = new S(); |
30
|
|
|
$this->assertStringy($stringy); |
31
|
|
|
$this->assertEquals('', (string) $stringy); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @expectedException InvalidArgumentException |
36
|
|
|
*/ |
37
|
|
|
public function testConstructWithArray() |
38
|
|
|
{ |
39
|
|
|
(string) new S(array()); |
40
|
|
|
$this->fail('Expecting exception when the constructor is passed an array'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @expectedException InvalidArgumentException |
45
|
|
|
*/ |
46
|
|
|
public function testMissingToString() |
47
|
|
|
{ |
48
|
|
|
(string) new S(new stdClass()); |
49
|
|
|
$this->fail('Expecting exception when the constructor is passed an ' . |
50
|
|
|
'object without a __toString method'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @dataProvider toStringProvider() |
55
|
|
|
*/ |
56
|
|
|
public function testToString($expected, $str) |
57
|
|
|
{ |
58
|
|
|
$this->assertEquals($expected, (string) new S($str)); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function toStringProvider() |
62
|
|
|
{ |
63
|
|
|
return array( |
64
|
|
|
array('', null), |
65
|
|
|
array('', false), |
66
|
|
|
array('1', true), |
67
|
|
|
array('-9', -9), |
68
|
|
|
array('1.18', 1.18), |
69
|
|
|
array(' string ', ' string ') |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
View Code Duplication |
public function testCreate() |
|
|
|
|
74
|
|
|
{ |
75
|
|
|
$stringy = S::create('foo bar', 'UTF-8'); |
76
|
|
|
$this->assertStringy($stringy); |
77
|
|
|
$this->assertEquals('foo bar', (string) $stringy); |
78
|
|
|
$this->assertEquals('UTF-8', $stringy->getEncoding()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function testChaining() |
82
|
|
|
{ |
83
|
|
|
$stringy = S::create("Fòô Bàř", 'UTF-8'); |
84
|
|
|
$this->assertStringy($stringy); |
85
|
|
|
$result = $stringy->collapseWhitespace()->swapCase()->upperCaseFirst(); |
86
|
|
|
$this->assertEquals('FÒÔ bÀŘ', $result); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function testCount() |
90
|
|
|
{ |
91
|
|
|
$stringy = S::create('Fòô', 'UTF-8'); |
92
|
|
|
$this->assertEquals(3, $stringy->count()); |
93
|
|
|
$this->assertEquals(3, count($stringy)); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function testGetIterator() |
97
|
|
|
{ |
98
|
|
|
$stringy = S::create('Fòô Bàř', 'UTF-8'); |
99
|
|
|
|
100
|
|
|
$valResult = array(); |
101
|
|
|
foreach ($stringy as $char) { |
102
|
|
|
$valResult[] = $char; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
$keyValResult = array(); |
106
|
|
|
foreach ($stringy as $pos => $char) { |
107
|
|
|
$keyValResult[$pos] = $char; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
$this->assertEquals(array('F', 'ò', 'ô', ' ', 'B', 'à', 'ř'), $valResult); |
111
|
|
|
$this->assertEquals(array('F', 'ò', 'ô', ' ', 'B', 'à', 'ř'), $keyValResult); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @dataProvider offsetExistsProvider() |
116
|
|
|
*/ |
117
|
|
|
public function testOffsetExists($expected, $offset) |
118
|
|
|
{ |
119
|
|
|
$stringy = S::create('fòô', 'UTF-8'); |
120
|
|
|
$this->assertEquals($expected, $stringy->offsetExists($offset)); |
121
|
|
|
$this->assertEquals($expected, isset($stringy[$offset])); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function offsetExistsProvider() |
125
|
|
|
{ |
126
|
|
|
return array( |
127
|
|
|
array(true, 0), |
128
|
|
|
array(true, 2), |
129
|
|
|
array(false, 3), |
130
|
|
|
array(true, -1), |
131
|
|
|
array(true, -3), |
132
|
|
|
array(false, -4) |
133
|
|
|
); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function testOffsetGet() |
137
|
|
|
{ |
138
|
|
|
$stringy = S::create('fòô', 'UTF-8'); |
139
|
|
|
|
140
|
|
|
$this->assertEquals('f', $stringy->offsetGet(0)); |
141
|
|
|
$this->assertEquals('ô', $stringy->offsetGet(2)); |
142
|
|
|
|
143
|
|
|
$this->assertEquals('ô', $stringy[2]); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @expectedException \OutOfBoundsException |
148
|
|
|
*/ |
149
|
|
|
public function testOffsetGetOutOfBounds() |
150
|
|
|
{ |
151
|
|
|
$stringy = S::create('fòô', 'UTF-8'); |
152
|
|
|
$test = $stringy[3]; |
|
|
|
|
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @expectedException \Exception |
157
|
|
|
*/ |
158
|
|
|
public function testOffsetSet() |
159
|
|
|
{ |
160
|
|
|
$stringy = S::create('fòô', 'UTF-8'); |
161
|
|
|
$stringy[1] = 'invalid'; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @expectedException \Exception |
166
|
|
|
*/ |
167
|
|
|
public function testOffsetUnset() |
168
|
|
|
{ |
169
|
|
|
$stringy = S::create('fòô', 'UTF-8'); |
170
|
|
|
unset($stringy[1]); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @dataProvider indexOfProvider() |
175
|
|
|
*/ |
176
|
|
|
public function testIndexOf($expected, $str, $subStr, $offset = 0, $encoding = null) |
177
|
|
|
{ |
178
|
|
|
$result = S::create($str, $encoding)->indexOf($subStr, $offset); |
179
|
|
|
$this->assertEquals($expected, $result); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
View Code Duplication |
public function indexOfProvider() |
|
|
|
|
183
|
|
|
{ |
184
|
|
|
return array( |
185
|
|
|
array(6, 'foo & bar', 'bar'), |
186
|
|
|
array(6, 'foo & bar', 'bar', 0), |
187
|
|
|
array(false, 'foo & bar', 'baz'), |
188
|
|
|
array(false, 'foo & bar', 'baz', 0), |
189
|
|
|
array(0, 'foo & bar & foo', 'foo', 0), |
190
|
|
|
array(12, 'foo & bar & foo', 'foo', 5), |
191
|
|
|
array(6, 'fòô & bàř', 'bàř', 0, 'UTF-8'), |
192
|
|
|
array(false, 'fòô & bàř', 'baz', 0, 'UTF-8'), |
193
|
|
|
array(0, 'fòô & bàř & fòô', 'fòô', 0, 'UTF-8'), |
194
|
|
|
array(12, 'fòô & bàř & fòô', 'fòô', 5, 'UTF-8'), |
195
|
|
|
); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @dataProvider indexOfLastProvider() |
200
|
|
|
*/ |
201
|
|
|
public function testIndexOfLast($expected, $str, $subStr, $offset = 0, $encoding = null) |
202
|
|
|
{ |
203
|
|
|
$result = S::create($str, $encoding)->indexOfLast($subStr, $offset); |
204
|
|
|
$this->assertEquals($expected, $result); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
View Code Duplication |
public function indexOfLastProvider() |
|
|
|
|
208
|
|
|
{ |
209
|
|
|
return array( |
210
|
|
|
array(6, 'foo & bar', 'bar'), |
211
|
|
|
array(6, 'foo & bar', 'bar', 0), |
212
|
|
|
array(false, 'foo & bar', 'baz'), |
213
|
|
|
array(false, 'foo & bar', 'baz', 0), |
214
|
|
|
array(12, 'foo & bar & foo', 'foo', 0), |
215
|
|
|
array(0, 'foo & bar & foo', 'foo', -5), |
216
|
|
|
array(6, 'fòô & bàř', 'bàř', 0, 'UTF-8'), |
217
|
|
|
array(false, 'fòô & bàř', 'baz', 0, 'UTF-8'), |
218
|
|
|
array(12, 'fòô & bàř & fòô', 'fòô', 0, 'UTF-8'), |
219
|
|
|
array(0, 'fòô & bàř & fòô', 'fòô', -5, 'UTF-8'), |
220
|
|
|
); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* @dataProvider appendProvider() |
225
|
|
|
*/ |
226
|
|
|
public function testAppend($expected, $str, $string, $encoding = null) |
227
|
|
|
{ |
228
|
|
|
$result = S::create($str, $encoding)->append($string); |
229
|
|
|
$this->assertStringy($result); |
230
|
|
|
$this->assertEquals($expected, $result); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
View Code Duplication |
public function appendProvider() |
|
|
|
|
234
|
|
|
{ |
235
|
|
|
return array( |
236
|
|
|
array('foobar', 'foo', 'bar'), |
237
|
|
|
array('fòôbàř', 'fòô', 'bàř', 'UTF-8') |
238
|
|
|
); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* @dataProvider prependProvider() |
243
|
|
|
*/ |
244
|
|
|
public function testPrepend($expected, $str, $string, $encoding = null) |
245
|
|
|
{ |
246
|
|
|
$result = S::create($str, $encoding)->prepend($string); |
247
|
|
|
$this->assertStringy($result); |
248
|
|
|
$this->assertEquals($expected, $result); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
View Code Duplication |
public function prependProvider() |
|
|
|
|
252
|
|
|
{ |
253
|
|
|
return array( |
254
|
|
|
array('foobar', 'bar', 'foo'), |
255
|
|
|
array('fòôbàř', 'bàř', 'fòô', 'UTF-8') |
256
|
|
|
); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* @dataProvider charsProvider() |
261
|
|
|
*/ |
262
|
|
|
public function testChars($expected, $str, $encoding = null) |
263
|
|
|
{ |
264
|
|
|
$result = S::create($str, $encoding)->chars(); |
265
|
|
|
$this->assertInternalType('array', $result); |
266
|
|
|
foreach ($result as $char) { |
267
|
|
|
$this->assertInternalType('string', $char); |
268
|
|
|
} |
269
|
|
|
$this->assertEquals($expected, $result); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
public function charsProvider() |
273
|
|
|
{ |
274
|
|
|
return array( |
275
|
|
|
array(array(), ''), |
276
|
|
|
array(array('T', 'e', 's', 't'), 'Test'), |
277
|
|
|
array(array('F', 'ò', 'ô', ' ', 'B', 'à', 'ř'), 'Fòô Bàř', 'UTF-8') |
278
|
|
|
); |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* @dataProvider linesProvider() |
283
|
|
|
*/ |
284
|
|
|
public function testLines($expected, $str, $encoding = null) |
285
|
|
|
{ |
286
|
|
|
$result = S::create($str, $encoding)->lines(); |
287
|
|
|
|
288
|
|
|
$this->assertInternalType('array', $result); |
289
|
|
|
foreach ($result as $line) { |
290
|
|
|
$this->assertStringy($line); |
291
|
|
|
} |
292
|
|
|
|
293
|
|
View Code Duplication |
for ($i = 0; $i < count($expected); $i++) { |
|
|
|
|
294
|
|
|
$this->assertEquals($expected[$i], $result[$i]); |
295
|
|
|
} |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
public function linesProvider() |
299
|
|
|
{ |
300
|
|
|
return array( |
301
|
|
|
array(array(), ""), |
302
|
|
|
array(array(''), "\r\n"), |
303
|
|
|
array(array('foo', 'bar'), "foo\nbar"), |
304
|
|
|
array(array('foo', 'bar'), "foo\rbar"), |
305
|
|
|
array(array('foo', 'bar'), "foo\r\nbar"), |
306
|
|
|
array(array('foo', '', 'bar'), "foo\r\n\r\nbar"), |
307
|
|
|
array(array('foo', 'bar', ''), "foo\r\nbar\r\n"), |
308
|
|
|
array(array('', 'foo', 'bar'), "\r\nfoo\r\nbar"), |
309
|
|
|
array(array('fòô', 'bàř'), "fòô\nbàř", 'UTF-8'), |
310
|
|
|
array(array('fòô', 'bàř'), "fòô\rbàř", 'UTF-8'), |
311
|
|
|
array(array('fòô', 'bàř'), "fòô\n\rbàř", 'UTF-8'), |
312
|
|
|
array(array('fòô', 'bàř'), "fòô\r\nbàř", 'UTF-8'), |
313
|
|
|
array(array('fòô', '', 'bàř'), "fòô\r\n\r\nbàř", 'UTF-8'), |
314
|
|
|
array(array('fòô', 'bàř', ''), "fòô\r\nbàř\r\n", 'UTF-8'), |
315
|
|
|
array(array('', 'fòô', 'bàř'), "\r\nfòô\r\nbàř", 'UTF-8'), |
316
|
|
|
); |
317
|
|
|
} |
318
|
|
|
/** |
319
|
|
|
* @dataProvider upperCaseFirstProvider() |
320
|
|
|
*/ |
321
|
|
|
public function testUpperCaseFirst($expected, $str, $encoding = null) |
322
|
|
|
{ |
323
|
|
|
$result = S::create($str, $encoding)->upperCaseFirst(); |
324
|
|
|
$this->assertStringy($result); |
325
|
|
|
$this->assertEquals($expected, $result); |
326
|
|
|
} |
327
|
|
|
|
328
|
|
View Code Duplication |
public function upperCaseFirstProvider() |
|
|
|
|
329
|
|
|
{ |
330
|
|
|
return array( |
331
|
|
|
array('Test', 'Test'), |
332
|
|
|
array('Test', 'test'), |
333
|
|
|
array('1a', '1a'), |
334
|
|
|
array('Σ test', 'σ test', 'UTF-8'), |
335
|
|
|
array(' σ test', ' σ test', 'UTF-8') |
336
|
|
|
); |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
/** |
340
|
|
|
* @dataProvider lowerCaseFirstProvider() |
341
|
|
|
*/ |
342
|
|
|
public function testLowerCaseFirst($expected, $str, $encoding = null) |
343
|
|
|
{ |
344
|
|
|
$stringy = S::create($str, $encoding); |
345
|
|
|
$result = $stringy->lowerCaseFirst(); |
346
|
|
|
$this->assertStringy($result); |
347
|
|
|
$this->assertEquals($expected, $result); |
348
|
|
|
$this->assertEquals($str, $stringy); |
349
|
|
|
} |
350
|
|
|
|
351
|
|
View Code Duplication |
public function lowerCaseFirstProvider() |
|
|
|
|
352
|
|
|
{ |
353
|
|
|
return array( |
354
|
|
|
array('test', 'Test'), |
355
|
|
|
array('test', 'test'), |
356
|
|
|
array('1a', '1a'), |
357
|
|
|
array('σ test', 'Σ test', 'UTF-8'), |
358
|
|
|
array(' Σ test', ' Σ test', 'UTF-8') |
359
|
|
|
); |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
/** |
363
|
|
|
* @dataProvider camelizeProvider() |
364
|
|
|
*/ |
365
|
|
|
public function testCamelize($expected, $str, $encoding = null) |
366
|
|
|
{ |
367
|
|
|
$stringy = S::create($str, $encoding); |
368
|
|
|
$result = $stringy->camelize(); |
369
|
|
|
$this->assertStringy($result); |
370
|
|
|
$this->assertEquals($expected, $result); |
371
|
|
|
$this->assertEquals($str, $stringy); |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
public function camelizeProvider() |
375
|
|
|
{ |
376
|
|
|
return array( |
377
|
|
|
array('camelCase', 'CamelCase'), |
378
|
|
|
array('camelCase', 'Camel-Case'), |
379
|
|
|
array('camelCase', 'camel case'), |
380
|
|
|
array('camelCase', 'camel -case'), |
381
|
|
|
array('camelCase', 'camel - case'), |
382
|
|
|
array('camelCase', 'camel_case'), |
383
|
|
|
array('camelCTest', 'camel c test'), |
384
|
|
|
array('stringWith1Number', 'string_with1number'), |
385
|
|
|
array('stringWith22Numbers', 'string-with-2-2 numbers'), |
386
|
|
|
array('dataRate', 'data_rate'), |
387
|
|
|
array('backgroundColor', 'background-color'), |
388
|
|
|
array('yesWeCan', 'yes_we_can'), |
389
|
|
|
array('mozSomething', '-moz-something'), |
390
|
|
|
array('carSpeed', '_car_speed_'), |
391
|
|
|
array('serveHTTP', 'ServeHTTP'), |
392
|
|
|
array('1Camel2Case', '1camel2case'), |
393
|
|
|
array('camelΣase', 'camel σase', 'UTF-8'), |
394
|
|
|
array('στανιλCase', 'Στανιλ case', 'UTF-8'), |
395
|
|
|
array('σamelCase', 'σamel Case', 'UTF-8') |
396
|
|
|
); |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
/** |
400
|
|
|
* @dataProvider upperCamelizeProvider() |
401
|
|
|
*/ |
402
|
|
|
public function testUpperCamelize($expected, $str, $encoding = null) |
403
|
|
|
{ |
404
|
|
|
$stringy = S::create($str, $encoding); |
405
|
|
|
$result = $stringy->upperCamelize(); |
406
|
|
|
$this->assertStringy($result); |
407
|
|
|
$this->assertEquals($expected, $result); |
408
|
|
|
$this->assertEquals($str, $stringy); |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
public function upperCamelizeProvider() |
412
|
|
|
{ |
413
|
|
|
return array( |
414
|
|
|
array('CamelCase', 'camelCase'), |
415
|
|
|
array('CamelCase', 'Camel-Case'), |
416
|
|
|
array('CamelCase', 'camel case'), |
417
|
|
|
array('CamelCase', 'camel -case'), |
418
|
|
|
array('CamelCase', 'camel - case'), |
419
|
|
|
array('CamelCase', 'camel_case'), |
420
|
|
|
array('CamelCTest', 'camel c test'), |
421
|
|
|
array('StringWith1Number', 'string_with1number'), |
422
|
|
|
array('StringWith22Numbers', 'string-with-2-2 numbers'), |
423
|
|
|
array('1Camel2Case', '1camel2case'), |
424
|
|
|
array('CamelΣase', 'camel σase', 'UTF-8'), |
425
|
|
|
array('ΣτανιλCase', 'στανιλ case', 'UTF-8'), |
426
|
|
|
array('ΣamelCase', 'Σamel Case', 'UTF-8') |
427
|
|
|
); |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
/** |
431
|
|
|
* @dataProvider dasherizeProvider() |
432
|
|
|
*/ |
433
|
|
|
public function testDasherize($expected, $str, $encoding = null) |
434
|
|
|
{ |
435
|
|
|
$stringy = S::create($str, $encoding); |
436
|
|
|
$result = $stringy->dasherize(); |
437
|
|
|
$this->assertStringy($result); |
438
|
|
|
$this->assertEquals($expected, $result); |
439
|
|
|
$this->assertEquals($str, $stringy); |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
public function dasherizeProvider() |
443
|
|
|
{ |
444
|
|
|
return array( |
445
|
|
|
array('test-case', 'testCase'), |
446
|
|
|
array('test-case', 'Test-Case'), |
447
|
|
|
array('test-case', 'test case'), |
448
|
|
|
array('-test-case', '-test -case'), |
449
|
|
|
array('test-case', 'test - case'), |
450
|
|
|
array('test-case', 'test_case'), |
451
|
|
|
array('test-c-test', 'test c test'), |
452
|
|
|
array('test-d-case', 'TestDCase'), |
453
|
|
|
array('test-c-c-test', 'TestCCTest'), |
454
|
|
|
array('string-with1number', 'string_with1number'), |
455
|
|
|
array('string-with-2-2-numbers', 'String-with_2_2 numbers'), |
456
|
|
|
array('1test2case', '1test2case'), |
457
|
|
|
array('data-rate', 'dataRate'), |
458
|
|
|
array('car-speed', 'CarSpeed'), |
459
|
|
|
array('yes-we-can', 'yesWeCan'), |
460
|
|
|
array('background-color', 'backgroundColor'), |
461
|
|
|
array('dash-σase', 'dash Σase', 'UTF-8'), |
462
|
|
|
array('στανιλ-case', 'Στανιλ case', 'UTF-8'), |
463
|
|
|
array('σash-case', 'Σash Case', 'UTF-8') |
464
|
|
|
); |
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
/** |
468
|
|
|
* @dataProvider underscoredProvider() |
469
|
|
|
*/ |
470
|
|
|
public function testUnderscored($expected, $str, $encoding = null) |
471
|
|
|
{ |
472
|
|
|
$stringy = S::create($str, $encoding); |
473
|
|
|
$result = $stringy->underscored(); |
474
|
|
|
$this->assertStringy($result); |
475
|
|
|
$this->assertEquals($expected, $result); |
476
|
|
|
$this->assertEquals($str, $stringy); |
477
|
|
|
} |
478
|
|
|
|
479
|
|
|
public function underscoredProvider() |
480
|
|
|
{ |
481
|
|
|
return array( |
482
|
|
|
array('test_case', 'testCase'), |
483
|
|
|
array('test_case', 'Test-Case'), |
484
|
|
|
array('test_case', 'test case'), |
485
|
|
|
array('test_case', 'test -case'), |
486
|
|
|
array('_test_case', '-test - case'), |
487
|
|
|
array('test_case', 'test_case'), |
488
|
|
|
array('test_c_test', ' test c test'), |
489
|
|
|
array('test_u_case', 'TestUCase'), |
490
|
|
|
array('test_c_c_test', 'TestCCTest'), |
491
|
|
|
array('string_with1number', 'string_with1number'), |
492
|
|
|
array('string_with_2_2_numbers', 'String-with_2_2 numbers'), |
493
|
|
|
array('1test2case', '1test2case'), |
494
|
|
|
array('yes_we_can', 'yesWeCan'), |
495
|
|
|
array('test_σase', 'test Σase', 'UTF-8'), |
496
|
|
|
array('στανιλ_case', 'Στανιλ case', 'UTF-8'), |
497
|
|
|
array('σash_case', 'Σash Case', 'UTF-8') |
498
|
|
|
); |
499
|
|
|
} |
500
|
|
|
|
501
|
|
|
/** |
502
|
|
|
* @dataProvider delimitProvider() |
503
|
|
|
*/ |
504
|
|
View Code Duplication |
public function testDelimit($expected, $str, $delimiter, $encoding = null) |
|
|
|
|
505
|
|
|
{ |
506
|
|
|
$stringy = S::create($str, $encoding); |
507
|
|
|
$result = $stringy->delimit($delimiter); |
508
|
|
|
$this->assertStringy($result); |
509
|
|
|
$this->assertEquals($expected, $result); |
510
|
|
|
$this->assertEquals($str, $stringy); |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
public function delimitProvider() |
514
|
|
|
{ |
515
|
|
|
return array( |
516
|
|
|
array('test*case', 'testCase', '*'), |
517
|
|
|
array('test&case', 'Test-Case', '&'), |
518
|
|
|
array('test#case', 'test case', '#'), |
519
|
|
|
array('test**case', 'test -case', '**'), |
520
|
|
|
array('~!~test~!~case', '-test - case', '~!~'), |
521
|
|
|
array('test*case', 'test_case', '*'), |
522
|
|
|
array('test%c%test', ' test c test', '%'), |
523
|
|
|
array('test+u+case', 'TestUCase', '+'), |
524
|
|
|
array('test=c=c=test', 'TestCCTest', '='), |
525
|
|
|
array('string#>with1number', 'string_with1number', '#>'), |
526
|
|
|
array('1test2case', '1test2case', '*'), |
527
|
|
|
array('test ύα σase', 'test Σase', ' ύα ', 'UTF-8',), |
528
|
|
|
array('στανιλαcase', 'Στανιλ case', 'α', 'UTF-8',), |
529
|
|
|
array('σashΘcase', 'Σash Case', 'Θ', 'UTF-8') |
530
|
|
|
); |
531
|
|
|
} |
532
|
|
|
|
533
|
|
|
/** |
534
|
|
|
* @dataProvider swapCaseProvider() |
535
|
|
|
*/ |
536
|
|
|
public function testSwapCase($expected, $str, $encoding = null) |
537
|
|
|
{ |
538
|
|
|
$stringy = S::create($str, $encoding); |
539
|
|
|
$result = $stringy->swapCase(); |
540
|
|
|
$this->assertStringy($result); |
541
|
|
|
$this->assertEquals($expected, $result); |
542
|
|
|
$this->assertEquals($str, $stringy); |
543
|
|
|
} |
544
|
|
|
|
545
|
|
|
public function swapCaseProvider() |
546
|
|
|
{ |
547
|
|
|
return array( |
548
|
|
|
array('TESTcASE', 'testCase'), |
549
|
|
|
array('tEST-cASE', 'Test-Case'), |
550
|
|
|
array(' - σASH cASE', ' - Σash Case', 'UTF-8'), |
551
|
|
|
array('νΤΑΝΙΛ', 'Ντανιλ', 'UTF-8') |
552
|
|
|
); |
553
|
|
|
} |
554
|
|
|
|
555
|
|
|
/** |
556
|
|
|
* @dataProvider titleizeProvider() |
557
|
|
|
*/ |
558
|
|
|
public function testTitleize($expected, $str, $ignore = null, |
559
|
|
|
$encoding = null) |
560
|
|
|
{ |
561
|
|
|
$stringy = S::create($str, $encoding); |
562
|
|
|
$result = $stringy->titleize($ignore); |
563
|
|
|
$this->assertStringy($result); |
564
|
|
|
$this->assertEquals($expected, $result); |
565
|
|
|
$this->assertEquals($str, $stringy); |
566
|
|
|
} |
567
|
|
|
|
568
|
|
|
public function titleizeProvider() |
569
|
|
|
{ |
570
|
|
|
$ignore = array('at', 'by', 'for', 'in', 'of', 'on', 'out', 'to', 'the'); |
571
|
|
|
|
572
|
|
|
return array( |
573
|
|
|
array('Title Case', 'TITLE CASE'), |
574
|
|
|
array('Testing The Method', 'testing the method'), |
575
|
|
|
array('Testing the Method', 'testing the method', $ignore), |
576
|
|
|
array('I Like to Watch Dvds at Home', 'i like to watch DVDs at home', |
577
|
|
|
$ignore), |
578
|
|
|
array('Θα Ήθελα Να Φύγει', ' Θα ήθελα να φύγει ', null, 'UTF-8') |
579
|
|
|
); |
580
|
|
|
} |
581
|
|
|
|
582
|
|
|
/** |
583
|
|
|
* @dataProvider humanizeProvider() |
584
|
|
|
*/ |
585
|
|
|
public function testHumanize($expected, $str, $encoding = null) |
586
|
|
|
{ |
587
|
|
|
$stringy = S::create($str, $encoding); |
588
|
|
|
$result = $stringy->humanize(); |
589
|
|
|
$this->assertStringy($result); |
590
|
|
|
$this->assertEquals($expected, $result); |
591
|
|
|
$this->assertEquals($str, $stringy); |
592
|
|
|
} |
593
|
|
|
|
594
|
|
|
public function humanizeProvider() |
595
|
|
|
{ |
596
|
|
|
return array( |
597
|
|
|
array('Author', 'author_id'), |
598
|
|
|
array('Test user', ' _test_user_'), |
599
|
|
|
array('Συγγραφέας', ' συγγραφέας_id ', 'UTF-8') |
600
|
|
|
); |
601
|
|
|
} |
602
|
|
|
|
603
|
|
|
/** |
604
|
|
|
* @dataProvider tidyProvider() |
605
|
|
|
*/ |
606
|
|
|
public function testTidy($expected, $str) |
607
|
|
|
{ |
608
|
|
|
$stringy = S::create($str); |
609
|
|
|
$result = $stringy->tidy(); |
610
|
|
|
$this->assertStringy($result); |
611
|
|
|
$this->assertEquals($expected, $result); |
612
|
|
|
$this->assertEquals($str, $stringy); |
613
|
|
|
} |
614
|
|
|
|
615
|
|
|
public function tidyProvider() |
616
|
|
|
{ |
617
|
|
|
return array( |
618
|
|
|
array('"I see..."', '“I see…”'), |
619
|
|
|
array("'This too'", "‘This too’"), |
620
|
|
|
array('test-dash', 'test—dash'), |
621
|
|
|
array('Ο συγγραφέας είπε...', 'Ο συγγραφέας είπε…') |
622
|
|
|
); |
623
|
|
|
} |
624
|
|
|
|
625
|
|
|
/** |
626
|
|
|
* @dataProvider collapseWhitespaceProvider() |
627
|
|
|
*/ |
628
|
|
|
public function testCollapseWhitespace($expected, $str, $encoding = null) |
629
|
|
|
{ |
630
|
|
|
$stringy = S::create($str, $encoding); |
631
|
|
|
$result = $stringy->collapseWhitespace(); |
632
|
|
|
$this->assertStringy($result); |
633
|
|
|
$this->assertEquals($expected, $result); |
634
|
|
|
$this->assertEquals($str, $stringy); |
635
|
|
|
} |
636
|
|
|
|
637
|
|
|
public function collapseWhitespaceProvider() |
638
|
|
|
{ |
639
|
|
|
return array( |
640
|
|
|
array('foo bar', ' foo bar '), |
641
|
|
|
array('test string', 'test string'), |
642
|
|
|
array('Ο συγγραφέας', ' Ο συγγραφέας '), |
643
|
|
|
array('123', ' 123 '), |
644
|
|
|
array('', ' ', 'UTF-8'), // no-break space (U+00A0) |
645
|
|
|
array('', ' ', 'UTF-8'), // spaces U+2000 to U+200A |
646
|
|
|
array('', ' ', 'UTF-8'), // narrow no-break space (U+202F) |
647
|
|
|
array('', ' ', 'UTF-8'), // medium mathematical space (U+205F) |
648
|
|
|
array('', ' ', 'UTF-8'), // ideographic space (U+3000) |
649
|
|
|
array('1 2 3', ' 1 2 3 ', 'UTF-8'), |
650
|
|
|
array('', ' '), |
651
|
|
|
array('', ''), |
652
|
|
|
); |
653
|
|
|
} |
654
|
|
|
|
655
|
|
|
/** |
656
|
|
|
* @dataProvider toAsciiProvider() |
657
|
|
|
*/ |
658
|
|
|
public function testToAscii($expected, $str, $removeUnsupported = true) |
659
|
|
|
{ |
660
|
|
|
$stringy = S::create($str); |
661
|
|
|
$result = $stringy->toAscii($removeUnsupported); |
662
|
|
|
$this->assertStringy($result); |
663
|
|
|
$this->assertEquals($expected, $result); |
664
|
|
|
$this->assertEquals($str, $stringy); |
665
|
|
|
} |
666
|
|
|
|
667
|
|
|
public function toAsciiProvider() |
668
|
|
|
{ |
669
|
|
|
return array( |
670
|
|
|
array('foo bar', 'fòô bàř'), |
671
|
|
|
array(' TEST ', ' ŤÉŚŢ '), |
672
|
|
|
array('f = z = 3', 'φ = ź = 3'), |
673
|
|
|
array('perevirka', 'перевірка'), |
674
|
|
|
array('lysaya gora', 'лысая гора'), |
675
|
|
|
array('shchuka', 'щука'), |
676
|
|
|
array('', '漢字'), |
677
|
|
|
array('xin chao the gioi', 'xin chào thế giới'), |
678
|
|
|
array('XIN CHAO THE GIOI', 'XIN CHÀO THẾ GIỚI'), |
679
|
|
|
array('dam phat chet luon', 'đấm phát chết luôn'), |
680
|
|
|
array(' ', ' '), // no-break space (U+00A0) |
681
|
|
|
array(' ', ' '), // spaces U+2000 to U+200A |
682
|
|
|
array(' ', ' '), // narrow no-break space (U+202F) |
683
|
|
|
array(' ', ' '), // medium mathematical space (U+205F) |
684
|
|
|
array(' ', ' '), // ideographic space (U+3000) |
685
|
|
|
array('', '𐍉'), // some uncommon, unsupported character (U+10349) |
686
|
|
|
array('𐍉', '𐍉', false), |
687
|
|
|
); |
688
|
|
|
} |
689
|
|
|
|
690
|
|
|
/** |
691
|
|
|
* @dataProvider padProvider() |
692
|
|
|
*/ |
693
|
|
View Code Duplication |
public function testPad($expected, $str, $length, $padStr = ' ', |
|
|
|
|
694
|
|
|
$padType = 'right', $encoding = null) |
695
|
|
|
{ |
696
|
|
|
$stringy = S::create($str, $encoding); |
697
|
|
|
$result = $stringy->pad($length, $padStr, $padType); |
698
|
|
|
$this->assertStringy($result); |
699
|
|
|
$this->assertEquals($expected, $result); |
700
|
|
|
$this->assertEquals($str, $stringy); |
701
|
|
|
} |
702
|
|
|
|
703
|
|
|
public function padProvider() |
704
|
|
|
{ |
705
|
|
|
return array( |
706
|
|
|
// length <= str |
707
|
|
|
array('foo bar', 'foo bar', -1), |
708
|
|
|
array('foo bar', 'foo bar', 7), |
709
|
|
|
array('fòô bàř', 'fòô bàř', 7, ' ', 'right', 'UTF-8'), |
710
|
|
|
|
711
|
|
|
// right |
712
|
|
|
array('foo bar ', 'foo bar', 9), |
713
|
|
|
array('foo bar_*', 'foo bar', 9, '_*', 'right'), |
714
|
|
|
array('fòô bàř¬ø¬', 'fòô bàř', 10, '¬ø', 'right', 'UTF-8'), |
715
|
|
|
|
716
|
|
|
// left |
717
|
|
|
array(' foo bar', 'foo bar', 9, ' ', 'left'), |
718
|
|
|
array('_*foo bar', 'foo bar', 9, '_*', 'left'), |
719
|
|
|
array('¬ø¬fòô bàř', 'fòô bàř', 10, '¬ø', 'left', 'UTF-8'), |
720
|
|
|
|
721
|
|
|
// both |
722
|
|
|
array('foo bar ', 'foo bar', 8, ' ', 'both'), |
723
|
|
|
array('¬fòô bàř¬ø', 'fòô bàř', 10, '¬ø', 'both', 'UTF-8'), |
724
|
|
|
array('¬øfòô bàř¬øÿ', 'fòô bàř', 12, '¬øÿ', 'both', 'UTF-8') |
725
|
|
|
); |
726
|
|
|
} |
727
|
|
|
|
728
|
|
|
/** |
729
|
|
|
* @expectedException \InvalidArgumentException |
730
|
|
|
*/ |
731
|
|
|
public function testPadException() |
732
|
|
|
{ |
733
|
|
|
$stringy = S::create('foo'); |
734
|
|
|
$result = $stringy->pad(5, 'foo', 'bar'); |
|
|
|
|
735
|
|
|
} |
736
|
|
|
|
737
|
|
|
/** |
738
|
|
|
* @dataProvider padLeftProvider() |
739
|
|
|
*/ |
740
|
|
View Code Duplication |
public function testPadLeft($expected, $str, $length, $padStr = ' ', |
|
|
|
|
741
|
|
|
$encoding = null) |
742
|
|
|
{ |
743
|
|
|
$stringy = S::create($str, $encoding); |
744
|
|
|
$result = $stringy->padLeft($length, $padStr); |
745
|
|
|
$this->assertStringy($result); |
746
|
|
|
$this->assertEquals($expected, $result); |
747
|
|
|
$this->assertEquals($str, $stringy); |
748
|
|
|
} |
749
|
|
|
|
750
|
|
View Code Duplication |
public function padLeftProvider() |
|
|
|
|
751
|
|
|
{ |
752
|
|
|
return array( |
753
|
|
|
array(' foo bar', 'foo bar', 9), |
754
|
|
|
array('_*foo bar', 'foo bar', 9, '_*'), |
755
|
|
|
array('_*_foo bar', 'foo bar', 10, '_*'), |
756
|
|
|
array(' fòô bàř', 'fòô bàř', 9, ' ', 'UTF-8'), |
757
|
|
|
array('¬øfòô bàř', 'fòô bàř', 9, '¬ø', 'UTF-8'), |
758
|
|
|
array('¬ø¬fòô bàř', 'fòô bàř', 10, '¬ø', 'UTF-8'), |
759
|
|
|
array('¬ø¬øfòô bàř', 'fòô bàř', 11, '¬ø', 'UTF-8'), |
760
|
|
|
); |
761
|
|
|
} |
762
|
|
|
|
763
|
|
|
/** |
764
|
|
|
* @dataProvider padRightProvider() |
765
|
|
|
*/ |
766
|
|
View Code Duplication |
public function testPadRight($expected, $str, $length, $padStr = ' ', |
|
|
|
|
767
|
|
|
$encoding = null) |
768
|
|
|
{ |
769
|
|
|
$stringy = S::create($str, $encoding); |
770
|
|
|
$result = $stringy->padRight($length, $padStr); |
771
|
|
|
$this->assertStringy($result); |
772
|
|
|
$this->assertEquals($expected, $result); |
773
|
|
|
$this->assertEquals($str, $stringy); |
774
|
|
|
} |
775
|
|
|
|
776
|
|
View Code Duplication |
public function padRightProvider() |
|
|
|
|
777
|
|
|
{ |
778
|
|
|
return array( |
779
|
|
|
array('foo bar ', 'foo bar', 9), |
780
|
|
|
array('foo bar_*', 'foo bar', 9, '_*'), |
781
|
|
|
array('foo bar_*_', 'foo bar', 10, '_*'), |
782
|
|
|
array('fòô bàř ', 'fòô bàř', 9, ' ', 'UTF-8'), |
783
|
|
|
array('fòô bàř¬ø', 'fòô bàř', 9, '¬ø', 'UTF-8'), |
784
|
|
|
array('fòô bàř¬ø¬', 'fòô bàř', 10, '¬ø', 'UTF-8'), |
785
|
|
|
array('fòô bàř¬ø¬ø', 'fòô bàř', 11, '¬ø', 'UTF-8'), |
786
|
|
|
); |
787
|
|
|
} |
788
|
|
|
|
789
|
|
|
/** |
790
|
|
|
* @dataProvider padBothProvider() |
791
|
|
|
*/ |
792
|
|
View Code Duplication |
public function testPadBoth($expected, $str, $length, $padStr = ' ', |
|
|
|
|
793
|
|
|
$encoding = null) |
794
|
|
|
{ |
795
|
|
|
$stringy = S::create($str, $encoding); |
796
|
|
|
$result = $stringy->padBoth($length, $padStr); |
797
|
|
|
$this->assertStringy($result); |
798
|
|
|
$this->assertEquals($expected, $result); |
799
|
|
|
$this->assertEquals($str, $stringy); |
800
|
|
|
} |
801
|
|
|
|
802
|
|
|
public function padBothProvider() |
803
|
|
|
{ |
804
|
|
|
return array( |
805
|
|
|
array('foo bar ', 'foo bar', 8), |
806
|
|
|
array(' foo bar ', 'foo bar', 9, ' '), |
807
|
|
|
array('fòô bàř ', 'fòô bàř', 8, ' ', 'UTF-8'), |
808
|
|
|
array(' fòô bàř ', 'fòô bàř', 9, ' ', 'UTF-8'), |
809
|
|
|
array('fòô bàř¬', 'fòô bàř', 8, '¬ø', 'UTF-8'), |
810
|
|
|
array('¬fòô bàř¬', 'fòô bàř', 9, '¬ø', 'UTF-8'), |
811
|
|
|
array('¬fòô bàř¬ø', 'fòô bàř', 10, '¬ø', 'UTF-8'), |
812
|
|
|
array('¬øfòô bàř¬ø', 'fòô bàř', 11, '¬ø', 'UTF-8'), |
813
|
|
|
array('¬fòô bàř¬ø', 'fòô bàř', 10, '¬øÿ', 'UTF-8'), |
814
|
|
|
array('¬øfòô bàř¬ø', 'fòô bàř', 11, '¬øÿ', 'UTF-8'), |
815
|
|
|
array('¬øfòô bàř¬øÿ', 'fòô bàř', 12, '¬øÿ', 'UTF-8') |
816
|
|
|
); |
817
|
|
|
} |
818
|
|
|
|
819
|
|
|
/** |
820
|
|
|
* @dataProvider startsWithProvider() |
821
|
|
|
*/ |
822
|
|
View Code Duplication |
public function testStartsWith($expected, $str, $substring, |
|
|
|
|
823
|
|
|
$caseSensitive = true, $encoding = null) |
824
|
|
|
{ |
825
|
|
|
$stringy = S::create($str, $encoding); |
826
|
|
|
$result = $stringy->startsWith($substring, $caseSensitive); |
827
|
|
|
$this->assertInternalType('boolean', $result); |
828
|
|
|
$this->assertEquals($expected, $result); |
829
|
|
|
$this->assertEquals($str, $stringy); |
830
|
|
|
} |
831
|
|
|
|
832
|
|
View Code Duplication |
public function startsWithProvider() |
|
|
|
|
833
|
|
|
{ |
834
|
|
|
return array( |
835
|
|
|
array(true, 'foo bars', 'foo bar'), |
836
|
|
|
array(true, 'FOO bars', 'foo bar', false), |
837
|
|
|
array(true, 'FOO bars', 'foo BAR', false), |
838
|
|
|
array(true, 'FÒÔ bàřs', 'fòô bàř', false, 'UTF-8'), |
839
|
|
|
array(true, 'fòô bàřs', 'fòô BÀŘ', false, 'UTF-8'), |
840
|
|
|
array(false, 'foo bar', 'bar'), |
841
|
|
|
array(false, 'foo bar', 'foo bars'), |
842
|
|
|
array(false, 'FOO bar', 'foo bars'), |
843
|
|
|
array(false, 'FOO bars', 'foo BAR'), |
844
|
|
|
array(false, 'FÒÔ bàřs', 'fòô bàř', true, 'UTF-8'), |
845
|
|
|
array(false, 'fòô bàřs', 'fòô BÀŘ', true, 'UTF-8'), |
846
|
|
|
); |
847
|
|
|
} |
848
|
|
|
|
849
|
|
|
/** |
850
|
|
|
* @dataProvider endsWithProvider() |
851
|
|
|
*/ |
852
|
|
View Code Duplication |
public function testEndsWith($expected, $str, $substring, |
|
|
|
|
853
|
|
|
$caseSensitive = true, $encoding = null) |
854
|
|
|
{ |
855
|
|
|
$stringy = S::create($str, $encoding); |
856
|
|
|
$result = $stringy->endsWith($substring, $caseSensitive); |
857
|
|
|
$this->assertInternalType('boolean', $result); |
858
|
|
|
$this->assertEquals($expected, $result); |
859
|
|
|
$this->assertEquals($str, $stringy); |
860
|
|
|
} |
861
|
|
|
|
862
|
|
View Code Duplication |
public function endsWithProvider() |
|
|
|
|
863
|
|
|
{ |
864
|
|
|
return array( |
865
|
|
|
array(true, 'foo bars', 'o bars'), |
866
|
|
|
array(true, 'FOO bars', 'o bars', false), |
867
|
|
|
array(true, 'FOO bars', 'o BARs', false), |
868
|
|
|
array(true, 'FÒÔ bàřs', 'ô bàřs', false, 'UTF-8'), |
869
|
|
|
array(true, 'fòô bàřs', 'ô BÀŘs', false, 'UTF-8'), |
870
|
|
|
array(false, 'foo bar', 'foo'), |
871
|
|
|
array(false, 'foo bar', 'foo bars'), |
872
|
|
|
array(false, 'FOO bar', 'foo bars'), |
873
|
|
|
array(false, 'FOO bars', 'foo BARS'), |
874
|
|
|
array(false, 'FÒÔ bàřs', 'fòô bàřs', true, 'UTF-8'), |
875
|
|
|
array(false, 'fòô bàřs', 'fòô BÀŘS', true, 'UTF-8'), |
876
|
|
|
); |
877
|
|
|
} |
878
|
|
|
|
879
|
|
|
/** |
880
|
|
|
* @dataProvider toBooleanProvider() |
881
|
|
|
*/ |
882
|
|
View Code Duplication |
public function testToBoolean($expected, $str, $encoding = null) |
|
|
|
|
883
|
|
|
{ |
884
|
|
|
$stringy = S::create($str, $encoding); |
885
|
|
|
$result = $stringy->toBoolean(); |
886
|
|
|
$this->assertInternalType('boolean', $result); |
887
|
|
|
$this->assertEquals($expected, $result); |
888
|
|
|
$this->assertEquals($str, $stringy); |
889
|
|
|
} |
890
|
|
|
|
891
|
|
|
public function toBooleanProvider() |
892
|
|
|
{ |
893
|
|
|
return array( |
894
|
|
|
array(true, 'true'), |
895
|
|
|
array(true, '1'), |
896
|
|
|
array(true, 'on'), |
897
|
|
|
array(true, 'ON'), |
898
|
|
|
array(true, 'yes'), |
899
|
|
|
array(true, '999'), |
900
|
|
|
array(false, 'false'), |
901
|
|
|
array(false, '0'), |
902
|
|
|
array(false, 'off'), |
903
|
|
|
array(false, 'OFF'), |
904
|
|
|
array(false, 'no'), |
905
|
|
|
array(false, '-999'), |
906
|
|
|
array(false, ''), |
907
|
|
|
array(false, ' '), |
908
|
|
|
array(false, ' ', 'UTF-8') // narrow no-break space (U+202F) |
909
|
|
|
); |
910
|
|
|
} |
911
|
|
|
|
912
|
|
|
/** |
913
|
|
|
* @dataProvider toSpacesProvider() |
914
|
|
|
*/ |
915
|
|
|
public function testToSpaces($expected, $str, $tabLength = 4) |
916
|
|
|
{ |
917
|
|
|
$stringy = S::create($str); |
918
|
|
|
$result = $stringy->toSpaces($tabLength); |
919
|
|
|
$this->assertStringy($result); |
920
|
|
|
$this->assertEquals($expected, $result); |
921
|
|
|
$this->assertEquals($str, $stringy); |
922
|
|
|
} |
923
|
|
|
|
924
|
|
View Code Duplication |
public function toSpacesProvider() |
|
|
|
|
925
|
|
|
{ |
926
|
|
|
return array( |
927
|
|
|
array(' foo bar ', ' foo bar '), |
928
|
|
|
array(' foo bar ', ' foo bar ', 5), |
929
|
|
|
array(' foo bar ', ' foo bar ', 2), |
930
|
|
|
array('foobar', ' foo bar ', 0), |
931
|
|
|
array(" foo\n bar", " foo\n bar"), |
932
|
|
|
array(" fòô\n bàř", " fòô\n bàř") |
933
|
|
|
); |
934
|
|
|
} |
935
|
|
|
|
936
|
|
|
/** |
937
|
|
|
* @dataProvider toTabsProvider() |
938
|
|
|
*/ |
939
|
|
|
public function testToTabs($expected, $str, $tabLength = 4) |
940
|
|
|
{ |
941
|
|
|
$stringy = S::create($str); |
942
|
|
|
$result = $stringy->toTabs($tabLength); |
943
|
|
|
$this->assertStringy($result); |
944
|
|
|
$this->assertEquals($expected, $result); |
945
|
|
|
$this->assertEquals($str, $stringy); |
946
|
|
|
} |
947
|
|
|
|
948
|
|
|
public function toTabsProvider() |
949
|
|
|
{ |
950
|
|
|
return array( |
951
|
|
|
array(' foo bar ', ' foo bar '), |
952
|
|
|
array(' foo bar ', ' foo bar ', 5), |
953
|
|
|
array(' foo bar ', ' foo bar ', 2), |
954
|
|
|
array(" foo\n bar", " foo\n bar"), |
955
|
|
|
array(" fòô\n bàř", " fòô\n bàř") |
956
|
|
|
); |
957
|
|
|
} |
958
|
|
|
|
959
|
|
|
/** |
960
|
|
|
* @dataProvider toLowerCaseProvider() |
961
|
|
|
*/ |
962
|
|
|
public function testToLowerCase($expected, $str, $encoding = null) |
963
|
|
|
{ |
964
|
|
|
$stringy = S::create($str, $encoding); |
965
|
|
|
$result = $stringy->toLowerCase(); |
966
|
|
|
$this->assertStringy($result); |
967
|
|
|
$this->assertEquals($expected, $result); |
968
|
|
|
$this->assertEquals($str, $stringy); |
969
|
|
|
} |
970
|
|
|
|
971
|
|
View Code Duplication |
public function toLowerCaseProvider() |
|
|
|
|
972
|
|
|
{ |
973
|
|
|
return array( |
974
|
|
|
array('foo bar', 'FOO BAR'), |
975
|
|
|
array(' foo_bar ', ' FOO_bar '), |
976
|
|
|
array('fòô bàř', 'FÒÔ BÀŘ', 'UTF-8'), |
977
|
|
|
array(' fòô_bàř ', ' FÒÔ_bàř ', 'UTF-8'), |
978
|
|
|
array('αυτοκίνητο', 'ΑΥΤΟΚΊΝΗΤΟ', 'UTF-8'), |
979
|
|
|
); |
980
|
|
|
} |
981
|
|
|
|
982
|
|
|
/** |
983
|
|
|
* @dataProvider toTitleCaseProvider() |
984
|
|
|
*/ |
985
|
|
|
public function testToTitleCase($expected, $str, $encoding = null) |
986
|
|
|
{ |
987
|
|
|
$stringy = S::create($str, $encoding); |
988
|
|
|
$result = $stringy->toTitleCase(); |
989
|
|
|
$this->assertStringy($result); |
990
|
|
|
$this->assertEquals($expected, $result); |
991
|
|
|
$this->assertEquals($str, $stringy); |
992
|
|
|
} |
993
|
|
|
|
994
|
|
View Code Duplication |
public function toTitleCaseProvider() |
|
|
|
|
995
|
|
|
{ |
996
|
|
|
return array( |
997
|
|
|
array('Foo Bar', 'foo bar'), |
998
|
|
|
array(' Foo_Bar ', ' foo_bar '), |
999
|
|
|
array('Fòô Bàř', 'fòô bàř', 'UTF-8'), |
1000
|
|
|
array(' Fòô_Bàř ', ' fòô_bàř ', 'UTF-8'), |
1001
|
|
|
array('Αυτοκίνητο Αυτοκίνητο', 'αυτοκίνητο αυτοκίνητο', 'UTF-8'), |
1002
|
|
|
); |
1003
|
|
|
} |
1004
|
|
|
|
1005
|
|
|
/** |
1006
|
|
|
* @dataProvider toUpperCaseProvider() |
1007
|
|
|
*/ |
1008
|
|
|
public function testToUpperCase($expected, $str, $encoding = null) |
1009
|
|
|
{ |
1010
|
|
|
$stringy = S::create($str, $encoding); |
1011
|
|
|
$result = $stringy->toUpperCase(); |
1012
|
|
|
$this->assertStringy($result); |
1013
|
|
|
$this->assertEquals($expected, $result); |
1014
|
|
|
$this->assertEquals($str, $stringy); |
1015
|
|
|
} |
1016
|
|
|
|
1017
|
|
View Code Duplication |
public function toUpperCaseProvider() |
|
|
|
|
1018
|
|
|
{ |
1019
|
|
|
return array( |
1020
|
|
|
array('FOO BAR', 'foo bar'), |
1021
|
|
|
array(' FOO_BAR ', ' FOO_bar '), |
1022
|
|
|
array('FÒÔ BÀŘ', 'fòô bàř', 'UTF-8'), |
1023
|
|
|
array(' FÒÔ_BÀŘ ', ' FÒÔ_bàř ', 'UTF-8'), |
1024
|
|
|
array('ΑΥΤΟΚΊΝΗΤΟ', 'αυτοκίνητο', 'UTF-8'), |
1025
|
|
|
); |
1026
|
|
|
} |
1027
|
|
|
|
1028
|
|
|
/** |
1029
|
|
|
* @dataProvider slugifyProvider() |
1030
|
|
|
*/ |
1031
|
|
|
public function testSlugify($expected, $str, $replacement = '-') |
1032
|
|
|
{ |
1033
|
|
|
$stringy = S::create($str); |
1034
|
|
|
$result = $stringy->slugify($replacement); |
1035
|
|
|
$this->assertStringy($result); |
1036
|
|
|
$this->assertEquals($expected, $result); |
1037
|
|
|
$this->assertEquals($str, $stringy); |
1038
|
|
|
} |
1039
|
|
|
|
1040
|
|
|
public function slugifyProvider() |
1041
|
|
|
{ |
1042
|
|
|
return array( |
1043
|
|
|
array('foo-bar', ' foo bar '), |
1044
|
|
|
array('foo-bar', 'foo -.-"-...bar'), |
1045
|
|
|
array('another-foo-bar', 'another..& foo -.-"-...bar'), |
1046
|
|
|
array('foo-dbar', " Foo d'Bar "), |
1047
|
|
|
array('a-string-with-dashes', 'A string-with-dashes'), |
1048
|
|
|
array('using-strings-like-foo-bar', 'Using strings like fòô bàř'), |
1049
|
|
|
array('numbers-1234', 'numbers 1234'), |
1050
|
|
|
array('perevirka-ryadka', 'перевірка рядка'), |
1051
|
|
|
array('bukvar-s-bukvoy-y', 'букварь с буквой ы'), |
1052
|
|
|
array('podekhal-k-podezdu-moego-doma', 'подъехал к подъезду моего дома'), |
1053
|
|
|
array('foo:bar:baz', 'Foo bar baz', ':'), |
1054
|
|
|
array('a_string_with_underscores', 'A_string with_underscores', '_'), |
1055
|
|
|
array('a_string_with_dashes', 'A string-with-dashes', '_'), |
1056
|
|
|
array('a\string\with\dashes', 'A string-with-dashes', '\\'), |
1057
|
|
|
array('an_odd_string', '-- An odd__ string-_', '_') |
1058
|
|
|
); |
1059
|
|
|
} |
1060
|
|
|
|
1061
|
|
|
/** |
1062
|
|
|
* @dataProvider betweenProvider() |
1063
|
|
|
*/ |
1064
|
|
View Code Duplication |
public function testBetween($expected, $str, $start, $end, $offset = null, |
|
|
|
|
1065
|
|
|
$encoding = null) |
1066
|
|
|
{ |
1067
|
|
|
$stringy = S::create($str, $encoding); |
1068
|
|
|
$result = $stringy->between($start, $end, $offset); |
1069
|
|
|
$this->assertStringy($result); |
1070
|
|
|
$this->assertEquals($expected, $result); |
1071
|
|
|
$this->assertEquals($str, $stringy); |
1072
|
|
|
} |
1073
|
|
|
|
1074
|
|
|
public function betweenProvider() |
1075
|
|
|
{ |
1076
|
|
|
return array( |
1077
|
|
|
array('', 'foo', '{', '}'), |
1078
|
|
|
array('', '{foo', '{', '}'), |
1079
|
|
|
array('foo', '{foo}', '{', '}'), |
1080
|
|
|
array('{foo', '{{foo}', '{', '}'), |
1081
|
|
|
array('', '{}foo}', '{', '}'), |
1082
|
|
|
array('foo', '}{foo}', '{', '}'), |
1083
|
|
|
array('foo', 'A description of {foo} goes here', '{', '}'), |
1084
|
|
|
array('bar', '{foo} and {bar}', '{', '}', 1), |
1085
|
|
|
array('', 'fòô', '{', '}', 0, 'UTF-8'), |
1086
|
|
|
array('', '{fòô', '{', '}', 0, 'UTF-8'), |
1087
|
|
|
array('fòô', '{fòô}', '{', '}', 0, 'UTF-8'), |
1088
|
|
|
array('{fòô', '{{fòô}', '{', '}', 0, 'UTF-8'), |
1089
|
|
|
array('', '{}fòô}', '{', '}', 0, 'UTF-8'), |
1090
|
|
|
array('fòô', '}{fòô}', '{', '}', 0, 'UTF-8'), |
1091
|
|
|
array('fòô', 'A description of {fòô} goes here', '{', '}', 0, 'UTF-8'), |
1092
|
|
|
array('bàř', '{fòô} and {bàř}', '{', '}', 1, 'UTF-8') |
1093
|
|
|
); |
1094
|
|
|
} |
1095
|
|
|
|
1096
|
|
|
/** |
1097
|
|
|
* @dataProvider containsProvider() |
1098
|
|
|
*/ |
1099
|
|
View Code Duplication |
public function testContains($expected, $haystack, $needle, |
|
|
|
|
1100
|
|
|
$caseSensitive = true, $encoding = null) |
1101
|
|
|
{ |
1102
|
|
|
$stringy = S::create($haystack, $encoding); |
1103
|
|
|
$result = $stringy->contains($needle, $caseSensitive); |
1104
|
|
|
$this->assertInternalType('boolean', $result); |
1105
|
|
|
$this->assertEquals($expected, $result); |
1106
|
|
|
$this->assertEquals($haystack, $stringy); |
1107
|
|
|
} |
1108
|
|
|
|
1109
|
|
|
public function containsProvider() |
1110
|
|
|
{ |
1111
|
|
|
return array( |
1112
|
|
|
array(true, 'Str contains foo bar', 'foo bar'), |
1113
|
|
|
array(true, '12398!@(*%!@# @!%#*&^%', ' @!%#*&^%'), |
1114
|
|
|
array(true, 'Ο συγγραφέας είπε', 'συγγραφέας', 'UTF-8'), |
1115
|
|
|
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'å´¥©', true, 'UTF-8'), |
1116
|
|
|
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'å˚ ∆', true, 'UTF-8'), |
1117
|
|
|
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'øœ¬', true, 'UTF-8'), |
1118
|
|
|
array(false, 'Str contains foo bar', 'Foo bar'), |
1119
|
|
|
array(false, 'Str contains foo bar', 'foobar'), |
1120
|
|
|
array(false, 'Str contains foo bar', 'foo bar '), |
1121
|
|
|
array(false, 'Ο συγγραφέας είπε', ' συγγραφέας ', true, 'UTF-8'), |
1122
|
|
|
array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', ' ßå˚', true, 'UTF-8'), |
1123
|
|
|
array(true, 'Str contains foo bar', 'Foo bar', false), |
1124
|
|
|
array(true, '12398!@(*%!@# @!%#*&^%', ' @!%#*&^%', false), |
1125
|
|
|
array(true, 'Ο συγγραφέας είπε', 'ΣΥΓΓΡΑΦΈΑΣ', false, 'UTF-8'), |
1126
|
|
|
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'Å´¥©', false, 'UTF-8'), |
1127
|
|
|
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'Å˚ ∆', false, 'UTF-8'), |
1128
|
|
|
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'ØŒ¬', false, 'UTF-8'), |
1129
|
|
|
array(false, 'Str contains foo bar', 'foobar', false), |
1130
|
|
|
array(false, 'Str contains foo bar', 'foo bar ', false), |
1131
|
|
|
array(false, 'Ο συγγραφέας είπε', ' συγγραφέας ', false, 'UTF-8'), |
1132
|
|
|
array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', ' ßÅ˚', false, 'UTF-8') |
1133
|
|
|
); |
1134
|
|
|
} |
1135
|
|
|
|
1136
|
|
|
/** |
1137
|
|
|
* @dataProvider containsAnyProvider() |
1138
|
|
|
*/ |
1139
|
|
View Code Duplication |
public function testcontainsAny($expected, $haystack, $needles, |
|
|
|
|
1140
|
|
|
$caseSensitive = true, $encoding = null) |
1141
|
|
|
{ |
1142
|
|
|
$stringy = S::create($haystack, $encoding); |
1143
|
|
|
$result = $stringy->containsAny($needles, $caseSensitive); |
1144
|
|
|
$this->assertInternalType('boolean', $result); |
1145
|
|
|
$this->assertEquals($expected, $result); |
1146
|
|
|
$this->assertEquals($haystack, $stringy); |
1147
|
|
|
} |
1148
|
|
|
|
1149
|
|
View Code Duplication |
public function containsAnyProvider() |
|
|
|
|
1150
|
|
|
{ |
1151
|
|
|
// One needle |
1152
|
|
|
$singleNeedle = array_map(function ($array) { |
1153
|
|
|
$array[2] = array($array[2]); |
1154
|
|
|
return $array; |
1155
|
|
|
}, $this->containsProvider()); |
1156
|
|
|
|
1157
|
|
|
$provider = array( |
1158
|
|
|
// No needles |
1159
|
|
|
array(false, 'Str contains foo bar', array()), |
1160
|
|
|
// Multiple needles |
1161
|
|
|
array(true, 'Str contains foo bar', array('foo', 'bar')), |
1162
|
|
|
array(true, '12398!@(*%!@# @!%#*&^%', array(' @!%#*', '&^%')), |
1163
|
|
|
array(true, 'Ο συγγραφέας είπε', array('συγγρ', 'αφέας'), 'UTF-8'), |
1164
|
|
|
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('å´¥', '©'), true, 'UTF-8'), |
1165
|
|
|
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('å˚ ', '∆'), true, 'UTF-8'), |
1166
|
|
|
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('øœ', '¬'), true, 'UTF-8'), |
1167
|
|
|
array(false, 'Str contains foo bar', array('Foo', 'Bar')), |
1168
|
|
|
array(false, 'Str contains foo bar', array('foobar', 'bar ')), |
1169
|
|
|
array(false, 'Str contains foo bar', array('foo bar ', ' foo')), |
1170
|
|
|
array(false, 'Ο συγγραφέας είπε', array(' συγγραφέας ', ' συγγραφ '), true, 'UTF-8'), |
1171
|
|
|
array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array(' ßå˚', ' ß '), true, 'UTF-8'), |
1172
|
|
|
array(true, 'Str contains foo bar', array('Foo bar', 'bar'), false), |
1173
|
|
|
array(true, '12398!@(*%!@# @!%#*&^%', array(' @!%#*&^%', '*&^%'), false), |
1174
|
|
|
array(true, 'Ο συγγραφέας είπε', array('ΣΥΓΓΡΑΦΈΑΣ', 'ΑΦΈΑ'), false, 'UTF-8'), |
1175
|
|
|
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('Å´¥©', '¥©'), false, 'UTF-8'), |
1176
|
|
|
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('Å˚ ∆', ' ∆'), false, 'UTF-8'), |
1177
|
|
|
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('ØŒ¬', 'Œ'), false, 'UTF-8'), |
1178
|
|
|
array(false, 'Str contains foo bar', array('foobar', 'none'), false), |
1179
|
|
|
array(false, 'Str contains foo bar', array('foo bar ', ' ba '), false), |
1180
|
|
|
array(false, 'Ο συγγραφέας είπε', array(' συγγραφέας ', ' ραφέ '), false, 'UTF-8'), |
1181
|
|
|
array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array(' ßÅ˚', ' Å˚ '), false, 'UTF-8'), |
1182
|
|
|
); |
1183
|
|
|
|
1184
|
|
|
return array_merge($singleNeedle, $provider); |
1185
|
|
|
} |
1186
|
|
|
|
1187
|
|
|
/** |
1188
|
|
|
* @dataProvider containsAllProvider() |
1189
|
|
|
*/ |
1190
|
|
View Code Duplication |
public function testContainsAll($expected, $haystack, $needles, |
|
|
|
|
1191
|
|
|
$caseSensitive = true, $encoding = null) |
1192
|
|
|
{ |
1193
|
|
|
$stringy = S::create($haystack, $encoding); |
1194
|
|
|
$result = $stringy->containsAll($needles, $caseSensitive); |
1195
|
|
|
$this->assertInternalType('boolean', $result); |
1196
|
|
|
$this->assertEquals($expected, $result); |
1197
|
|
|
$this->assertEquals($haystack, $stringy); |
1198
|
|
|
} |
1199
|
|
|
|
1200
|
|
View Code Duplication |
public function containsAllProvider() |
|
|
|
|
1201
|
|
|
{ |
1202
|
|
|
// One needle |
1203
|
|
|
$singleNeedle = array_map(function ($array) { |
1204
|
|
|
$array[2] = array($array[2]); |
1205
|
|
|
return $array; |
1206
|
|
|
}, $this->containsProvider()); |
1207
|
|
|
|
1208
|
|
|
$provider = array( |
1209
|
|
|
// One needle |
1210
|
|
|
array(false, 'Str contains foo bar', array()), |
1211
|
|
|
// Multiple needles |
1212
|
|
|
array(true, 'Str contains foo bar', array('foo', 'bar')), |
1213
|
|
|
array(true, '12398!@(*%!@# @!%#*&^%', array(' @!%#*', '&^%')), |
1214
|
|
|
array(true, 'Ο συγγραφέας είπε', array('συγγρ', 'αφέας'), 'UTF-8'), |
1215
|
|
|
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('å´¥', '©'), true, 'UTF-8'), |
1216
|
|
|
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('å˚ ', '∆'), true, 'UTF-8'), |
1217
|
|
|
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('øœ', '¬'), true, 'UTF-8'), |
1218
|
|
|
array(false, 'Str contains foo bar', array('Foo', 'bar')), |
1219
|
|
|
array(false, 'Str contains foo bar', array('foobar', 'bar')), |
1220
|
|
|
array(false, 'Str contains foo bar', array('foo bar ', 'bar')), |
1221
|
|
|
array(false, 'Ο συγγραφέας είπε', array(' συγγραφέας ', ' συγγραφ '), true, 'UTF-8'), |
1222
|
|
|
array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array(' ßå˚', ' ß '), true, 'UTF-8'), |
1223
|
|
|
array(true, 'Str contains foo bar', array('Foo bar', 'bar'), false), |
1224
|
|
|
array(true, '12398!@(*%!@# @!%#*&^%', array(' @!%#*&^%', '*&^%'), false), |
1225
|
|
|
array(true, 'Ο συγγραφέας είπε', array('ΣΥΓΓΡΑΦΈΑΣ', 'ΑΦΈΑ'), false, 'UTF-8'), |
1226
|
|
|
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('Å´¥©', '¥©'), false, 'UTF-8'), |
1227
|
|
|
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('Å˚ ∆', ' ∆'), false, 'UTF-8'), |
1228
|
|
|
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('ØŒ¬', 'Œ'), false, 'UTF-8'), |
1229
|
|
|
array(false, 'Str contains foo bar', array('foobar', 'none'), false), |
1230
|
|
|
array(false, 'Str contains foo bar', array('foo bar ', ' ba'), false), |
1231
|
|
|
array(false, 'Ο συγγραφέας είπε', array(' συγγραφέας ', ' ραφέ '), false, 'UTF-8'), |
1232
|
|
|
array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array(' ßÅ˚', ' Å˚ '), false, 'UTF-8'), |
1233
|
|
|
); |
1234
|
|
|
|
1235
|
|
|
return array_merge($singleNeedle, $provider); |
1236
|
|
|
} |
1237
|
|
|
|
1238
|
|
|
/** |
1239
|
|
|
* @dataProvider surroundProvider() |
1240
|
|
|
*/ |
1241
|
|
|
public function testSurround($expected, $str, $substring) |
1242
|
|
|
{ |
1243
|
|
|
$stringy = S::create($str); |
1244
|
|
|
$result = $stringy->surround($substring); |
1245
|
|
|
$this->assertStringy($result); |
1246
|
|
|
$this->assertEquals($expected, $result); |
1247
|
|
|
$this->assertEquals($str, $stringy); |
1248
|
|
|
} |
1249
|
|
|
|
1250
|
|
View Code Duplication |
public function surroundProvider() |
|
|
|
|
1251
|
|
|
{ |
1252
|
|
|
return array( |
1253
|
|
|
array('__foobar__', 'foobar', '__'), |
1254
|
|
|
array('test', 'test', ''), |
1255
|
|
|
array('**', '', '*'), |
1256
|
|
|
array('¬fòô bàř¬', 'fòô bàř', '¬'), |
1257
|
|
|
array('ßå∆˚ test ßå∆˚', ' test ', 'ßå∆˚') |
1258
|
|
|
); |
1259
|
|
|
} |
1260
|
|
|
|
1261
|
|
|
/** |
1262
|
|
|
* @dataProvider insertProvider() |
1263
|
|
|
*/ |
1264
|
|
View Code Duplication |
public function testInsert($expected, $str, $substring, $index, |
|
|
|
|
1265
|
|
|
$encoding = null) |
1266
|
|
|
{ |
1267
|
|
|
$stringy = S::create($str, $encoding); |
1268
|
|
|
$result = $stringy->insert($substring, $index); |
1269
|
|
|
$this->assertStringy($result); |
1270
|
|
|
$this->assertEquals($expected, $result); |
1271
|
|
|
$this->assertEquals($str, $stringy); |
1272
|
|
|
} |
1273
|
|
|
|
1274
|
|
|
public function insertProvider() |
1275
|
|
|
{ |
1276
|
|
|
return array( |
1277
|
|
|
array('foo bar', 'oo bar', 'f', 0), |
1278
|
|
|
array('foo bar', 'f bar', 'oo', 1), |
1279
|
|
|
array('f bar', 'f bar', 'oo', 20), |
1280
|
|
|
array('foo bar', 'foo ba', 'r', 6), |
1281
|
|
|
array('fòôbàř', 'fòôbř', 'à', 4, 'UTF-8'), |
1282
|
|
|
array('fòô bàř', 'òô bàř', 'f', 0, 'UTF-8'), |
1283
|
|
|
array('fòô bàř', 'f bàř', 'òô', 1, 'UTF-8'), |
1284
|
|
|
array('fòô bàř', 'fòô bà', 'ř', 6, 'UTF-8') |
1285
|
|
|
); |
1286
|
|
|
} |
1287
|
|
|
|
1288
|
|
|
/** |
1289
|
|
|
* @dataProvider truncateProvider() |
1290
|
|
|
*/ |
1291
|
|
View Code Duplication |
public function testTruncate($expected, $str, $length, $substring = '', |
|
|
|
|
1292
|
|
|
$encoding = null) |
1293
|
|
|
{ |
1294
|
|
|
$stringy = S::create($str, $encoding); |
1295
|
|
|
$result = $stringy->truncate($length, $substring); |
1296
|
|
|
$this->assertStringy($result); |
1297
|
|
|
$this->assertEquals($expected, $result); |
1298
|
|
|
$this->assertEquals($str, $stringy); |
1299
|
|
|
} |
1300
|
|
|
|
1301
|
|
View Code Duplication |
public function truncateProvider() |
|
|
|
|
1302
|
|
|
{ |
1303
|
|
|
return array( |
1304
|
|
|
array('Test foo bar', 'Test foo bar', 12), |
1305
|
|
|
array('Test foo ba', 'Test foo bar', 11), |
1306
|
|
|
array('Test foo', 'Test foo bar', 8), |
1307
|
|
|
array('Test fo', 'Test foo bar', 7), |
1308
|
|
|
array('Test', 'Test foo bar', 4), |
1309
|
|
|
array('Test foo bar', 'Test foo bar', 12, '...'), |
1310
|
|
|
array('Test foo...', 'Test foo bar', 11, '...'), |
1311
|
|
|
array('Test ...', 'Test foo bar', 8, '...'), |
1312
|
|
|
array('Test...', 'Test foo bar', 7, '...'), |
1313
|
|
|
array('T...', 'Test foo bar', 4, '...'), |
1314
|
|
|
array('Test fo....', 'Test foo bar', 11, '....'), |
1315
|
|
|
array('Test fòô bàř', 'Test fòô bàř', 12, '', 'UTF-8'), |
1316
|
|
|
array('Test fòô bà', 'Test fòô bàř', 11, '', 'UTF-8'), |
1317
|
|
|
array('Test fòô', 'Test fòô bàř', 8, '', 'UTF-8'), |
1318
|
|
|
array('Test fò', 'Test fòô bàř', 7, '', 'UTF-8'), |
1319
|
|
|
array('Test', 'Test fòô bàř', 4, '', 'UTF-8'), |
1320
|
|
|
array('Test fòô bàř', 'Test fòô bàř', 12, 'ϰϰ', 'UTF-8'), |
1321
|
|
|
array('Test fòô ϰϰ', 'Test fòô bàř', 11, 'ϰϰ', 'UTF-8'), |
1322
|
|
|
array('Test fϰϰ', 'Test fòô bàř', 8, 'ϰϰ', 'UTF-8'), |
1323
|
|
|
array('Test ϰϰ', 'Test fòô bàř', 7, 'ϰϰ', 'UTF-8'), |
1324
|
|
|
array('Teϰϰ', 'Test fòô bàř', 4, 'ϰϰ', 'UTF-8'), |
1325
|
|
|
array('What are your pl...', 'What are your plans today?', 19, '...') |
1326
|
|
|
); |
1327
|
|
|
} |
1328
|
|
|
|
1329
|
|
|
/** |
1330
|
|
|
* @dataProvider safeTruncateProvider() |
1331
|
|
|
*/ |
1332
|
|
View Code Duplication |
public function testSafeTruncate($expected, $str, $length, $substring = '', |
|
|
|
|
1333
|
|
|
$encoding = null) |
1334
|
|
|
{ |
1335
|
|
|
$stringy = S::create($str, $encoding); |
1336
|
|
|
$result = $stringy->safeTruncate($length, $substring); |
1337
|
|
|
$this->assertStringy($result); |
1338
|
|
|
$this->assertEquals($expected, $result); |
1339
|
|
|
$this->assertEquals($str, $stringy); |
1340
|
|
|
} |
1341
|
|
|
|
1342
|
|
View Code Duplication |
public function safeTruncateProvider() |
|
|
|
|
1343
|
|
|
{ |
1344
|
|
|
return array( |
1345
|
|
|
array('Test foo bar', 'Test foo bar', 12), |
1346
|
|
|
array('Test foo', 'Test foo bar', 11), |
1347
|
|
|
array('Test foo', 'Test foo bar', 8), |
1348
|
|
|
array('Test', 'Test foo bar', 7), |
1349
|
|
|
array('Test', 'Test foo bar', 4), |
1350
|
|
|
array('Test foo bar', 'Test foo bar', 12, '...'), |
1351
|
|
|
array('Test foo...', 'Test foo bar', 11, '...'), |
1352
|
|
|
array('Test...', 'Test foo bar', 8, '...'), |
1353
|
|
|
array('Test...', 'Test foo bar', 7, '...'), |
1354
|
|
|
array('...', 'Test foo bar', 4, '...'), |
1355
|
|
|
array('Test....', 'Test foo bar', 11, '....'), |
1356
|
|
|
array('Test fòô bàř', 'Test fòô bàř', 12, '', 'UTF-8'), |
1357
|
|
|
array('Test fòô', 'Test fòô bàř', 11, '', 'UTF-8'), |
1358
|
|
|
array('Test fòô', 'Test fòô bàř', 8, '', 'UTF-8'), |
1359
|
|
|
array('Test', 'Test fòô bàř', 7, '', 'UTF-8'), |
1360
|
|
|
array('Test', 'Test fòô bàř', 4, '', 'UTF-8'), |
1361
|
|
|
array('Test fòô bàř', 'Test fòô bàř', 12, 'ϰϰ', 'UTF-8'), |
1362
|
|
|
array('Test fòôϰϰ', 'Test fòô bàř', 11, 'ϰϰ', 'UTF-8'), |
1363
|
|
|
array('Testϰϰ', 'Test fòô bàř', 8, 'ϰϰ', 'UTF-8'), |
1364
|
|
|
array('Testϰϰ', 'Test fòô bàř', 7, 'ϰϰ', 'UTF-8'), |
1365
|
|
|
array('ϰϰ', 'Test fòô bàř', 4, 'ϰϰ', 'UTF-8'), |
1366
|
|
|
array('What are your plans...', 'What are your plans today?', 22, '...') |
1367
|
|
|
); |
1368
|
|
|
} |
1369
|
|
|
|
1370
|
|
|
/** |
1371
|
|
|
* @dataProvider reverseProvider() |
1372
|
|
|
*/ |
1373
|
|
|
public function testReverse($expected, $str, $encoding = null) |
1374
|
|
|
{ |
1375
|
|
|
$stringy = S::create($str, $encoding); |
1376
|
|
|
$result = $stringy->reverse(); |
1377
|
|
|
$this->assertStringy($result); |
1378
|
|
|
$this->assertEquals($expected, $result); |
1379
|
|
|
$this->assertEquals($str, $stringy); |
1380
|
|
|
} |
1381
|
|
|
|
1382
|
|
View Code Duplication |
public function reverseProvider() |
|
|
|
|
1383
|
|
|
{ |
1384
|
|
|
return array( |
1385
|
|
|
array('', ''), |
1386
|
|
|
array('raboof', 'foobar'), |
1387
|
|
|
array('řàbôòf', 'fòôbàř', 'UTF-8'), |
1388
|
|
|
array('řàb ôòf', 'fòô bàř', 'UTF-8'), |
1389
|
|
|
array('∂∆ ˚åß', 'ßå˚ ∆∂', 'UTF-8') |
1390
|
|
|
); |
1391
|
|
|
} |
1392
|
|
|
|
1393
|
|
|
/** |
1394
|
|
|
* @dataProvider repeatProvider() |
1395
|
|
|
*/ |
1396
|
|
View Code Duplication |
public function testRepeat($expected, $str, $multiplier, $encoding = null) |
|
|
|
|
1397
|
|
|
{ |
1398
|
|
|
$stringy = S::create($str, $encoding); |
1399
|
|
|
$result = $stringy->repeat($multiplier); |
1400
|
|
|
$this->assertStringy($result); |
1401
|
|
|
$this->assertEquals($expected, $result); |
1402
|
|
|
$this->assertEquals($str, $stringy); |
1403
|
|
|
} |
1404
|
|
|
|
1405
|
|
|
public function repeatProvider() |
1406
|
|
|
{ |
1407
|
|
|
return array( |
1408
|
|
|
array('', 'foo', 0), |
1409
|
|
|
array('foo', 'foo', 1), |
1410
|
|
|
array('foofoo', 'foo', 2), |
1411
|
|
|
array('foofoofoo', 'foo', 3), |
1412
|
|
|
array('fòô', 'fòô', 1, 'UTF-8'), |
1413
|
|
|
array('fòôfòô', 'fòô', 2, 'UTF-8'), |
1414
|
|
|
array('fòôfòôfòô', 'fòô', 3, 'UTF-8') |
1415
|
|
|
); |
1416
|
|
|
} |
1417
|
|
|
|
1418
|
|
|
/** |
1419
|
|
|
* @dataProvider shuffleProvider() |
1420
|
|
|
*/ |
1421
|
|
|
public function testShuffle($str, $encoding = null) |
1422
|
|
|
{ |
1423
|
|
|
$stringy = S::create($str, $encoding); |
1424
|
|
|
$encoding = $encoding ?: mb_internal_encoding(); |
1425
|
|
|
$result = $stringy->shuffle(); |
1426
|
|
|
|
1427
|
|
|
$this->assertStringy($result); |
1428
|
|
|
$this->assertEquals($str, $stringy); |
1429
|
|
|
$this->assertEquals(mb_strlen($str, $encoding), |
1430
|
|
|
mb_strlen($result, $encoding)); |
1431
|
|
|
|
1432
|
|
|
// We'll make sure that the chars are present after shuffle |
1433
|
|
|
for ($i = 0; $i < mb_strlen($str, $encoding); $i++) { |
1434
|
|
|
$char = mb_substr($str, $i, 1, $encoding); |
1435
|
|
|
$countBefore = mb_substr_count($str, $char, $encoding); |
1436
|
|
|
$countAfter = mb_substr_count($result, $char, $encoding); |
1437
|
|
|
$this->assertEquals($countBefore, $countAfter); |
1438
|
|
|
} |
1439
|
|
|
} |
1440
|
|
|
|
1441
|
|
|
public function shuffleProvider() |
1442
|
|
|
{ |
1443
|
|
|
return array( |
1444
|
|
|
array('foo bar'), |
1445
|
|
|
array('∂∆ ˚åß', 'UTF-8'), |
1446
|
|
|
array('å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'UTF-8') |
1447
|
|
|
); |
1448
|
|
|
} |
1449
|
|
|
|
1450
|
|
|
/** |
1451
|
|
|
* @dataProvider trimProvider() |
1452
|
|
|
*/ |
1453
|
|
|
public function testTrim($expected, $str, $chars = null, $encoding = null) |
1454
|
|
|
{ |
1455
|
|
|
$stringy = S::create($str, $encoding); |
1456
|
|
|
$result = $stringy->trim($chars); |
1457
|
|
|
$this->assertStringy($result); |
1458
|
|
|
$this->assertEquals($expected, $result); |
1459
|
|
|
$this->assertEquals($str, $stringy); |
1460
|
|
|
} |
1461
|
|
|
|
1462
|
|
|
public function trimProvider() |
1463
|
|
|
{ |
1464
|
|
|
return array( |
1465
|
|
|
array('foo bar', ' foo bar '), |
1466
|
|
|
array('foo bar', ' foo bar'), |
1467
|
|
|
array('foo bar', 'foo bar '), |
1468
|
|
|
array('foo bar', "\n\t foo bar \n\t"), |
1469
|
|
|
array('fòô bàř', ' fòô bàř '), |
1470
|
|
|
array('fòô bàř', ' fòô bàř'), |
1471
|
|
|
array('fòô bàř', 'fòô bàř '), |
1472
|
|
|
array(' foo bar ', "\n\t foo bar \n\t", "\n\t"), |
1473
|
|
|
array('fòô bàř', "\n\t fòô bàř \n\t", null, 'UTF-8'), |
1474
|
|
|
array('fòô', ' fòô ', null, 'UTF-8'), // narrow no-break space (U+202F) |
1475
|
|
|
array('fòô', ' fòô ', null, 'UTF-8'), // medium mathematical space (U+205F) |
1476
|
|
|
array('fòô', ' fòô', null, 'UTF-8') // spaces U+2000 to U+200A |
1477
|
|
|
); |
1478
|
|
|
} |
1479
|
|
|
|
1480
|
|
|
/** |
1481
|
|
|
* @dataProvider trimLeftProvider() |
1482
|
|
|
*/ |
1483
|
|
|
public function testTrimLeft($expected, $str, $chars = null, |
1484
|
|
|
$encoding = null) |
1485
|
|
|
{ |
1486
|
|
|
$stringy = S::create($str, $encoding); |
1487
|
|
|
$result = $stringy->trimLeft($chars); |
1488
|
|
|
$this->assertStringy($result); |
1489
|
|
|
$this->assertEquals($expected, $result); |
1490
|
|
|
$this->assertEquals($str, $stringy); |
1491
|
|
|
} |
1492
|
|
|
|
1493
|
|
View Code Duplication |
public function trimLeftProvider() |
|
|
|
|
1494
|
|
|
{ |
1495
|
|
|
return array( |
1496
|
|
|
array('foo bar ', ' foo bar '), |
1497
|
|
|
array('foo bar', ' foo bar'), |
1498
|
|
|
array('foo bar ', 'foo bar '), |
1499
|
|
|
array("foo bar \n\t", "\n\t foo bar \n\t"), |
1500
|
|
|
array('fòô bàř ', ' fòô bàř '), |
1501
|
|
|
array('fòô bàř', ' fòô bàř'), |
1502
|
|
|
array('fòô bàř ', 'fòô bàř '), |
1503
|
|
|
array('foo bar', '--foo bar', '-'), |
1504
|
|
|
array('fòô bàř', 'òòfòô bàř', 'ò', 'UTF-8'), |
1505
|
|
|
array("fòô bàř \n\t", "\n\t fòô bàř \n\t", null, 'UTF-8'), |
1506
|
|
|
array('fòô ', ' fòô ', null, 'UTF-8'), // narrow no-break space (U+202F) |
1507
|
|
|
array('fòô ', ' fòô ', null, 'UTF-8'), // medium mathematical space (U+205F) |
1508
|
|
|
array('fòô', ' fòô', null, 'UTF-8') // spaces U+2000 to U+200A |
1509
|
|
|
); |
1510
|
|
|
} |
1511
|
|
|
|
1512
|
|
|
/** |
1513
|
|
|
* @dataProvider trimRightProvider() |
1514
|
|
|
*/ |
1515
|
|
|
public function testTrimRight($expected, $str, $chars = null, |
1516
|
|
|
$encoding = null) |
1517
|
|
|
{ |
1518
|
|
|
$stringy = S::create($str, $encoding); |
1519
|
|
|
$result = $stringy->trimRight($chars); |
1520
|
|
|
$this->assertStringy($result); |
1521
|
|
|
$this->assertEquals($expected, $result); |
1522
|
|
|
$this->assertEquals($str, $stringy); |
1523
|
|
|
} |
1524
|
|
|
|
1525
|
|
View Code Duplication |
public function trimRightProvider() |
|
|
|
|
1526
|
|
|
{ |
1527
|
|
|
return array( |
1528
|
|
|
array(' foo bar', ' foo bar '), |
1529
|
|
|
array('foo bar', 'foo bar '), |
1530
|
|
|
array(' foo bar', ' foo bar'), |
1531
|
|
|
array("\n\t foo bar", "\n\t foo bar \n\t"), |
1532
|
|
|
array(' fòô bàř', ' fòô bàř '), |
1533
|
|
|
array('fòô bàř', 'fòô bàř '), |
1534
|
|
|
array(' fòô bàř', ' fòô bàř'), |
1535
|
|
|
array('foo bar', 'foo bar--', '-'), |
1536
|
|
|
array('fòô bàř', 'fòô bàřòò', 'ò', 'UTF-8'), |
1537
|
|
|
array("\n\t fòô bàř", "\n\t fòô bàř \n\t", null, 'UTF-8'), |
1538
|
|
|
array(' fòô', ' fòô ', null, 'UTF-8'), // narrow no-break space (U+202F) |
1539
|
|
|
array(' fòô', ' fòô ', null, 'UTF-8'), // medium mathematical space (U+205F) |
1540
|
|
|
array('fòô', 'fòô ', null, 'UTF-8') // spaces U+2000 to U+200A |
1541
|
|
|
); |
1542
|
|
|
} |
1543
|
|
|
|
1544
|
|
|
/** |
1545
|
|
|
* @dataProvider longestCommonPrefixProvider() |
1546
|
|
|
*/ |
1547
|
|
View Code Duplication |
public function testLongestCommonPrefix($expected, $str, $otherStr, |
|
|
|
|
1548
|
|
|
$encoding = null) |
1549
|
|
|
{ |
1550
|
|
|
$stringy = S::create($str, $encoding); |
1551
|
|
|
$result = $stringy->longestCommonPrefix($otherStr); |
1552
|
|
|
$this->assertStringy($result); |
1553
|
|
|
$this->assertEquals($expected, $result); |
1554
|
|
|
$this->assertEquals($str, $stringy); |
1555
|
|
|
} |
1556
|
|
|
|
1557
|
|
View Code Duplication |
public function longestCommonPrefixProvider() |
|
|
|
|
1558
|
|
|
{ |
1559
|
|
|
return array( |
1560
|
|
|
array('foo', 'foobar', 'foo bar'), |
1561
|
|
|
array('foo bar', 'foo bar', 'foo bar'), |
1562
|
|
|
array('f', 'foo bar', 'far boo'), |
1563
|
|
|
array('', 'toy car', 'foo bar'), |
1564
|
|
|
array('', 'foo bar', ''), |
1565
|
|
|
array('fòô', 'fòôbar', 'fòô bar', 'UTF-8'), |
1566
|
|
|
array('fòô bar', 'fòô bar', 'fòô bar', 'UTF-8'), |
1567
|
|
|
array('fò', 'fòô bar', 'fòr bar', 'UTF-8'), |
1568
|
|
|
array('', 'toy car', 'fòô bar', 'UTF-8'), |
1569
|
|
|
array('', 'fòô bar', '', 'UTF-8'), |
1570
|
|
|
); |
1571
|
|
|
} |
1572
|
|
|
|
1573
|
|
|
/** |
1574
|
|
|
* @dataProvider longestCommonSuffixProvider() |
1575
|
|
|
*/ |
1576
|
|
View Code Duplication |
public function testLongestCommonSuffix($expected, $str, $otherStr, |
|
|
|
|
1577
|
|
|
$encoding = null) |
1578
|
|
|
{ |
1579
|
|
|
$stringy = S::create($str, $encoding); |
1580
|
|
|
$result = $stringy->longestCommonSuffix($otherStr); |
1581
|
|
|
$this->assertStringy($result); |
1582
|
|
|
$this->assertEquals($expected, $result); |
1583
|
|
|
$this->assertEquals($str, $stringy); |
1584
|
|
|
} |
1585
|
|
|
|
1586
|
|
View Code Duplication |
public function longestCommonSuffixProvider() |
|
|
|
|
1587
|
|
|
{ |
1588
|
|
|
return array( |
1589
|
|
|
array('bar', 'foobar', 'foo bar'), |
1590
|
|
|
array('foo bar', 'foo bar', 'foo bar'), |
1591
|
|
|
array('ar', 'foo bar', 'boo far'), |
1592
|
|
|
array('', 'foo bad', 'foo bar'), |
1593
|
|
|
array('', 'foo bar', ''), |
1594
|
|
|
array('bàř', 'fòôbàř', 'fòô bàř', 'UTF-8'), |
1595
|
|
|
array('fòô bàř', 'fòô bàř', 'fòô bàř', 'UTF-8'), |
1596
|
|
|
array(' bàř', 'fòô bàř', 'fòr bàř', 'UTF-8'), |
1597
|
|
|
array('', 'toy car', 'fòô bàř', 'UTF-8'), |
1598
|
|
|
array('', 'fòô bàř', '', 'UTF-8'), |
1599
|
|
|
); |
1600
|
|
|
} |
1601
|
|
|
|
1602
|
|
|
/** |
1603
|
|
|
* @dataProvider longestCommonSubstringProvider() |
1604
|
|
|
*/ |
1605
|
|
View Code Duplication |
public function testLongestCommonSubstring($expected, $str, $otherStr, |
|
|
|
|
1606
|
|
|
$encoding = null) |
1607
|
|
|
{ |
1608
|
|
|
$stringy = S::create($str, $encoding); |
1609
|
|
|
$result = $stringy->longestCommonSubstring($otherStr); |
1610
|
|
|
$this->assertStringy($result); |
1611
|
|
|
$this->assertEquals($expected, $result); |
1612
|
|
|
$this->assertEquals($str, $stringy); |
1613
|
|
|
} |
1614
|
|
|
|
1615
|
|
View Code Duplication |
public function longestCommonSubstringProvider() |
|
|
|
|
1616
|
|
|
{ |
1617
|
|
|
return array( |
1618
|
|
|
array('foo', 'foobar', 'foo bar'), |
1619
|
|
|
array('foo bar', 'foo bar', 'foo bar'), |
1620
|
|
|
array('oo ', 'foo bar', 'boo far'), |
1621
|
|
|
array('foo ba', 'foo bad', 'foo bar'), |
1622
|
|
|
array('', 'foo bar', ''), |
1623
|
|
|
array('fòô', 'fòôbàř', 'fòô bàř', 'UTF-8'), |
1624
|
|
|
array('fòô bàř', 'fòô bàř', 'fòô bàř', 'UTF-8'), |
1625
|
|
|
array(' bàř', 'fòô bàř', 'fòr bàř', 'UTF-8'), |
1626
|
|
|
array(' ', 'toy car', 'fòô bàř', 'UTF-8'), |
1627
|
|
|
array('', 'fòô bàř', '', 'UTF-8'), |
1628
|
|
|
); |
1629
|
|
|
} |
1630
|
|
|
|
1631
|
|
|
/** |
1632
|
|
|
* @dataProvider lengthProvider() |
1633
|
|
|
*/ |
1634
|
|
|
public function testLength($expected, $str, $encoding = null) |
1635
|
|
|
{ |
1636
|
|
|
$stringy = S::create($str, $encoding); |
1637
|
|
|
$result = $stringy->length(); |
1638
|
|
|
$this->assertInternalType('int', $result); |
1639
|
|
|
$this->assertEquals($expected, $result); |
1640
|
|
|
$this->assertEquals($str, $stringy); |
1641
|
|
|
} |
1642
|
|
|
|
1643
|
|
|
public function lengthProvider() |
1644
|
|
|
{ |
1645
|
|
|
return array( |
1646
|
|
|
array(11, ' foo bar '), |
1647
|
|
|
array(1, 'f'), |
1648
|
|
|
array(0, ''), |
1649
|
|
|
array(7, 'fòô bàř', 'UTF-8') |
1650
|
|
|
); |
1651
|
|
|
} |
1652
|
|
|
|
1653
|
|
|
/** |
1654
|
|
|
* @dataProvider sliceProvider() |
1655
|
|
|
*/ |
1656
|
|
View Code Duplication |
public function testSlice($expected, $str, $start, $end = null, |
|
|
|
|
1657
|
|
|
$encoding = null) |
1658
|
|
|
{ |
1659
|
|
|
$stringy = S::create($str, $encoding); |
1660
|
|
|
$result = $stringy->slice($start, $end); |
1661
|
|
|
$this->assertStringy($result); |
1662
|
|
|
$this->assertEquals($expected, $result); |
1663
|
|
|
$this->assertEquals($str, $stringy); |
1664
|
|
|
} |
1665
|
|
|
|
1666
|
|
|
public function sliceProvider() |
1667
|
|
|
{ |
1668
|
|
|
return array( |
1669
|
|
|
array('foobar', 'foobar', 0), |
1670
|
|
|
array('foobar', 'foobar', 0, null), |
1671
|
|
|
array('foobar', 'foobar', 0, 6), |
1672
|
|
|
array('fooba', 'foobar', 0, 5), |
1673
|
|
|
array('', 'foobar', 3, 0), |
1674
|
|
|
array('', 'foobar', 3, 2), |
1675
|
|
|
array('ba', 'foobar', 3, 5), |
1676
|
|
|
array('ba', 'foobar', 3, -1), |
1677
|
|
|
array('fòôbàř', 'fòôbàř', 0, null, 'UTF-8'), |
1678
|
|
|
array('fòôbàř', 'fòôbàř', 0, null), |
1679
|
|
|
array('fòôbàř', 'fòôbàř', 0, 6, 'UTF-8'), |
1680
|
|
|
array('fòôbà', 'fòôbàř', 0, 5, 'UTF-8'), |
1681
|
|
|
array('', 'fòôbàř', 3, 0, 'UTF-8'), |
1682
|
|
|
array('', 'fòôbàř', 3, 2, 'UTF-8'), |
1683
|
|
|
array('bà', 'fòôbàř', 3, 5, 'UTF-8'), |
1684
|
|
|
array('bà', 'fòôbàř', 3, -1, 'UTF-8') |
1685
|
|
|
); |
1686
|
|
|
} |
1687
|
|
|
|
1688
|
|
|
/** |
1689
|
|
|
* @dataProvider splitProvider() |
1690
|
|
|
*/ |
1691
|
|
|
public function testSplit($expected, $str, $pattern, $limit = null, |
1692
|
|
|
$encoding = null) |
1693
|
|
|
{ |
1694
|
|
|
$stringy = S::create($str, $encoding); |
1695
|
|
|
$result = $stringy->split($pattern, $limit); |
1696
|
|
|
|
1697
|
|
|
$this->assertInternalType('array', $result); |
1698
|
|
|
foreach ($result as $string) { |
1699
|
|
|
$this->assertStringy($string); |
1700
|
|
|
} |
1701
|
|
|
|
1702
|
|
View Code Duplication |
for ($i = 0; $i < count($expected); $i++) { |
|
|
|
|
1703
|
|
|
$this->assertEquals($expected[$i], $result[$i]); |
1704
|
|
|
} |
1705
|
|
|
} |
1706
|
|
|
|
1707
|
|
|
public function splitProvider() |
1708
|
|
|
{ |
1709
|
|
|
return array( |
1710
|
|
|
array(array('foo,bar,baz'), 'foo,bar,baz', ''), |
1711
|
|
|
array(array('foo,bar,baz'), 'foo,bar,baz', '-'), |
1712
|
|
|
array(array('foo', 'bar', 'baz'), 'foo,bar,baz', ','), |
1713
|
|
|
array(array('foo', 'bar', 'baz'), 'foo,bar,baz', ',', null), |
1714
|
|
|
array(array('foo', 'bar', 'baz'), 'foo,bar,baz', ',', -1), |
1715
|
|
|
array(array(), 'foo,bar,baz', ',', 0), |
1716
|
|
|
array(array('foo'), 'foo,bar,baz', ',', 1), |
1717
|
|
|
array(array('foo', 'bar'), 'foo,bar,baz', ',', 2), |
1718
|
|
|
array(array('foo', 'bar', 'baz'), 'foo,bar,baz', ',', 3), |
1719
|
|
|
array(array('foo', 'bar', 'baz'), 'foo,bar,baz', ',', 10), |
1720
|
|
|
array(array('fòô,bàř,baz'), 'fòô,bàř,baz', '-', null, 'UTF-8'), |
1721
|
|
|
array(array('fòô', 'bàř', 'baz'), 'fòô,bàř,baz', ',', null, 'UTF-8'), |
1722
|
|
|
array(array('fòô', 'bàř', 'baz'), 'fòô,bàř,baz', ',', null, 'UTF-8'), |
1723
|
|
|
array(array('fòô', 'bàř', 'baz'), 'fòô,bàř,baz', ',', -1, 'UTF-8'), |
1724
|
|
|
array(array(), 'fòô,bàř,baz', ',', 0, 'UTF-8'), |
1725
|
|
|
array(array('fòô'), 'fòô,bàř,baz', ',', 1, 'UTF-8'), |
1726
|
|
|
array(array('fòô', 'bàř'), 'fòô,bàř,baz', ',', 2, 'UTF-8'), |
1727
|
|
|
array(array('fòô', 'bàř', 'baz'), 'fòô,bàř,baz', ',', 3, 'UTF-8'), |
1728
|
|
|
array(array('fòô', 'bàř', 'baz'), 'fòô,bàř,baz', ',', 10, 'UTF-8') |
1729
|
|
|
); |
1730
|
|
|
} |
1731
|
|
|
|
1732
|
|
|
/** |
1733
|
|
|
* @dataProvider substrProvider() |
1734
|
|
|
*/ |
1735
|
|
View Code Duplication |
public function testSubstr($expected, $str, $start, $length = null, |
|
|
|
|
1736
|
|
|
$encoding = null) |
1737
|
|
|
{ |
1738
|
|
|
$stringy = S::create($str, $encoding); |
1739
|
|
|
$result = $stringy->substr($start, $length); |
1740
|
|
|
$this->assertStringy($result); |
1741
|
|
|
$this->assertEquals($expected, $result); |
1742
|
|
|
$this->assertEquals($str, $stringy); |
1743
|
|
|
} |
1744
|
|
|
|
1745
|
|
|
public function substrProvider() |
1746
|
|
|
{ |
1747
|
|
|
return array( |
1748
|
|
|
array('foo bar', 'foo bar', 0), |
1749
|
|
|
array('bar', 'foo bar', 4), |
1750
|
|
|
array('bar', 'foo bar', 4, null), |
1751
|
|
|
array('o b', 'foo bar', 2, 3), |
1752
|
|
|
array('', 'foo bar', 4, 0), |
1753
|
|
|
array('fòô bàř', 'fòô bàř', 0, null, 'UTF-8'), |
1754
|
|
|
array('bàř', 'fòô bàř', 4, null, 'UTF-8'), |
1755
|
|
|
array('ô b', 'fòô bàř', 2, 3, 'UTF-8'), |
1756
|
|
|
array('', 'fòô bàř', 4, 0, 'UTF-8') |
1757
|
|
|
); |
1758
|
|
|
} |
1759
|
|
|
|
1760
|
|
|
/** |
1761
|
|
|
* @dataProvider atProvider() |
1762
|
|
|
*/ |
1763
|
|
View Code Duplication |
public function testAt($expected, $str, $index, $encoding = null) |
|
|
|
|
1764
|
|
|
{ |
1765
|
|
|
$stringy = S::create($str, $encoding); |
1766
|
|
|
$result = $stringy->at($index); |
1767
|
|
|
$this->assertStringy($result); |
1768
|
|
|
$this->assertEquals($expected, $result); |
1769
|
|
|
$this->assertEquals($str, $stringy); |
1770
|
|
|
} |
1771
|
|
|
|
1772
|
|
|
public function atProvider() |
1773
|
|
|
{ |
1774
|
|
|
return array( |
1775
|
|
|
array('f', 'foo bar', 0), |
1776
|
|
|
array('o', 'foo bar', 1), |
1777
|
|
|
array('r', 'foo bar', 6), |
1778
|
|
|
array('', 'foo bar', 7), |
1779
|
|
|
array('f', 'fòô bàř', 0, 'UTF-8'), |
1780
|
|
|
array('ò', 'fòô bàř', 1, 'UTF-8'), |
1781
|
|
|
array('ř', 'fòô bàř', 6, 'UTF-8'), |
1782
|
|
|
array('', 'fòô bàř', 7, 'UTF-8'), |
1783
|
|
|
); |
1784
|
|
|
} |
1785
|
|
|
|
1786
|
|
|
/** |
1787
|
|
|
* @dataProvider firstProvider() |
1788
|
|
|
*/ |
1789
|
|
View Code Duplication |
public function testFirst($expected, $str, $n, $encoding = null) |
|
|
|
|
1790
|
|
|
{ |
1791
|
|
|
$stringy = S::create($str, $encoding); |
1792
|
|
|
$result = $stringy->first($n); |
1793
|
|
|
$this->assertStringy($result); |
1794
|
|
|
$this->assertEquals($expected, $result); |
1795
|
|
|
$this->assertEquals($str, $stringy); |
1796
|
|
|
} |
1797
|
|
|
|
1798
|
|
View Code Duplication |
public function firstProvider() |
|
|
|
|
1799
|
|
|
{ |
1800
|
|
|
return array( |
1801
|
|
|
array('', 'foo bar', -5), |
1802
|
|
|
array('', 'foo bar', 0), |
1803
|
|
|
array('f', 'foo bar', 1), |
1804
|
|
|
array('foo', 'foo bar', 3), |
1805
|
|
|
array('foo bar', 'foo bar', 7), |
1806
|
|
|
array('foo bar', 'foo bar', 8), |
1807
|
|
|
array('', 'fòô bàř', -5, 'UTF-8'), |
1808
|
|
|
array('', 'fòô bàř', 0, 'UTF-8'), |
1809
|
|
|
array('f', 'fòô bàř', 1, 'UTF-8'), |
1810
|
|
|
array('fòô', 'fòô bàř', 3, 'UTF-8'), |
1811
|
|
|
array('fòô bàř', 'fòô bàř', 7, 'UTF-8'), |
1812
|
|
|
array('fòô bàř', 'fòô bàř', 8, 'UTF-8'), |
1813
|
|
|
); |
1814
|
|
|
} |
1815
|
|
|
|
1816
|
|
|
/** |
1817
|
|
|
* @dataProvider lastProvider() |
1818
|
|
|
*/ |
1819
|
|
View Code Duplication |
public function testLast($expected, $str, $n, $encoding = null) |
|
|
|
|
1820
|
|
|
{ |
1821
|
|
|
$stringy = S::create($str, $encoding); |
1822
|
|
|
$result = $stringy->last($n); |
1823
|
|
|
$this->assertStringy($result); |
1824
|
|
|
$this->assertEquals($expected, $result); |
1825
|
|
|
$this->assertEquals($str, $stringy); |
1826
|
|
|
} |
1827
|
|
|
|
1828
|
|
View Code Duplication |
public function lastProvider() |
|
|
|
|
1829
|
|
|
{ |
1830
|
|
|
return array( |
1831
|
|
|
array('', 'foo bar', -5), |
1832
|
|
|
array('', 'foo bar', 0), |
1833
|
|
|
array('r', 'foo bar', 1), |
1834
|
|
|
array('bar', 'foo bar', 3), |
1835
|
|
|
array('foo bar', 'foo bar', 7), |
1836
|
|
|
array('foo bar', 'foo bar', 8), |
1837
|
|
|
array('', 'fòô bàř', -5, 'UTF-8'), |
1838
|
|
|
array('', 'fòô bàř', 0, 'UTF-8'), |
1839
|
|
|
array('ř', 'fòô bàř', 1, 'UTF-8'), |
1840
|
|
|
array('bàř', 'fòô bàř', 3, 'UTF-8'), |
1841
|
|
|
array('fòô bàř', 'fòô bàř', 7, 'UTF-8'), |
1842
|
|
|
array('fòô bàř', 'fòô bàř', 8, 'UTF-8'), |
1843
|
|
|
); |
1844
|
|
|
} |
1845
|
|
|
|
1846
|
|
|
/** |
1847
|
|
|
* @dataProvider ensureLeftProvider() |
1848
|
|
|
*/ |
1849
|
|
View Code Duplication |
public function testEnsureLeft($expected, $str, $substring, $encoding = null) |
|
|
|
|
1850
|
|
|
{ |
1851
|
|
|
$stringy = S::create($str, $encoding); |
1852
|
|
|
$result = $stringy->ensureLeft($substring); |
1853
|
|
|
$this->assertStringy($result); |
1854
|
|
|
$this->assertEquals($expected, $result); |
1855
|
|
|
$this->assertEquals($str, $stringy); |
1856
|
|
|
} |
1857
|
|
|
|
1858
|
|
View Code Duplication |
public function ensureLeftProvider() |
|
|
|
|
1859
|
|
|
{ |
1860
|
|
|
return array( |
1861
|
|
|
array('foobar', 'foobar', 'f'), |
1862
|
|
|
array('foobar', 'foobar', 'foo'), |
1863
|
|
|
array('foo/foobar', 'foobar', 'foo/'), |
1864
|
|
|
array('http://foobar', 'foobar', 'http://'), |
1865
|
|
|
array('http://foobar', 'http://foobar', 'http://'), |
1866
|
|
|
array('fòôbàř', 'fòôbàř', 'f', 'UTF-8'), |
1867
|
|
|
array('fòôbàř', 'fòôbàř', 'fòô', 'UTF-8'), |
1868
|
|
|
array('fòô/fòôbàř', 'fòôbàř', 'fòô/', 'UTF-8'), |
1869
|
|
|
array('http://fòôbàř', 'fòôbàř', 'http://', 'UTF-8'), |
1870
|
|
|
array('http://fòôbàř', 'http://fòôbàř', 'http://', 'UTF-8'), |
1871
|
|
|
); |
1872
|
|
|
} |
1873
|
|
|
|
1874
|
|
|
/** |
1875
|
|
|
* @dataProvider ensureRightProvider() |
1876
|
|
|
*/ |
1877
|
|
View Code Duplication |
public function testEnsureRight($expected, $str, $substring, $encoding = null) |
|
|
|
|
1878
|
|
|
{ |
1879
|
|
|
$stringy = S::create($str, $encoding); |
1880
|
|
|
$result = $stringy->ensureRight($substring); |
1881
|
|
|
$this->assertStringy($result); |
1882
|
|
|
$this->assertEquals($expected, $result); |
1883
|
|
|
$this->assertEquals($str, $stringy); |
1884
|
|
|
} |
1885
|
|
|
|
1886
|
|
View Code Duplication |
public function ensureRightProvider() |
|
|
|
|
1887
|
|
|
{ |
1888
|
|
|
return array( |
1889
|
|
|
array('foobar', 'foobar', 'r'), |
1890
|
|
|
array('foobar', 'foobar', 'bar'), |
1891
|
|
|
array('foobar/bar', 'foobar', '/bar'), |
1892
|
|
|
array('foobar.com/', 'foobar', '.com/'), |
1893
|
|
|
array('foobar.com/', 'foobar.com/', '.com/'), |
1894
|
|
|
array('fòôbàř', 'fòôbàř', 'ř', 'UTF-8'), |
1895
|
|
|
array('fòôbàř', 'fòôbàř', 'bàř', 'UTF-8'), |
1896
|
|
|
array('fòôbàř/bàř', 'fòôbàř', '/bàř', 'UTF-8'), |
1897
|
|
|
array('fòôbàř.com/', 'fòôbàř', '.com/', 'UTF-8'), |
1898
|
|
|
array('fòôbàř.com/', 'fòôbàř.com/', '.com/', 'UTF-8'), |
1899
|
|
|
); |
1900
|
|
|
} |
1901
|
|
|
|
1902
|
|
|
/** |
1903
|
|
|
* @dataProvider removeLeftProvider() |
1904
|
|
|
*/ |
1905
|
|
View Code Duplication |
public function testRemoveLeft($expected, $str, $substring, $encoding = null) |
|
|
|
|
1906
|
|
|
{ |
1907
|
|
|
$stringy = S::create($str, $encoding); |
1908
|
|
|
$result = $stringy->removeLeft($substring); |
1909
|
|
|
$this->assertStringy($result); |
1910
|
|
|
$this->assertEquals($expected, $result); |
1911
|
|
|
$this->assertEquals($str, $stringy); |
1912
|
|
|
} |
1913
|
|
|
|
1914
|
|
View Code Duplication |
public function removeLeftProvider() |
|
|
|
|
1915
|
|
|
{ |
1916
|
|
|
return array( |
1917
|
|
|
array('foo bar', 'foo bar', ''), |
1918
|
|
|
array('oo bar', 'foo bar', 'f'), |
1919
|
|
|
array('bar', 'foo bar', 'foo '), |
1920
|
|
|
array('foo bar', 'foo bar', 'oo'), |
1921
|
|
|
array('foo bar', 'foo bar', 'oo bar'), |
1922
|
|
|
array('oo bar', 'foo bar', S::create('foo bar')->first(1), 'UTF-8'), |
1923
|
|
|
array('oo bar', 'foo bar', S::create('foo bar')->at(0), 'UTF-8'), |
1924
|
|
|
array('fòô bàř', 'fòô bàř', '', 'UTF-8'), |
1925
|
|
|
array('òô bàř', 'fòô bàř', 'f', 'UTF-8'), |
1926
|
|
|
array('bàř', 'fòô bàř', 'fòô ', 'UTF-8'), |
1927
|
|
|
array('fòô bàř', 'fòô bàř', 'òô', 'UTF-8'), |
1928
|
|
|
array('fòô bàř', 'fòô bàř', 'òô bàř', 'UTF-8') |
1929
|
|
|
); |
1930
|
|
|
} |
1931
|
|
|
|
1932
|
|
|
/** |
1933
|
|
|
* @dataProvider removeRightProvider() |
1934
|
|
|
*/ |
1935
|
|
View Code Duplication |
public function testRemoveRight($expected, $str, $substring, $encoding = null) |
|
|
|
|
1936
|
|
|
{ |
1937
|
|
|
$stringy = S::create($str, $encoding); |
1938
|
|
|
$result = $stringy->removeRight($substring); |
1939
|
|
|
$this->assertStringy($result); |
1940
|
|
|
$this->assertEquals($expected, $result); |
1941
|
|
|
$this->assertEquals($str, $stringy); |
1942
|
|
|
} |
1943
|
|
|
|
1944
|
|
View Code Duplication |
public function removeRightProvider() |
|
|
|
|
1945
|
|
|
{ |
1946
|
|
|
return array( |
1947
|
|
|
array('foo bar', 'foo bar', ''), |
1948
|
|
|
array('foo ba', 'foo bar', 'r'), |
1949
|
|
|
array('foo', 'foo bar', ' bar'), |
1950
|
|
|
array('foo bar', 'foo bar', 'ba'), |
1951
|
|
|
array('foo bar', 'foo bar', 'foo ba'), |
1952
|
|
|
array('foo ba', 'foo bar', S::create('foo bar')->last(1), 'UTF-8'), |
1953
|
|
|
array('foo ba', 'foo bar', S::create('foo bar')->at(6), 'UTF-8'), |
1954
|
|
|
array('fòô bàř', 'fòô bàř', '', 'UTF-8'), |
1955
|
|
|
array('fòô bà', 'fòô bàř', 'ř', 'UTF-8'), |
1956
|
|
|
array('fòô', 'fòô bàř', ' bàř', 'UTF-8'), |
1957
|
|
|
array('fòô bàř', 'fòô bàř', 'bà', 'UTF-8'), |
1958
|
|
|
array('fòô bàř', 'fòô bàř', 'fòô bà', 'UTF-8') |
1959
|
|
|
); |
1960
|
|
|
} |
1961
|
|
|
|
1962
|
|
|
/** |
1963
|
|
|
* @dataProvider isAlphaProvider() |
1964
|
|
|
*/ |
1965
|
|
View Code Duplication |
public function testIsAlpha($expected, $str, $encoding = null) |
|
|
|
|
1966
|
|
|
{ |
1967
|
|
|
$stringy = S::create($str, $encoding); |
1968
|
|
|
$result = $stringy->isAlpha(); |
1969
|
|
|
$this->assertInternalType('boolean', $result); |
1970
|
|
|
$this->assertEquals($expected, $result); |
1971
|
|
|
$this->assertEquals($str, $stringy); |
1972
|
|
|
} |
1973
|
|
|
|
1974
|
|
|
public function isAlphaProvider() |
1975
|
|
|
{ |
1976
|
|
|
return array( |
1977
|
|
|
array(true, ''), |
1978
|
|
|
array(true, 'foobar'), |
1979
|
|
|
array(false, 'foo bar'), |
1980
|
|
|
array(false, 'foobar2'), |
1981
|
|
|
array(true, 'fòôbàř', 'UTF-8'), |
1982
|
|
|
array(false, 'fòô bàř', 'UTF-8'), |
1983
|
|
|
array(false, 'fòôbàř2', 'UTF-8'), |
1984
|
|
|
array(true, 'ҠѨњфгШ', 'UTF-8'), |
1985
|
|
|
array(false, 'ҠѨњ¨ˆфгШ', 'UTF-8'), |
1986
|
|
|
array(true, '丹尼爾', 'UTF-8') |
1987
|
|
|
); |
1988
|
|
|
} |
1989
|
|
|
|
1990
|
|
|
/** |
1991
|
|
|
* @dataProvider isAlphanumericProvider() |
1992
|
|
|
*/ |
1993
|
|
View Code Duplication |
public function testIsAlphanumeric($expected, $str, $encoding = null) |
|
|
|
|
1994
|
|
|
{ |
1995
|
|
|
$stringy = S::create($str, $encoding); |
1996
|
|
|
$result = $stringy->isAlphanumeric(); |
1997
|
|
|
$this->assertInternalType('boolean', $result); |
1998
|
|
|
$this->assertEquals($expected, $result); |
1999
|
|
|
$this->assertEquals($str, $stringy); |
2000
|
|
|
} |
2001
|
|
|
|
2002
|
|
View Code Duplication |
public function isAlphanumericProvider() |
|
|
|
|
2003
|
|
|
{ |
2004
|
|
|
return array( |
2005
|
|
|
array(true, ''), |
2006
|
|
|
array(true, 'foobar1'), |
2007
|
|
|
array(false, 'foo bar'), |
2008
|
|
|
array(false, 'foobar2"'), |
2009
|
|
|
array(false, "\nfoobar\n"), |
2010
|
|
|
array(true, 'fòôbàř1', 'UTF-8'), |
2011
|
|
|
array(false, 'fòô bàř', 'UTF-8'), |
2012
|
|
|
array(false, 'fòôbàř2"', 'UTF-8'), |
2013
|
|
|
array(true, 'ҠѨњфгШ', 'UTF-8'), |
2014
|
|
|
array(false, 'ҠѨњ¨ˆфгШ', 'UTF-8'), |
2015
|
|
|
array(true, '丹尼爾111', 'UTF-8'), |
2016
|
|
|
array(true, 'دانيال1', 'UTF-8'), |
2017
|
|
|
array(false, 'دانيال1 ', 'UTF-8') |
2018
|
|
|
); |
2019
|
|
|
} |
2020
|
|
|
|
2021
|
|
|
/** |
2022
|
|
|
* @dataProvider isBlankProvider() |
2023
|
|
|
*/ |
2024
|
|
View Code Duplication |
public function testIsBlank($expected, $str, $encoding = null) |
|
|
|
|
2025
|
|
|
{ |
2026
|
|
|
$stringy = S::create($str, $encoding); |
2027
|
|
|
$result = $stringy->isBlank(); |
2028
|
|
|
$this->assertInternalType('boolean', $result); |
2029
|
|
|
$this->assertEquals($expected, $result); |
2030
|
|
|
$this->assertEquals($str, $stringy); |
2031
|
|
|
} |
2032
|
|
|
|
2033
|
|
|
public function isBlankProvider() |
2034
|
|
|
{ |
2035
|
|
|
return array( |
2036
|
|
|
array(true, ''), |
2037
|
|
|
array(true, ' '), |
2038
|
|
|
array(true, "\n\t "), |
2039
|
|
|
array(true, "\n\t \v\f"), |
2040
|
|
|
array(false, "\n\t a \v\f"), |
2041
|
|
|
array(false, "\n\t ' \v\f"), |
2042
|
|
|
array(false, "\n\t 2 \v\f"), |
2043
|
|
|
array(true, '', 'UTF-8'), |
2044
|
|
|
array(true, ' ', 'UTF-8'), // no-break space (U+00A0) |
2045
|
|
|
array(true, ' ', 'UTF-8'), // spaces U+2000 to U+200A |
2046
|
|
|
array(true, ' ', 'UTF-8'), // narrow no-break space (U+202F) |
2047
|
|
|
array(true, ' ', 'UTF-8'), // medium mathematical space (U+205F) |
2048
|
|
|
array(true, ' ', 'UTF-8'), // ideographic space (U+3000) |
2049
|
|
|
array(false, ' z', 'UTF-8'), |
2050
|
|
|
array(false, ' 1', 'UTF-8'), |
2051
|
|
|
); |
2052
|
|
|
} |
2053
|
|
|
|
2054
|
|
|
/** |
2055
|
|
|
* @dataProvider isJsonProvider() |
2056
|
|
|
*/ |
2057
|
|
View Code Duplication |
public function testIsJson($expected, $str, $encoding = null) |
|
|
|
|
2058
|
|
|
{ |
2059
|
|
|
$stringy = S::create($str, $encoding); |
2060
|
|
|
$result = $stringy->isJson(); |
2061
|
|
|
$this->assertInternalType('boolean', $result); |
2062
|
|
|
$this->assertEquals($expected, $result); |
2063
|
|
|
$this->assertEquals($str, $stringy); |
2064
|
|
|
} |
2065
|
|
|
|
2066
|
|
View Code Duplication |
public function isJsonProvider() |
|
|
|
|
2067
|
|
|
{ |
2068
|
|
|
return array( |
2069
|
|
|
array(true, ''), |
2070
|
|
|
array(true, '123'), |
2071
|
|
|
array(true, '{"foo": "bar"}'), |
2072
|
|
|
array(false, '{"foo":"bar",}'), |
2073
|
|
|
array(false, '{"foo"}'), |
2074
|
|
|
array(true, '["foo"]'), |
2075
|
|
|
array(false, '{"foo": "bar"]'), |
2076
|
|
|
array(true, '123', 'UTF-8'), |
2077
|
|
|
array(true, '{"fòô": "bàř"}', 'UTF-8'), |
2078
|
|
|
array(false, '{"fòô":"bàř",}', 'UTF-8'), |
2079
|
|
|
array(false, '{"fòô"}', 'UTF-8'), |
2080
|
|
|
array(false, '["fòô": "bàř"]', 'UTF-8'), |
2081
|
|
|
array(true, '["fòô"]', 'UTF-8'), |
2082
|
|
|
array(false, '{"fòô": "bàř"]', 'UTF-8'), |
2083
|
|
|
); |
2084
|
|
|
} |
2085
|
|
|
|
2086
|
|
|
/** |
2087
|
|
|
* @dataProvider isLowerCaseProvider() |
2088
|
|
|
*/ |
2089
|
|
View Code Duplication |
public function testIsLowerCase($expected, $str, $encoding = null) |
|
|
|
|
2090
|
|
|
{ |
2091
|
|
|
$stringy = S::create($str, $encoding); |
2092
|
|
|
$result = $stringy->isLowerCase(); |
2093
|
|
|
$this->assertInternalType('boolean', $result); |
2094
|
|
|
$this->assertEquals($expected, $result); |
2095
|
|
|
$this->assertEquals($str, $stringy); |
2096
|
|
|
} |
2097
|
|
|
|
2098
|
|
View Code Duplication |
public function isLowerCaseProvider() |
|
|
|
|
2099
|
|
|
{ |
2100
|
|
|
return array( |
2101
|
|
|
array(true, ''), |
2102
|
|
|
array(true, 'foobar'), |
2103
|
|
|
array(false, 'foo bar'), |
2104
|
|
|
array(false, 'Foobar'), |
2105
|
|
|
array(true, 'fòôbàř', 'UTF-8'), |
2106
|
|
|
array(false, 'fòôbàř2', 'UTF-8'), |
2107
|
|
|
array(false, 'fòô bàř', 'UTF-8'), |
2108
|
|
|
array(false, 'fòôbÀŘ', 'UTF-8'), |
2109
|
|
|
); |
2110
|
|
|
} |
2111
|
|
|
|
2112
|
|
|
/** |
2113
|
|
|
* @dataProvider hasLowerCaseProvider() |
2114
|
|
|
*/ |
2115
|
|
View Code Duplication |
public function testHasLowerCase($expected, $str, $encoding = null) |
|
|
|
|
2116
|
|
|
{ |
2117
|
|
|
$stringy = S::create($str, $encoding); |
2118
|
|
|
$result = $stringy->hasLowerCase(); |
2119
|
|
|
$this->assertInternalType('boolean', $result); |
2120
|
|
|
$this->assertEquals($expected, $result); |
2121
|
|
|
$this->assertEquals($str, $stringy); |
2122
|
|
|
} |
2123
|
|
|
|
2124
|
|
View Code Duplication |
public function hasLowerCaseProvider() |
|
|
|
|
2125
|
|
|
{ |
2126
|
|
|
return array( |
2127
|
|
|
array(false, ''), |
2128
|
|
|
array(true, 'foobar'), |
2129
|
|
|
array(false, 'FOO BAR'), |
2130
|
|
|
array(true, 'fOO BAR'), |
2131
|
|
|
array(true, 'foO BAR'), |
2132
|
|
|
array(true, 'FOO BAr'), |
2133
|
|
|
array(true, 'Foobar'), |
2134
|
|
|
array(false, 'FÒÔBÀŘ', 'UTF-8'), |
2135
|
|
|
array(true, 'fòôbàř', 'UTF-8'), |
2136
|
|
|
array(true, 'fòôbàř2', 'UTF-8'), |
2137
|
|
|
array(true, 'Fòô bàř', 'UTF-8'), |
2138
|
|
|
array(true, 'fòôbÀŘ', 'UTF-8'), |
2139
|
|
|
); |
2140
|
|
|
} |
2141
|
|
|
|
2142
|
|
|
/** |
2143
|
|
|
* @dataProvider isSerializedProvider() |
2144
|
|
|
*/ |
2145
|
|
View Code Duplication |
public function testIsSerialized($expected, $str, $encoding = null) |
|
|
|
|
2146
|
|
|
{ |
2147
|
|
|
$stringy = S::create($str, $encoding); |
2148
|
|
|
$result = $stringy->isSerialized(); |
2149
|
|
|
$this->assertInternalType('boolean', $result); |
2150
|
|
|
$this->assertEquals($expected, $result); |
2151
|
|
|
$this->assertEquals($str, $stringy); |
2152
|
|
|
} |
2153
|
|
|
|
2154
|
|
|
public function isSerializedProvider() |
2155
|
|
|
{ |
2156
|
|
|
return array( |
2157
|
|
|
array(false, ''), |
2158
|
|
|
array(true, 'a:1:{s:3:"foo";s:3:"bar";}'), |
2159
|
|
|
array(false, 'a:1:{s:3:"foo";s:3:"bar"}'), |
2160
|
|
|
array(true, serialize(array('foo' => 'bar'))), |
2161
|
|
|
array(true, 'a:1:{s:5:"fòô";s:5:"bàř";}', 'UTF-8'), |
2162
|
|
|
array(false, 'a:1:{s:5:"fòô";s:5:"bàř"}', 'UTF-8'), |
2163
|
|
|
array(true, serialize(array('fòô' => 'bár')), 'UTF-8'), |
2164
|
|
|
); |
2165
|
|
|
} |
2166
|
|
|
|
2167
|
|
|
/** |
2168
|
|
|
* @dataProvider isUpperCaseProvider() |
2169
|
|
|
*/ |
2170
|
|
View Code Duplication |
public function testIsUpperCase($expected, $str, $encoding = null) |
|
|
|
|
2171
|
|
|
{ |
2172
|
|
|
$stringy = S::create($str, $encoding); |
2173
|
|
|
$result = $stringy->isUpperCase(); |
2174
|
|
|
$this->assertInternalType('boolean', $result); |
2175
|
|
|
$this->assertEquals($expected, $result); |
2176
|
|
|
$this->assertEquals($str, $stringy); |
2177
|
|
|
} |
2178
|
|
|
|
2179
|
|
View Code Duplication |
public function isUpperCaseProvider() |
|
|
|
|
2180
|
|
|
{ |
2181
|
|
|
return array( |
2182
|
|
|
array(true, ''), |
2183
|
|
|
array(true, 'FOOBAR'), |
2184
|
|
|
array(false, 'FOO BAR'), |
2185
|
|
|
array(false, 'fOOBAR'), |
2186
|
|
|
array(true, 'FÒÔBÀŘ', 'UTF-8'), |
2187
|
|
|
array(false, 'FÒÔBÀŘ2', 'UTF-8'), |
2188
|
|
|
array(false, 'FÒÔ BÀŘ', 'UTF-8'), |
2189
|
|
|
array(false, 'FÒÔBàř', 'UTF-8'), |
2190
|
|
|
); |
2191
|
|
|
} |
2192
|
|
|
|
2193
|
|
|
/** |
2194
|
|
|
* @dataProvider hasUpperCaseProvider() |
2195
|
|
|
*/ |
2196
|
|
View Code Duplication |
public function testHasUpperCase($expected, $str, $encoding = null) |
|
|
|
|
2197
|
|
|
{ |
2198
|
|
|
$stringy = S::create($str, $encoding); |
2199
|
|
|
$result = $stringy->hasUpperCase(); |
2200
|
|
|
$this->assertInternalType('boolean', $result); |
2201
|
|
|
$this->assertEquals($expected, $result); |
2202
|
|
|
$this->assertEquals($str, $stringy); |
2203
|
|
|
} |
2204
|
|
|
|
2205
|
|
View Code Duplication |
public function hasUpperCaseProvider() |
|
|
|
|
2206
|
|
|
{ |
2207
|
|
|
return array( |
2208
|
|
|
array(false, ''), |
2209
|
|
|
array(true, 'FOOBAR'), |
2210
|
|
|
array(false, 'foo bar'), |
2211
|
|
|
array(true, 'Foo bar'), |
2212
|
|
|
array(true, 'FOo bar'), |
2213
|
|
|
array(true, 'foo baR'), |
2214
|
|
|
array(true, 'fOOBAR'), |
2215
|
|
|
array(false, 'fòôbàř', 'UTF-8'), |
2216
|
|
|
array(true, 'FÒÔBÀŘ', 'UTF-8'), |
2217
|
|
|
array(true, 'FÒÔBÀŘ2', 'UTF-8'), |
2218
|
|
|
array(true, 'fÒÔ BÀŘ', 'UTF-8'), |
2219
|
|
|
array(true, 'FÒÔBàř', 'UTF-8'), |
2220
|
|
|
); |
2221
|
|
|
} |
2222
|
|
|
|
2223
|
|
|
/** |
2224
|
|
|
* @dataProvider isHexadecimalProvider() |
2225
|
|
|
*/ |
2226
|
|
View Code Duplication |
public function testIsHexadecimal($expected, $str, $encoding = null) |
|
|
|
|
2227
|
|
|
{ |
2228
|
|
|
$stringy = S::create($str, $encoding); |
2229
|
|
|
$result = $stringy->isHexadecimal(); |
2230
|
|
|
$this->assertInternalType('boolean', $result); |
2231
|
|
|
$this->assertEquals($expected, $result); |
2232
|
|
|
$this->assertEquals($str, $stringy); |
2233
|
|
|
} |
2234
|
|
|
|
2235
|
|
|
public function isHexadecimalProvider() |
2236
|
|
|
{ |
2237
|
|
|
return array( |
2238
|
|
|
array(true, ''), |
2239
|
|
|
array(true, 'abcdef'), |
2240
|
|
|
array(true, 'ABCDEF'), |
2241
|
|
|
array(true, '0123456789'), |
2242
|
|
|
array(true, '0123456789AbCdEf'), |
2243
|
|
|
array(false, '0123456789x'), |
2244
|
|
|
array(false, 'ABCDEFx'), |
2245
|
|
|
array(true, 'abcdef', 'UTF-8'), |
2246
|
|
|
array(true, 'ABCDEF', 'UTF-8'), |
2247
|
|
|
array(true, '0123456789', 'UTF-8'), |
2248
|
|
|
array(true, '0123456789AbCdEf', 'UTF-8'), |
2249
|
|
|
array(false, '0123456789x', 'UTF-8'), |
2250
|
|
|
array(false, 'ABCDEFx', 'UTF-8'), |
2251
|
|
|
); |
2252
|
|
|
} |
2253
|
|
|
|
2254
|
|
|
/** |
2255
|
|
|
* @dataProvider countSubstrProvider() |
2256
|
|
|
*/ |
2257
|
|
|
public function testCountSubstr($expected, $str, $substring, |
2258
|
|
|
$caseSensitive = true, $encoding = null) |
2259
|
|
|
{ |
2260
|
|
|
$stringy = S::create($str, $encoding); |
2261
|
|
|
$result = $stringy->countSubstr($substring, $caseSensitive); |
2262
|
|
|
$this->assertInternalType('int', $result); |
2263
|
|
|
$this->assertEquals($expected, $result); |
2264
|
|
|
$this->assertEquals($str, $stringy); |
2265
|
|
|
} |
2266
|
|
|
|
2267
|
|
|
public function countSubstrProvider() |
2268
|
|
|
{ |
2269
|
|
|
return array( |
2270
|
|
|
array(0, '', 'foo'), |
2271
|
|
|
array(0, 'foo', 'bar'), |
2272
|
|
|
array(1, 'foo bar', 'foo'), |
2273
|
|
|
array(2, 'foo bar', 'o'), |
2274
|
|
|
array(0, '', 'fòô', 'UTF-8'), |
2275
|
|
|
array(0, 'fòô', 'bàř', 'UTF-8'), |
2276
|
|
|
array(1, 'fòô bàř', 'fòô', 'UTF-8'), |
2277
|
|
|
array(2, 'fôòô bàř', 'ô', 'UTF-8'), |
2278
|
|
|
array(0, 'fÔÒÔ bàř', 'ô', 'UTF-8'), |
2279
|
|
|
array(0, 'foo', 'BAR', false), |
2280
|
|
|
array(1, 'foo bar', 'FOo', false), |
2281
|
|
|
array(2, 'foo bar', 'O', false), |
2282
|
|
|
array(1, 'fòô bàř', 'fÒÔ', false, 'UTF-8'), |
2283
|
|
|
array(2, 'fôòô bàř', 'Ô', false, 'UTF-8'), |
2284
|
|
|
array(2, 'συγγραφέας', 'Σ', false, 'UTF-8') |
2285
|
|
|
); |
2286
|
|
|
} |
2287
|
|
|
|
2288
|
|
|
/** |
2289
|
|
|
* @dataProvider replaceProvider() |
2290
|
|
|
*/ |
2291
|
|
View Code Duplication |
public function testReplace($expected, $str, $search, $replacement, |
|
|
|
|
2292
|
|
|
$encoding = null) |
2293
|
|
|
{ |
2294
|
|
|
$stringy = S::create($str, $encoding); |
2295
|
|
|
$result = $stringy->replace($search, $replacement); |
2296
|
|
|
$this->assertStringy($result); |
2297
|
|
|
$this->assertEquals($expected, $result); |
2298
|
|
|
$this->assertEquals($str, $stringy); |
2299
|
|
|
} |
2300
|
|
|
|
2301
|
|
|
public function replaceProvider() |
2302
|
|
|
{ |
2303
|
|
|
return array( |
2304
|
|
|
array('', '', '', ''), |
2305
|
|
|
array('foo', '', '', 'foo'), |
2306
|
|
|
array('foo', '\s', '\s', 'foo'), |
2307
|
|
|
array('foo bar', 'foo bar', '', ''), |
2308
|
|
|
array('foo bar', 'foo bar', 'f(o)o', '\1'), |
2309
|
|
|
array('\1 bar', 'foo bar', 'foo', '\1'), |
2310
|
|
|
array('bar', 'foo bar', 'foo ', ''), |
2311
|
|
|
array('far bar', 'foo bar', 'foo', 'far'), |
2312
|
|
|
array('bar bar', 'foo bar foo bar', 'foo ', ''), |
2313
|
|
|
array('', '', '', '', 'UTF-8'), |
2314
|
|
|
array('fòô', '', '', 'fòô', 'UTF-8'), |
2315
|
|
|
array('fòô', '\s', '\s', 'fòô', 'UTF-8'), |
2316
|
|
|
array('fòô bàř', 'fòô bàř', '', '', 'UTF-8'), |
2317
|
|
|
array('bàř', 'fòô bàř', 'fòô ', '', 'UTF-8'), |
2318
|
|
|
array('far bàř', 'fòô bàř', 'fòô', 'far', 'UTF-8'), |
2319
|
|
|
array('bàř bàř', 'fòô bàř fòô bàř', 'fòô ', '', 'UTF-8'), |
2320
|
|
|
); |
2321
|
|
|
} |
2322
|
|
|
|
2323
|
|
|
/** |
2324
|
|
|
* @dataProvider regexReplaceProvider() |
2325
|
|
|
*/ |
2326
|
|
View Code Duplication |
public function testregexReplace($expected, $str, $pattern, $replacement, |
|
|
|
|
2327
|
|
|
$options = 'msr', $encoding = null) |
2328
|
|
|
{ |
2329
|
|
|
$stringy = S::create($str, $encoding); |
2330
|
|
|
$result = $stringy->regexReplace($pattern, $replacement, $options); |
2331
|
|
|
$this->assertStringy($result); |
2332
|
|
|
$this->assertEquals($expected, $result); |
2333
|
|
|
$this->assertEquals($str, $stringy); |
2334
|
|
|
} |
2335
|
|
|
|
2336
|
|
|
public function regexReplaceProvider() |
2337
|
|
|
{ |
2338
|
|
|
return array( |
2339
|
|
|
array('', '', '', ''), |
2340
|
|
|
array('bar', 'foo', 'f[o]+', 'bar'), |
2341
|
|
|
array('o bar', 'foo bar', 'f(o)o', '\1'), |
2342
|
|
|
array('bar', 'foo bar', 'f[O]+\s', '', 'i'), |
2343
|
|
|
array('foo', 'bar', '[[:alpha:]]{3}', 'foo'), |
2344
|
|
|
array('', '', '', '', 'msr', 'UTF-8'), |
2345
|
|
|
array('bàř', 'fòô ', 'f[òô]+\s', 'bàř', 'msr', 'UTF-8'), |
2346
|
|
|
array('fòô', 'bàř', '[[:alpha:]]{3}', 'fòô', 'msr', 'UTF-8') |
2347
|
|
|
); |
2348
|
|
|
} |
2349
|
|
|
|
2350
|
|
|
/** |
2351
|
|
|
* @dataProvider htmlEncodeProvider() |
2352
|
|
|
*/ |
2353
|
|
View Code Duplication |
public function testHtmlEncode($expected, $str, $flags = ENT_COMPAT, $encoding = null) |
|
|
|
|
2354
|
|
|
{ |
2355
|
|
|
$stringy = S::create($str, $encoding); |
2356
|
|
|
$result = $stringy->htmlEncode($flags); |
2357
|
|
|
$this->assertStringy($result); |
2358
|
|
|
$this->assertEquals($expected, $result); |
2359
|
|
|
$this->assertEquals($str, $stringy); |
2360
|
|
|
} |
2361
|
|
|
|
2362
|
|
View Code Duplication |
public function htmlEncodeProvider() |
|
|
|
|
2363
|
|
|
{ |
2364
|
|
|
return array( |
2365
|
|
|
array('&', '&'), |
2366
|
|
|
array('"', '"'), |
2367
|
|
|
array(''', "'", ENT_QUOTES), |
2368
|
|
|
array('<', '<'), |
2369
|
|
|
array('>', '>'), |
2370
|
|
|
); |
2371
|
|
|
} |
2372
|
|
|
|
2373
|
|
|
/** |
2374
|
|
|
* @dataProvider htmlDecodeProvider() |
2375
|
|
|
*/ |
2376
|
|
View Code Duplication |
public function testHtmlDecode($expected, $str, $flags = ENT_COMPAT, $encoding = null) |
|
|
|
|
2377
|
|
|
{ |
2378
|
|
|
$stringy = S::create($str, $encoding); |
2379
|
|
|
$result = $stringy->htmlDecode($flags); |
2380
|
|
|
$this->assertStringy($result); |
2381
|
|
|
$this->assertEquals($expected, $result); |
2382
|
|
|
$this->assertEquals($str, $stringy); |
2383
|
|
|
} |
2384
|
|
|
|
2385
|
|
View Code Duplication |
public function htmlDecodeProvider() |
|
|
|
|
2386
|
|
|
{ |
2387
|
|
|
return array( |
2388
|
|
|
array('&', '&'), |
2389
|
|
|
array('"', '"'), |
2390
|
|
|
array("'", ''', ENT_QUOTES), |
2391
|
|
|
array('<', '<'), |
2392
|
|
|
array('>', '>'), |
2393
|
|
|
); |
2394
|
|
|
} |
2395
|
|
|
} |
2396
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.