mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-09-01 09:03:03 +02:00
Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
2155447ce8 | ||
|
77efce3a38 | ||
|
f6085ed2cb | ||
|
fa36291254 | ||
|
88145e83e8 | ||
|
9bd5a9c0c8 | ||
|
41ea0277b2 | ||
|
d862f9c24c | ||
|
61cd5f5f4d | ||
|
ea20aebc91 | ||
|
49e1c5ad2a | ||
|
90913d39bc | ||
|
02da00c433 | ||
|
07f23d6165 | ||
|
d27683b570 | ||
|
bc175f0e12 | ||
|
a6964e4561 | ||
|
5fff1a4124 |
15
CHANGELOG.md
15
CHANGELOG.md
@@ -1,3 +1,18 @@
|
||||
### 1.2.1 (2013-10-11)
|
||||
|
||||
* Cleaned up tests
|
||||
* Added homepage to composer.json
|
||||
|
||||
### 1.2.0 (2013-09-15)
|
||||
|
||||
* Fixed pad's use of InvalidArgumentException
|
||||
* Fixed replace(). It now correctly treats regex special chars as normal chars
|
||||
* Added additional Cyrillic letters to toAscii
|
||||
* Added $caseSensitive to contains() and count()
|
||||
* Added toLowerCase()
|
||||
* Added toUpperCase()
|
||||
* Added regexReplace()
|
||||
|
||||
### 1.1.0 (2013-08-31)
|
||||
|
||||
* Fix for collapseWhitespace()
|
||||
|
74
README.md
74
README.md
@@ -38,6 +38,7 @@ A PHP library with a variety of string manipulation functions with multibyte sup
|
||||
* [padBoth](#padboth)
|
||||
* [padLeft](#padleft)
|
||||
* [padRight](#padright)
|
||||
* [regexReplace](#regexreplace)
|
||||
* [removeLeft](#removeleft)
|
||||
* [removeRight](#removeright)
|
||||
* [replace](#replace)
|
||||
@@ -52,8 +53,10 @@ A PHP library with a variety of string manipulation functions with multibyte sup
|
||||
* [tidy](#tidy)
|
||||
* [titleize](#titleize)
|
||||
* [toAscii](#toascii)
|
||||
* [toLowerCase](#tolowercase)
|
||||
* [toSpaces](#tospaces)
|
||||
* [toTabs](#totabs)
|
||||
* [toUpperCase](#touppercase)
|
||||
* [trim](#trim)
|
||||
* [truncate](#truncate)
|
||||
* [underscored](#underscored)
|
||||
@@ -118,9 +121,9 @@ echo S::swapCase($string, 'UTF-8'); // 'fÒÔ bÀŘ'
|
||||
## Methods
|
||||
|
||||
In the list below, any static method other than S::create refers to a
|
||||
method in Stringy\StaticStringy. For all others, they're found in Stringy\Stringy. Furthermore, all methods that return a Stringy object or string do not modify the original.
|
||||
method in `Stringy\StaticStringy`. For all others, they're found in `Stringy\Stringy`. Furthermore, all methods that return a Stringy object or string do not modify the original.
|
||||
|
||||
*Note: If $encoding is not given, it defaults to mb_internal_encoding().*
|
||||
*Note: If `$encoding` is not given, it defaults to `mb_internal_encoding()`.*
|
||||
|
||||
#### at
|
||||
|
||||
@@ -167,11 +170,13 @@ S::collapseWhitespace(' Ο συγγραφέας '); // 'Ο συγγρα
|
||||
|
||||
#### contains
|
||||
|
||||
$stringy->contains(string $needle)
|
||||
$stringy->contains(string $needle [, boolean $caseSensitive = true ])
|
||||
|
||||
S::contains(string $haystack, string $needle [, string $encoding ])
|
||||
S::contains(string $haystack, string $needle [, boolean $caseSensitive = true [, string $encoding ]])
|
||||
|
||||
Returns true if the string contains $needle, false otherwise.
|
||||
Returns true if the string contains $needle, false otherwise. By default,
|
||||
the comparison is case-sensitive, but can be made insensitive
|
||||
by setting $caseSensitive to false.
|
||||
|
||||
```php
|
||||
S::create('Ο συγγραφέας είπε', 'UTF-8')->contains('συγγραφέας');
|
||||
@@ -180,12 +185,13 @@ S::contains('Ο συγγραφέας είπε', 'συγγραφέας', 'UTF-8')
|
||||
|
||||
#### count
|
||||
|
||||
$stringy->count(string $substring)
|
||||
$stringy->count(string $substring [, boolean $caseSensitive = true ])
|
||||
|
||||
S::count(string $str, string $substring [, string $encoding ])
|
||||
S::count(string $str, string $substring [, boolean $caseSensitive = true [, string $encoding ]])
|
||||
|
||||
Returns the number of occurrences of $substring in the given string. An alias for
|
||||
mb_substr_count()
|
||||
Returns the number of occurrences of $substring in the given string.
|
||||
By default, the comparison is case-sensitive, but can be made insensitive
|
||||
by setting $caseSensitive to false.
|
||||
|
||||
```php
|
||||
S::create('Ο συγγραφέας είπε', 'UTF-8')->count('α');
|
||||
@@ -543,6 +549,22 @@ S::create('foo bar')->padRight(10, '_*');
|
||||
S::padRight('foo bar', 10, '_*'); // 'foo bar_*_'
|
||||
```
|
||||
|
||||
#### regexReplace
|
||||
|
||||
$stringy->regexReplace(string $pattern, string $replacement [, string $options = 'msr'])
|
||||
|
||||
S::regexReplace(string $str, string $pattern, string $replacement [, string $options = 'msr' [, string $encoding ]])
|
||||
|
||||
Replaces all occurrences of $pattern in $str by $replacement. An alias
|
||||
for mb_ereg_replace(). Note that the 'i' option with multibyte patterns
|
||||
in mb_ereg_replace() requires PHP 5.4+. This is due to a lack of support
|
||||
in the bundled version of Oniguruma in PHP 5.3.
|
||||
|
||||
```php
|
||||
S::create('fòô ', 'UTF-8')->regexReplace('f[òô]+\s', 'bàř', 'msr');
|
||||
S::regexReplace('fòô ', 'f[òô]+\s', 'bàř', 'msr', 'UTF-8'); // 'bàř'
|
||||
```
|
||||
|
||||
#### removeLeft
|
||||
|
||||
$stringy->removeLeft(string $substring)
|
||||
@@ -571,11 +593,11 @@ S::removeRight('fòô bàř', ' bàř', 'UTF-8'); // 'fòô'
|
||||
|
||||
#### replace
|
||||
|
||||
$stringy->replace(string $search, string $replace)
|
||||
$stringy->replace(string $search, string $replacement)
|
||||
|
||||
S::replace(string $str, string $search, string $replace [, string $encoding ])
|
||||
S::replace(string $str, string $search, string $replacement [, string $encoding ])
|
||||
|
||||
Returns a string with all occurrences of $search replaced with $replace.
|
||||
Replaces all occurrences of $search in $str by $replacement.
|
||||
|
||||
```php
|
||||
S::create('fòô bàř fòô bàř', 'UTF-8')->replace('fòô ', '');
|
||||
@@ -742,6 +764,20 @@ S::create('fòô bàř')->toAscii();
|
||||
S::toAscii('fòô bàř'); // 'foo bar'
|
||||
```
|
||||
|
||||
#### toLowerCase
|
||||
|
||||
$stringy->toLowerCase()
|
||||
|
||||
S::toLowerCase(string $str [, string $encoding ])
|
||||
|
||||
Converts all characters in the string to lowercase. An alias for PHP's
|
||||
mb_strtolower().
|
||||
|
||||
```php
|
||||
S::create('FÒÔ BÀŘ', 'UTF-8')->toLowerCase();
|
||||
S::toLowerCase('FÒÔ BÀŘ', 'UTF-8'); // 'fòô bàř'
|
||||
```
|
||||
|
||||
#### toSpaces
|
||||
|
||||
$stringy->toSpaces([ tabLength = 4 ])
|
||||
@@ -771,6 +807,20 @@ S::create(' fòô bàř')->toTabs();
|
||||
S::toTabs(' fòô bàř'); // ' fòô bàř'
|
||||
```
|
||||
|
||||
#### toUpperCase
|
||||
|
||||
$stringy->toUpperCase()
|
||||
|
||||
S::toUpperCase(string $str [, string $encoding ])
|
||||
|
||||
Converts all characters in the string to uppercase. An alias for PHP's
|
||||
mb_strtoupper().
|
||||
|
||||
```php
|
||||
S::create('fòô bàř', 'UTF-8')->toUpperCase();
|
||||
S::toUpperCase('fòô bàř', 'UTF-8'); // 'FÒÔ BÀŘ'
|
||||
```
|
||||
|
||||
#### trim
|
||||
|
||||
$stringy->trim()
|
||||
|
@@ -5,6 +5,7 @@
|
||||
"multibyte", "string", "manipulation", "utility", "methods", "utf-8",
|
||||
"helpers", "utils", "utf"
|
||||
],
|
||||
"homepage": "https://github.com/danielstjules/Stringy",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
|
@@ -132,7 +132,6 @@ class StaticStringy
|
||||
* equivalents.
|
||||
*
|
||||
* @param string $str String to remove special chars
|
||||
* @param string $encoding The character encoding
|
||||
* @return string String with those characters removed
|
||||
*/
|
||||
public static function tidy($str)
|
||||
@@ -145,7 +144,8 @@ class StaticStringy
|
||||
* single space. This includes tabs and newline characters, as well as
|
||||
* multibyte whitespace such as the thin space and ideographic space.
|
||||
*
|
||||
* @param string $str The string to cleanup whitespace
|
||||
* @param string $str The string to cleanup whitespace
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The trimmed string with condensed whitespace
|
||||
*/
|
||||
public static function collapseWhitespace($str, $encoding = null)
|
||||
@@ -296,6 +296,32 @@ class StaticStringy
|
||||
return Stringy::create($str)->toTabs($tabLength)->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts all characters in the string to lowercase. An alias for PHP's
|
||||
* mb_strtolower().
|
||||
*
|
||||
* @param string $str String to convert case
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The lowercase string
|
||||
*/
|
||||
public static function toLowerCase($str, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->toLowerCase()->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts all characters in the string to uppercase. An alias for PHP's
|
||||
* mb_strtoupper().
|
||||
*
|
||||
* @param string $str String to convert case
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The uppercase string
|
||||
*/
|
||||
public static function toUpperCase($str, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->toUpperCase()->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the string into an URL slug. This includes replacing non-ASCII
|
||||
* characters with their closest ASCII equivalents, removing non-alphanumeric
|
||||
@@ -311,16 +337,20 @@ class StaticStringy
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the string contains $needle, false otherwise.
|
||||
* Returns true if the string contains $needle, false otherwise. By default,
|
||||
* the comparison is case-sensitive, but can be made insensitive by setting
|
||||
* $caseSensitive to false.
|
||||
*
|
||||
* @param string $haystack String being checked
|
||||
* @param string $needle Substring to look for
|
||||
* @param string $encoding The character encoding
|
||||
* @param string $haystack String being checked
|
||||
* @param string $needle Substring to look for
|
||||
* @param bool $caseSensitive Whether or not to enforce case-sensitivity
|
||||
* @param string $encoding The character encoding
|
||||
* @return bool Whether or not $haystack contains $needle
|
||||
*/
|
||||
public static function contains($haystack, $needle, $encoding = null)
|
||||
public static function contains($haystack, $needle, $caseSensitive = true,
|
||||
$encoding = null)
|
||||
{
|
||||
return Stringy::create($haystack, $encoding)->contains($needle);
|
||||
return Stringy::create($haystack, $encoding)->contains($needle, $caseSensitive);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -686,29 +716,52 @@ class StaticStringy
|
||||
|
||||
/**
|
||||
* Returns the number of occurrences of $substring in the given string.
|
||||
* An alias for mb_substr_count()
|
||||
* By default, the comparison is case-sensitive, but can be made insensitive
|
||||
* by setting $caseSensitive to false.
|
||||
*
|
||||
* @param string $str The string to search through
|
||||
* @param string $substring The substring to search for
|
||||
* @param string $encoding The character encoding
|
||||
* @param string $str The string to search through
|
||||
* @param string $substring The substring to search for
|
||||
* @param bool $caseSensitive Whether or not to enforce case-sensitivity
|
||||
* @param string $encoding The character encoding
|
||||
* @return int The number of $substring occurrences
|
||||
*/
|
||||
public static function count($str, $substring, $encoding = null)
|
||||
public static function count($str, $substring, $caseSensitive = true,
|
||||
$encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->count($substring);
|
||||
return Stringy::create($str, $encoding)->count($substring, $caseSensitive);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string with all occurrences of $search replaced with $replace.
|
||||
* Replaces all occurrences of $search in $str by $replacement.
|
||||
*
|
||||
* @param string $str The haystack to search through
|
||||
* @param string $search The needle to search for
|
||||
* @param string $replace The string to replace with
|
||||
* @param string $encoding The character encoding
|
||||
* @param string $str The haystack to search through
|
||||
* @param string $search The needle to search for
|
||||
* @param string $replacement The string to replace with
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The resulting string after the replacements
|
||||
*/
|
||||
public static function replace($str, $search, $replace, $encoding = null)
|
||||
public static function replace($str, $search, $replacement, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->replace($search, $replace)->str;
|
||||
return Stringy::create($str, $encoding)->replace($search, $replacement)->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces all occurrences of $pattern in $str by $replacement. An alias
|
||||
* for mb_ereg_replace(). Note that the 'i' option with multibyte patterns
|
||||
* in mb_ereg_replace() requires PHP 5.4+. This is due to a lack of support
|
||||
* in the bundled version of Oniguruma in PHP 5.3.
|
||||
*
|
||||
* @param string $str The haystack to search through
|
||||
* @param string $pattern The regular expression pattern
|
||||
* @param string $replacement The string to replace with
|
||||
* @param string $options Matching conditions to be used
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The resulting string after the replacements
|
||||
*/
|
||||
public static function regexReplace($str, $pattern, $replacement,
|
||||
$options = 'msr', $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->regexReplace($pattern,
|
||||
$replacement, $options, $encoding)->str;
|
||||
}
|
||||
}
|
||||
|
@@ -284,55 +284,81 @@ class Stringy
|
||||
{
|
||||
$stringy = self::create($this->str, $this->encoding);
|
||||
$charsArray = array(
|
||||
'a' => array('à', 'á', 'â', 'ã', 'ā', 'ą', 'ă', 'å', 'α', 'ά', 'ἀ',
|
||||
'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ', 'ἇ', 'ᾀ', 'ᾁ', 'ᾂ', 'ᾃ',
|
||||
'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ', 'ά', 'ᾰ', 'ᾱ', 'ᾲ', 'ᾳ', 'ᾴ',
|
||||
'ᾶ', 'ᾷ'),
|
||||
'b' => array('б', 'β'),
|
||||
'c' => array('ç', 'ć', 'č', 'ĉ', 'ċ'),
|
||||
'd' => array('ď', 'ð', 'đ', 'ƌ', 'ȡ', 'ɖ', 'ɗ', 'ᵭ', 'ᶁ', 'ᶑ'),
|
||||
'e' => array('è', 'é', 'ê', 'ë', 'ē', 'ę', 'ě', 'ĕ', 'ė', 'ε', 'έ',
|
||||
'ἐ', 'ἑ', 'ἒ', 'ἓ', 'ἔ', 'ἕ', 'ὲ', 'έ', 'е', 'ё', 'э'),
|
||||
'g' => array('ĝ', 'ğ', 'ġ', 'ģ'),
|
||||
'h' => array('ĥ', 'ħ'),
|
||||
'i' => array('ì', 'í', 'î', 'ï', 'ī', 'ĩ', 'ĭ', 'į', 'ı', 'ι', 'ί',
|
||||
'ϊ', 'ΐ', 'ἰ', 'ἱ', 'ἲ', 'ἳ', 'ἴ', 'ἵ', 'ἶ', 'ἷ', 'ὶ',
|
||||
'ί', 'ῐ', 'ῑ', 'ῒ', 'ΐ', 'ῖ', 'ῗ'),
|
||||
'j' => array('ĵ'),
|
||||
'k' => array('ķ', 'ĸ'),
|
||||
'l' => array('ł', 'ľ', 'ĺ', 'ļ', 'ŀ'),
|
||||
'n' => array('ñ', 'ń', 'ň', 'ņ', 'ʼn', 'ŋ', 'ν'),
|
||||
'o' => array('ò', 'ó', 'ô', 'õ', 'ø', 'ō', 'ő', 'ŏ', 'ο', 'ό', 'ὀ',
|
||||
'ὁ', 'ὂ', 'ὃ', 'ὄ', 'ὅ', 'ὸ', 'ό', 'ö'),
|
||||
'r' => array('ŕ', 'ř', 'ŗ'),
|
||||
's' => array('ś', 'š', 'ş'),
|
||||
't' => array('ť', 'ţ'),
|
||||
'u' => array('ü', 'ù', 'ú', 'û', 'ū', 'ů', 'ű', 'ŭ', 'ũ', 'ų', 'µ'),
|
||||
'w' => array('ŵ'),
|
||||
'y' => array('ÿ', 'ý', 'ŷ'),
|
||||
'z' => array('ź', 'ž', 'ż'),
|
||||
'oe' => array('œ'),
|
||||
'A' => array('Á', 'Â', 'Ã', 'Å', 'Ā', 'Ą', 'Ă', 'Α', 'Ά', 'Ἀ', 'Ἁ',
|
||||
'Ἂ', 'Ἃ', 'Ἄ', 'Ἅ', 'Ἆ', 'Ἇ', 'ᾈ', 'ᾉ', 'ᾊ', 'ᾋ', 'ᾌ',
|
||||
'ᾍ', 'ᾎ', 'ᾏ', 'Ᾰ', 'Ᾱ', 'Ὰ', 'Ά', 'ᾼ'),
|
||||
'B' => array('Б'),
|
||||
'C' => array('Ć', 'Č', 'Ĉ', 'Ċ'),
|
||||
'D' => array('Ď', 'Ð', 'Đ', 'Ɖ', 'Ɗ', 'Ƌ', 'ᴅ', 'ᴆ'),
|
||||
'E' => array('É', 'Ê', 'Ë', 'Ē', 'Ę', 'Ě', 'Ĕ', 'Ė', 'Ε', 'Έ', 'Ἐ',
|
||||
'Ἑ', 'Ἒ', 'Ἓ', 'Ἔ', 'Ἕ', 'Έ', 'Ὲ', 'Е', 'Ё', 'Э'),
|
||||
'G' => array('Ğ', 'Ġ', 'Ģ'),
|
||||
'I' => array('Í', 'Î', 'Ï', 'Ī', 'Ĩ', 'Ĭ', 'Į', 'İ', 'Ι', 'Ί', 'Ϊ',
|
||||
'Ἰ', 'Ἱ', 'Ἳ', 'Ἴ', 'Ἵ', 'Ἶ', 'Ἷ', 'Ῐ', 'Ῑ', 'Ὶ', 'Ί'),
|
||||
'L' => array('Ĺ', 'Ł'),
|
||||
'N' => array('Ń', 'Ñ', 'Ň', 'Ņ', 'Ŋ',),
|
||||
'O' => array('Ó', 'Ô', 'Õ', 'Ø', 'Ō', 'Ő', 'Ŏ', 'Ο', 'Ό', 'Ὀ', 'Ὁ',
|
||||
'Ὂ', 'Ὃ', 'Ὄ', 'Ὅ', 'Ὸ', 'Ό'),
|
||||
'R' => array('Ř', 'Ŕ'),
|
||||
'S' => array('Ş', 'Ŝ', 'Ș', 'Š', 'Ś'),
|
||||
'T' => array('Ť', 'Ţ', 'Ŧ', 'Ț'),
|
||||
'U' => array('Ù', 'Ú', 'Û', 'Ū', 'Ů', 'Ű', 'Ŭ', 'Ũ', 'Ų'),
|
||||
'Y' => array('Ý', 'Ÿ', 'Ῠ', 'Ῡ', 'Ὺ', 'Ύ'),
|
||||
'Z' => array('Ź', 'Ž', 'Ż')
|
||||
'a' => array('à', 'á', 'â', 'ã', 'ā', 'ą', 'ă', 'å', 'α', 'ά', 'ἀ',
|
||||
'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ', 'ἇ', 'ᾀ', 'ᾁ', 'ᾂ', 'ᾃ',
|
||||
'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ', 'ά', 'ᾰ', 'ᾱ', 'ᾲ', 'ᾳ', 'ᾴ',
|
||||
'ᾶ', 'ᾷ', 'а'),
|
||||
'b' => array('б', 'β'),
|
||||
'c' => array('ç', 'ć', 'č', 'ĉ', 'ċ'),
|
||||
'd' => array('ď', 'ð', 'đ', 'ƌ', 'ȡ', 'ɖ', 'ɗ', 'ᵭ', 'ᶁ', 'ᶑ', 'д'),
|
||||
'e' => array('è', 'é', 'ê', 'ë', 'ē', 'ę', 'ě', 'ĕ', 'ė', 'ε', 'έ',
|
||||
'ἐ', 'ἑ', 'ἒ', 'ἓ', 'ἔ', 'ἕ', 'ὲ', 'έ', 'е', 'ё', 'э', 'є'),
|
||||
'f' => array('ф'),
|
||||
'g' => array('ĝ', 'ğ', 'ġ', 'ģ', 'г', 'ґ'),
|
||||
'h' => array('ĥ', 'ħ'),
|
||||
'i' => array('ì', 'í', 'î', 'ï', 'ī', 'ĩ', 'ĭ', 'į', 'ı', 'ι', 'ί',
|
||||
'ϊ', 'ΐ', 'ἰ', 'ἱ', 'ἲ', 'ἳ', 'ἴ', 'ἵ', 'ἶ', 'ἷ', 'ὶ',
|
||||
'ί', 'ῐ', 'ῑ', 'ῒ', 'ΐ', 'ῖ', 'ῗ', 'і', 'ї', 'и'),
|
||||
'j' => array('ĵ'),
|
||||
'k' => array('ķ', 'ĸ', 'к'),
|
||||
'l' => array('ł', 'ľ', 'ĺ', 'ļ', 'ŀ', 'л'),
|
||||
'm' => array('м'),
|
||||
'n' => array('ñ', 'ń', 'ň', 'ņ', 'ʼn', 'ŋ', 'ν', 'н'),
|
||||
'o' => array('ò', 'ó', 'ô', 'õ', 'ø', 'ō', 'ő', 'ŏ', 'ο', 'ό', 'ὀ',
|
||||
'ὁ', 'ὂ', 'ὃ', 'ὄ', 'ὅ', 'ὸ', 'ό', 'ö', 'о'),
|
||||
'p' => array('п'),
|
||||
'r' => array('ŕ', 'ř', 'ŗ', 'р'),
|
||||
's' => array('ś', 'š', 'ş', 'с'),
|
||||
't' => array('ť', 'ţ', 'т'),
|
||||
'u' => array('ü', 'ù', 'ú', 'û', 'ū', 'ů', 'ű', 'ŭ', 'ũ', 'ų', 'µ', 'у'),
|
||||
'v' => array('в'),
|
||||
'w' => array('ŵ'),
|
||||
'y' => array('ÿ', 'ý', 'ŷ', 'й', 'ы'),
|
||||
'z' => array('ź', 'ž', 'ż', 'з'),
|
||||
'ch' => array('ч'),
|
||||
'kh' => array('х'),
|
||||
'oe' => array('œ'),
|
||||
'sh' => array('ш'),
|
||||
'shch' => array('щ'),
|
||||
'ts' => array('ц'),
|
||||
'ya' => array('я'),
|
||||
'yu' => array('ю'),
|
||||
'zh' => array('ж'),
|
||||
'A' => array('Á', 'Â', 'Ã', 'Å', 'Ā', 'Ą', 'Ă', 'Α', 'Ά', 'Ἀ', 'Ἁ',
|
||||
'Ἂ', 'Ἃ', 'Ἄ', 'Ἅ', 'Ἆ', 'Ἇ', 'ᾈ', 'ᾉ', 'ᾊ', 'ᾋ', 'ᾌ',
|
||||
'ᾍ', 'ᾎ', 'ᾏ', 'Ᾰ', 'Ᾱ', 'Ὰ', 'Ά', 'ᾼ', 'А'),
|
||||
'B' => array('Б'),
|
||||
'C' => array('Ć', 'Č', 'Ĉ', 'Ċ'),
|
||||
'D' => array('Ď', 'Ð', 'Đ', 'Ɖ', 'Ɗ', 'Ƌ', 'ᴅ', 'ᴆ', 'Д'),
|
||||
'E' => array('É', 'Ê', 'Ë', 'Ē', 'Ę', 'Ě', 'Ĕ', 'Ė', 'Ε', 'Έ', 'Ἐ',
|
||||
'Ἑ', 'Ἒ', 'Ἓ', 'Ἔ', 'Ἕ', 'Έ', 'Ὲ', 'Е', 'Ё', 'Э', 'Є'),
|
||||
'F' => array('Ф'),
|
||||
'G' => array('Ğ', 'Ġ', 'Ģ', 'Г', 'Ґ'),
|
||||
'I' => array('Í', 'Î', 'Ï', 'Ī', 'Ĩ', 'Ĭ', 'Į', 'İ', 'Ι', 'Ί', 'Ϊ',
|
||||
'Ἰ', 'Ἱ', 'Ἳ', 'Ἴ', 'Ἵ', 'Ἶ', 'Ἷ', 'Ῐ', 'Ῑ', 'Ὶ', 'Ί',
|
||||
'И', 'І', 'Ї'),
|
||||
'K' => array('К'),
|
||||
'L' => array('Ĺ', 'Ł', 'Л'),
|
||||
'M' => array('М'),
|
||||
'N' => array('Ń', 'Ñ', 'Ň', 'Ņ', 'Ŋ', 'Н'),
|
||||
'O' => array('Ó', 'Ô', 'Õ', 'Ø', 'Ō', 'Ő', 'Ŏ', 'Ο', 'Ό', 'Ὀ', 'Ὁ',
|
||||
'Ὂ', 'Ὃ', 'Ὄ', 'Ὅ', 'Ὸ', 'Ό', 'О'),
|
||||
'P' => array('П'),
|
||||
'R' => array('Ř', 'Ŕ', 'Р'),
|
||||
'S' => array('Ş', 'Ŝ', 'Ș', 'Š', 'Ś', 'С'),
|
||||
'T' => array('Ť', 'Ţ', 'Ŧ', 'Ț', 'Т'),
|
||||
'U' => array('Ù', 'Ú', 'Û', 'Ū', 'Ů', 'Ű', 'Ŭ', 'Ũ', 'Ų', 'У'),
|
||||
'V' => array('В'),
|
||||
'Y' => array('Ý', 'Ÿ', 'Ῠ', 'Ῡ', 'Ὺ', 'Ύ', 'Ы', 'Й'),
|
||||
'Z' => array('Ź', 'Ž', 'Ż', 'З'),
|
||||
'CH' => array('Ч'),
|
||||
'KH' => array('Х'),
|
||||
'SH' => array('Ш'),
|
||||
'SHCH' => array('Щ'),
|
||||
'TS' => array('Ц'),
|
||||
'YA' => array('Я'),
|
||||
'YU' => array('Ю'),
|
||||
'ZH' => array('Ж')
|
||||
);
|
||||
|
||||
foreach ($charsArray as $key => $value) {
|
||||
@@ -359,7 +385,7 @@ class Stringy
|
||||
public function pad($length, $padStr = ' ', $padType = 'right')
|
||||
{
|
||||
if (!in_array($padType, array('left', 'right', 'both'))) {
|
||||
throw new InvalidArgumentException('Pad expects $padType ' .
|
||||
throw new \InvalidArgumentException('Pad expects $padType ' .
|
||||
"to be one of 'left', 'right' or 'both'");
|
||||
}
|
||||
|
||||
@@ -418,9 +444,9 @@ class Stringy
|
||||
* Returns a new string of a given length such that the end of the string is
|
||||
* padded. Alias for pad() with a $padType of 'right'.
|
||||
*
|
||||
* @param int $length Desired string length after padding
|
||||
* @param string $padStr String used to pad, defaults to space
|
||||
* @return string Object with a right padded $str
|
||||
* @param int $length Desired string length after padding
|
||||
* @param string $padStr String used to pad, defaults to space
|
||||
* @return Stringy Object with a right padded $str
|
||||
*/
|
||||
public function padRight($length, $padStr = ' ')
|
||||
{
|
||||
@@ -522,6 +548,32 @@ class Stringy
|
||||
return $stringy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts all characters in the string to lowercase. An alias for PHP's
|
||||
* mb_strtolower().
|
||||
*
|
||||
* @return Stringy Object with all characters of $str being lowercase
|
||||
*/
|
||||
public function toLowerCase()
|
||||
{
|
||||
$str = mb_strtolower($this->str, $this->encoding);
|
||||
|
||||
return self::create($str, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts all characters in the string to uppercase. An alias for PHP's
|
||||
* mb_strtoupper().
|
||||
*
|
||||
* @return Stringy Object with all characters of $str being uppercase
|
||||
*/
|
||||
public function toUpperCase()
|
||||
{
|
||||
$str = mb_strtoupper($this->str, $this->encoding);
|
||||
|
||||
return self::create($str, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the string into an URL slug. This includes replacing non-ASCII
|
||||
* characters with their closest ASCII equivalents, removing non-alphanumeric
|
||||
@@ -542,17 +594,20 @@ class Stringy
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the string contains $needle, false otherwise.
|
||||
* Returns true if the string contains $needle, false otherwise. By default
|
||||
* the comparison is case-sensitive, but can be made insensitive by setting
|
||||
* $caseSensitive to false.
|
||||
*
|
||||
* @param string $needle Substring to look for
|
||||
* @param string $needle Substring to look for
|
||||
* @param bool $caseSensitive Whether or not to enforce case-sensitivity
|
||||
* @return bool Whether or not $str contains $needle
|
||||
*/
|
||||
public function contains($needle)
|
||||
public function contains($needle, $caseSensitive = true)
|
||||
{
|
||||
if (mb_strpos($this->str, $needle, 0, $this->encoding) !== false)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
if ($caseSensitive)
|
||||
return (mb_strpos($this->str, $needle, 0, $this->encoding) !== false);
|
||||
else
|
||||
return (mb_stripos($this->str, $needle, 0, $this->encoding) !== false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -639,7 +694,7 @@ class Stringy
|
||||
|
||||
// If the last word was truncated
|
||||
if (mb_strpos($stringy->str, ' ', $length - 1, $stringy->encoding) != $length) {
|
||||
// Find pos of the last occurence of a space, and get everything up until
|
||||
// Find pos of the last occurrence of a space, and get everything up until
|
||||
$lastPos = mb_strrpos($truncated, ' ', 0, $stringy->encoding);
|
||||
$truncated = mb_substr($truncated, 0, $lastPos, $stringy->encoding);
|
||||
}
|
||||
@@ -947,7 +1002,7 @@ class Stringy
|
||||
/**
|
||||
* Returns true if $str matches the supplied pattern, false otherwise.
|
||||
*
|
||||
* @param string Regex pattern to match against
|
||||
* @param string $pattern Regex pattern to match against
|
||||
* @return bool Whether or not $str matches the pattern
|
||||
*/
|
||||
private function matchesPattern($pattern)
|
||||
@@ -1049,37 +1104,66 @@ class Stringy
|
||||
|
||||
/**
|
||||
* Returns the number of occurrences of $substring in the given string.
|
||||
* An alias for mb_substr_count()
|
||||
* By default, the comparison is case-sensitive, but can be made insensitive
|
||||
* by setting $caseSensitive to false.
|
||||
*
|
||||
* @param string $substring The substring to search for
|
||||
* @param string $substring The substring to search for
|
||||
* @param bool $caseSensitive Whether or not to enforce case-sensitivity
|
||||
* @return int The number of $substring occurrences
|
||||
*/
|
||||
public function count($substring)
|
||||
public function count($substring, $caseSensitive = true)
|
||||
{
|
||||
if (!$caseSensitive) {
|
||||
$str = mb_strtoupper($this->str, $this->encoding);
|
||||
$substring = mb_strtoupper($substring, $this->encoding);
|
||||
|
||||
return mb_substr_count($str, $substring, $this->encoding);
|
||||
}
|
||||
|
||||
return mb_substr_count($this->str, $substring, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string with all occurrences of $search replaced with $replace.
|
||||
* Replaces all occurrences of $search in $str by $replacement.
|
||||
*
|
||||
* @param string $search The needle to search for
|
||||
* @param string $replace The string to replace with
|
||||
* @param string $search The needle to search for
|
||||
* @param string $replacement The string to replace with
|
||||
* @return Stringy Object with the resulting $str after the replacements
|
||||
*/
|
||||
public function replace($search, $replace)
|
||||
public function replace($search, $replacement)
|
||||
{
|
||||
$stringy = self::create($this->str, $this->encoding);
|
||||
|
||||
$regexEncoding = mb_regex_encoding();
|
||||
mb_regex_encoding($stringy->encoding);
|
||||
mb_regex_encoding($this->encoding);
|
||||
|
||||
// Don't want the args accidentally being parsed as regex
|
||||
$quotedSearch = preg_quote($search);
|
||||
$quotedReplace = preg_quote($replace);
|
||||
// Don't want the args being parsed as regex
|
||||
$search = preg_quote($search);
|
||||
$replacement = preg_quote($replacement);
|
||||
|
||||
$stringy->str = mb_ereg_replace($search, $replace, $stringy->str);
|
||||
$str = mb_ereg_replace($search, $replacement, $this->str);
|
||||
mb_regex_encoding($regexEncoding);
|
||||
|
||||
return $stringy;
|
||||
return self::create($str, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces all occurrences of $pattern in $str by $replacement. An alias
|
||||
* for mb_ereg_replace(). Note that the 'i' option with multibyte patterns
|
||||
* in mb_ereg_replace() requires PHP 5.4+. This is due to a lack of support
|
||||
* in the bundled version of Oniguruma in PHP 5.3.
|
||||
*
|
||||
* @param string $pattern The regular expression pattern
|
||||
* @param string $replacement The string to replace with
|
||||
* @param string $options Matching conditions to be used
|
||||
* @return Stringy Object with the resulting $str after the replacements
|
||||
*/
|
||||
public function regexReplace($pattern, $replacement, $options = 'msr')
|
||||
{
|
||||
$regexEncoding = mb_regex_encoding();
|
||||
mb_regex_encoding($this->encoding);
|
||||
|
||||
$str = mb_ereg_replace($pattern, $replacement, $this->str, $options);
|
||||
mb_regex_encoding($regexEncoding);
|
||||
|
||||
return self::create($str, $this->encoding);
|
||||
}
|
||||
}
|
||||
|
@@ -2,35 +2,31 @@
|
||||
|
||||
abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function stringsForUpperCaseFirst()
|
||||
public function upperCaseFirstProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('Test', 'Test'),
|
||||
array('Test', 'test'),
|
||||
array('1a', '1a'),
|
||||
array('Σ test', 'σ test', 'UTF-8'),
|
||||
array(' σ test', ' σ test', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForLowerCaseFirst()
|
||||
public function lowerCaseFirstProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('test', 'Test'),
|
||||
array('test', 'test'),
|
||||
array('1a', '1a'),
|
||||
array('σ test', 'Σ test', 'UTF-8'),
|
||||
array(' Σ test', ' Σ test', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForCamelize()
|
||||
public function camelizeProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('camelCase', 'CamelCase'),
|
||||
array('camelCase', 'Camel-Case'),
|
||||
array('camelCase', 'camel case'),
|
||||
@@ -45,13 +41,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array('στανιλCase', 'Στανιλ case', 'UTF-8'),
|
||||
array('σamelCase', 'σamel Case', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForUpperCamelize()
|
||||
public function upperCamelizeProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('CamelCase', 'camelCase'),
|
||||
array('CamelCase', 'Camel-Case'),
|
||||
array('CamelCase', 'camel case'),
|
||||
@@ -66,13 +60,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array('ΣτανιλCase', 'στανιλ case', 'UTF-8'),
|
||||
array('ΣamelCase', 'Σamel Case', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForDasherize()
|
||||
public function dasherizeProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('test-case', 'testCase'),
|
||||
array('test-case', 'Test-Case'),
|
||||
array('test-case', 'test case'),
|
||||
@@ -89,13 +81,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array('στανιλ-case', 'Στανιλ case', 'UTF-8'),
|
||||
array('σash-case', 'Σash Case', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForUnderscored()
|
||||
public function underscoredProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('test_case', 'testCase'),
|
||||
array('test_case', 'Test-Case'),
|
||||
array('test_case', 'test case'),
|
||||
@@ -112,63 +102,53 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array('στανιλ_case', 'Στανιλ case', 'UTF-8'),
|
||||
array('σash_case', 'Σash Case', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForSwapCase()
|
||||
public function swapCaseProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('TESTcASE', 'testCase'),
|
||||
array('tEST-cASE', 'Test-Case'),
|
||||
array(' - σASH cASE', ' - Σash Case', 'UTF-8'),
|
||||
array('νΤΑΝΙΛ', 'Ντανιλ', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForTitleize()
|
||||
public function titleizeProvider()
|
||||
{
|
||||
$ignore = array('at', 'by', 'for', 'in', 'of', 'on', 'out', 'to', 'the');
|
||||
|
||||
$testData = array(
|
||||
return array(
|
||||
array('Testing The Method', 'testing the method'),
|
||||
array('Testing the Method', 'testing the method', $ignore, 'UTF-8'),
|
||||
array('I Like to Watch DVDs at Home', 'i like to watch DVDs at home',
|
||||
$ignore, 'UTF-8'),
|
||||
array('Θα Ήθελα Να Φύγει', ' Θα ήθελα να φύγει ', null, 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForHumanize()
|
||||
public function humanizeProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('Author', 'author_id'),
|
||||
array('Test user', ' _test_user_'),
|
||||
array('Συγγραφέας', ' συγγραφέας_id ', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForTidy()
|
||||
public function tidyProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('"I see..."', '“I see…”'),
|
||||
array("'This too'", "‘This too’"),
|
||||
array('test-dash', 'test—dash'),
|
||||
array('Ο συγγραφέας είπε...', 'Ο συγγραφέας είπε…')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForCollapseWhitespace()
|
||||
public function collapseWhitespaceProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('foo bar', ' foo bar '),
|
||||
array('test string', 'test string'),
|
||||
array('Ο συγγραφέας', ' Ο συγγραφέας '),
|
||||
@@ -178,24 +158,23 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array('', ' '),
|
||||
array('', ''),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForToAscii()
|
||||
public function toAsciiProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('foo bar', 'fòô bàř'),
|
||||
array(' TEST ', ' ŤÉŚŢ '),
|
||||
array('φ = z = 3', 'φ = ź = 3')
|
||||
array('φ = z = 3', 'φ = ź = 3'),
|
||||
array('perevirka', 'перевірка'),
|
||||
array('lysaya gora', 'лысая гора'),
|
||||
array('shchuka', 'щука')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForPad()
|
||||
public function padProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
// $length <= $str
|
||||
array('foo bar', 'foo bar', -1),
|
||||
array('foo bar', 'foo bar', 7),
|
||||
@@ -232,47 +211,39 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array('¬øfòô bàř¬ø', 'fòô bàř', 11, '¬øÿ', 'both', 'UTF-8'),
|
||||
array('¬øfòô bàř¬øÿ', 'fòô bàř', 12, '¬øÿ', 'both', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForPadLeft()
|
||||
public function padLeftProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array(' foo bar', 'foo bar', 9),
|
||||
array('_*_foo bar', 'foo bar', 10, '_*'),
|
||||
array('¬ø¬øfòô bàř', 'fòô bàř', 11, '¬ø', 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForPadRight()
|
||||
public function padRightProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('foo bar ', 'foo bar', 9),
|
||||
array('foo bar_*_', 'foo bar', 10, '_*'),
|
||||
array('fòô bàř¬ø¬ø', 'fòô bàř', 11, '¬ø', 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForPadBoth()
|
||||
public function padBothProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('foo bar ', 'foo bar', 8),
|
||||
array(' foo bar ', 'foo bar', 9, ' '),
|
||||
array('¬fòô bàř¬ø', 'fòô bàř', 10, '¬øÿ', 'UTF-8'),
|
||||
array('¬øfòô bàř¬øÿ', 'fòô bàř', 12, '¬øÿ', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForStartsWith()
|
||||
public function startsWithProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array(true, 'foo bars', 'foo bar'),
|
||||
array(true, 'FOO bars', 'foo bar', false),
|
||||
array(true, 'FOO bars', 'foo BAR', false),
|
||||
@@ -285,13 +256,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array(false, 'FÒÔ bàřs', 'fòô bàř', true, 'UTF-8'),
|
||||
array(false, 'fòô bàřs', 'fòô BÀŘ', true, 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForEndsWith()
|
||||
public function endsWithProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array(true, 'foo bars', 'o bars'),
|
||||
array(true, 'FOO bars', 'o bars', false),
|
||||
array(true, 'FOO bars', 'o BARs', false),
|
||||
@@ -304,13 +273,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array(false, 'FÒÔ bàřs', 'fòô bàřs', true, 'UTF-8'),
|
||||
array(false, 'fòô bàřs', 'fòô BÀŘS', true, 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForToSpaces()
|
||||
public function toSpacesProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array(' foo bar ', ' foo bar '),
|
||||
array(' foo bar ', ' foo bar ', 5),
|
||||
array(' foo bar ', ' foo bar ', 2),
|
||||
@@ -318,72 +285,96 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array(" foo\n bar", " foo\n bar"),
|
||||
array(" fòô\n bàř", " fòô\n bàř")
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForToTabs()
|
||||
public function toTabsProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array(' foo bar ', ' foo bar '),
|
||||
array(' foo bar ', ' foo bar ', 5),
|
||||
array(' foo bar ', ' foo bar ', 2),
|
||||
array(" foo\n bar", " foo\n bar"),
|
||||
array(" fòô\n bàř", " fòô\n bàř")
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForSlugify()
|
||||
public function toLowerCaseProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('foo bar', 'FOO BAR'),
|
||||
array(' foo_bar ', ' FOO_bar '),
|
||||
array('fòô bàř', 'FÒÔ BÀŘ', 'UTF-8'),
|
||||
array(' fòô_bàř ', ' FÒÔ_bàř ', 'UTF-8'),
|
||||
array('αυτοκίνητο', 'ΑΥΤΟΚΊΝΗΤΟ', 'UTF-8'),
|
||||
);
|
||||
}
|
||||
|
||||
public function toUpperCaseProvider()
|
||||
{
|
||||
return array(
|
||||
array('FOO BAR', 'foo bar'),
|
||||
array(' FOO_BAR ', ' FOO_bar '),
|
||||
array('FÒÔ BÀŘ', 'fòô bàř', 'UTF-8'),
|
||||
array(' FÒÔ_BÀŘ ', ' FÒÔ_bàř ', 'UTF-8'),
|
||||
array('ΑΥΤΟΚΊΝΗΤΟ', 'αυτοκίνητο', 'UTF-8'),
|
||||
);
|
||||
}
|
||||
|
||||
public function slugifyProvider()
|
||||
{
|
||||
return array(
|
||||
array('foo-bar', ' foo bar '),
|
||||
array('foo-dbar', " Foo d'Bar "),
|
||||
array('a-string-with-dashes', 'A string-with-dashes'),
|
||||
array('using-strings-like-foo-bar', 'Using strings like fòô bàř'),
|
||||
array('unrecognized-chars-like', 'unrecognized chars like συγγρ'),
|
||||
array('numbers-1234', 'numbers 1234')
|
||||
array('numbers-1234', 'numbers 1234'),
|
||||
array('perevirka-ryadka', 'перевірка рядка'),
|
||||
array('bukvar-s-bukvoy-y', 'букварь с буквой ы')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForContains()
|
||||
public function containsProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array(true, 'This string contains foo bar', 'foo bar'),
|
||||
array(true, '12398!@(*%!@# @!%#*&^%', ' @!%#*&^%'),
|
||||
array(true, 'Ο συγγραφέας είπε', 'συγγραφέας', 'UTF-8'),
|
||||
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'å´¥©', 'UTF-8'),
|
||||
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'å˚ ∆', 'UTF-8'),
|
||||
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'øœ¬', 'UTF-8'),
|
||||
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'å´¥©', true, 'UTF-8'),
|
||||
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'å˚ ∆', true, 'UTF-8'),
|
||||
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'øœ¬', true, 'UTF-8'),
|
||||
array(false, 'This string contains foo bar', 'Foo bar'),
|
||||
array(false, 'This string contains foo bar', 'foobar'),
|
||||
array(false, 'This string contains foo bar', 'foo bar '),
|
||||
array(false, 'Ο συγγραφέας είπε', ' συγγραφέας ', 'UTF-8'),
|
||||
array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', ' ßå˚', 'UTF-8')
|
||||
array(false, 'Ο συγγραφέας είπε', ' συγγραφέας ', true, 'UTF-8'),
|
||||
array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', ' ßå˚', true, 'UTF-8'),
|
||||
array(true, 'This string contains foo bar', 'Foo bar', false),
|
||||
array(true, '12398!@(*%!@# @!%#*&^%', ' @!%#*&^%', false),
|
||||
array(true, 'Ο συγγραφέας είπε', 'ΣΥΓΓΡΑΦΈΑΣ', false, 'UTF-8'),
|
||||
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'Å´¥©', false, 'UTF-8'),
|
||||
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'Å˚ ∆', false, 'UTF-8'),
|
||||
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'ØŒ¬', false, 'UTF-8'),
|
||||
array(false, 'This string contains foo bar', 'foobar', false),
|
||||
array(false, 'This string contains foo bar', 'foo bar ', false),
|
||||
array(false, 'Ο συγγραφέας είπε', ' συγγραφέας ', false, 'UTF-8'),
|
||||
array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', ' ßÅ˚', false, 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForSurround()
|
||||
public function surroundProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('__foobar__', 'foobar', '__'),
|
||||
array('test', 'test', ''),
|
||||
array('**', '', '*'),
|
||||
array('¬fòô bàř¬', 'fòô bàř', '¬'),
|
||||
array('ßå∆˚ test ßå∆˚', ' test ', 'ßå∆˚')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForInsert()
|
||||
public function insertProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('foo bar', 'oo bar', 'f', 0),
|
||||
array('foo bar', 'f bar', 'oo', 1),
|
||||
array('f bar', 'f bar', 'oo', 20),
|
||||
@@ -392,13 +383,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array('fòô bàř', 'f bàř', 'òô', 1, 'UTF-8'),
|
||||
array('fòô bàř', 'fòô bà', 'ř', 6, 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForTruncate()
|
||||
public function truncateProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('Test foo bar', 'Test foo bar', 12),
|
||||
array('Test foo ba', 'Test foo bar', 11),
|
||||
array('Test foo', 'Test foo bar', 8),
|
||||
@@ -422,13 +411,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array('Teϰϰ', 'Test fòô bàř', 4, 'ϰϰ', 'UTF-8'),
|
||||
array('What are your pl...', 'What are your plans today?', 19, '...')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForSafeTruncate()
|
||||
public function safeTruncateProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('Test foo bar', 'Test foo bar', 12),
|
||||
array('Test foo', 'Test foo bar', 11),
|
||||
array('Test foo', 'Test foo bar', 8),
|
||||
@@ -452,37 +439,31 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array('ϰϰ', 'Test fòô bàř', 4, 'ϰϰ', 'UTF-8'),
|
||||
array('What are your plans...', 'What are your plans today?', 22, '...')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForReverse()
|
||||
public function reverseProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('', ''),
|
||||
array('raboof', 'foobar'),
|
||||
array('řàbôòf', 'fòôbàř', 'UTF-8'),
|
||||
array('řàb ôòf', 'fòô bàř', 'UTF-8'),
|
||||
array('∂∆ ˚åß', 'ßå˚ ∆∂', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForShuffle()
|
||||
public function shuffleProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('foo bar'),
|
||||
array('∂∆ ˚åß', 'UTF-8'),
|
||||
array('å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForTrim()
|
||||
public function trimProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('foo bar', ' foo bar '),
|
||||
array('foo bar', ' foo bar'),
|
||||
array('foo bar', 'foo bar '),
|
||||
@@ -492,13 +473,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array('fòô bàř', 'fòô bàř '),
|
||||
array('fòô bàř', "\n\t fòô bàř \n\t")
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForLongestCommonPrefix()
|
||||
public function longestCommonPrefixProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('foo', 'foobar', 'foo bar'),
|
||||
array('foo bar', 'foo bar', 'foo bar'),
|
||||
array('f', 'foo bar', 'far boo'),
|
||||
@@ -510,13 +489,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array('', 'toy car', 'fòô bar', 'UTF-8'),
|
||||
array('', 'fòô bar', '', 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForLongestCommonSuffix()
|
||||
public function longestCommonSuffixProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('bar', 'foobar', 'foo bar'),
|
||||
array('foo bar', 'foo bar', 'foo bar'),
|
||||
array('ar', 'foo bar', 'boo far'),
|
||||
@@ -528,13 +505,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array('', 'toy car', 'fòô bàř', 'UTF-8'),
|
||||
array('', 'fòô bàř', '', 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForLongestCommonSubstring()
|
||||
public function longestCommonSubstringProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('foo', 'foobar', 'foo bar'),
|
||||
array('foo bar', 'foo bar', 'foo bar'),
|
||||
array('oo ', 'foo bar', 'boo far'),
|
||||
@@ -546,25 +521,21 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array(' ', 'toy car', 'fòô bàř', 'UTF-8'),
|
||||
array('', 'fòô bàř', '', 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForLength()
|
||||
public function lengthProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array(11, ' foo bar '),
|
||||
array(1, 'f'),
|
||||
array(0, ''),
|
||||
array(7, 'fòô bàř', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForSubstr()
|
||||
public function substrProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('foo bar', 'foo bar', 0),
|
||||
array('bar', 'foo bar', 4),
|
||||
array('bar', 'foo bar', 4, null),
|
||||
@@ -575,13 +546,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array('ô b', 'fòô bàř', 2, 3, 'UTF-8'),
|
||||
array('', 'fòô bàř', 4, 0, 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForAt()
|
||||
public function atProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('f', 'foo bar', 0),
|
||||
array('o', 'foo bar', 1),
|
||||
array('r', 'foo bar', 6),
|
||||
@@ -591,13 +560,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array('ř', 'fòô bàř', 6, 'UTF-8'),
|
||||
array('', 'fòô bàř', 7, 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForFirst()
|
||||
public function firstProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('', 'foo bar', -5),
|
||||
array('', 'foo bar', 0),
|
||||
array('f', 'foo bar', 1),
|
||||
@@ -611,13 +578,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array('fòô bàř', 'fòô bàř', 7, 'UTF-8'),
|
||||
array('fòô bàř', 'fòô bàř', 8, 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForLast()
|
||||
public function lastProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('', 'foo bar', -5),
|
||||
array('', 'foo bar', 0),
|
||||
array('r', 'foo bar', 1),
|
||||
@@ -631,13 +596,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array('fòô bàř', 'fòô bàř', 7, 'UTF-8'),
|
||||
array('fòô bàř', 'fòô bàř', 8, 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForEnsureLeft()
|
||||
public function ensureLeftProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('foobar', 'foobar', 'f'),
|
||||
array('foobar', 'foobar', 'foo'),
|
||||
array('foo/foobar', 'foobar', 'foo/'),
|
||||
@@ -649,13 +612,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array('http://fòôbàř', 'fòôbàř', 'http://', 'UTF-8'),
|
||||
array('http://fòôbàř', 'http://fòôbàř', 'http://', 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForEnsureRight()
|
||||
public function ensureRightProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('foobar', 'foobar', 'r'),
|
||||
array('foobar', 'foobar', 'bar'),
|
||||
array('foobar/bar', 'foobar', '/bar'),
|
||||
@@ -667,13 +628,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array('fòôbàř.com/', 'fòôbàř', '.com/', 'UTF-8'),
|
||||
array('fòôbàř.com/', 'fòôbàř.com/', '.com/', 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForRemoveLeft()
|
||||
public function removeLeftProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('foo bar', 'foo bar', ''),
|
||||
array('oo bar', 'foo bar', 'f'),
|
||||
array('bar', 'foo bar', 'foo '),
|
||||
@@ -685,13 +644,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array('fòô bàř', 'fòô bàř', 'òô', 'UTF-8'),
|
||||
array('fòô bàř', 'fòô bàř', 'òô bàř', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForRemoveRight()
|
||||
public function removeRightProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('foo bar', 'foo bar', ''),
|
||||
array('foo ba', 'foo bar', 'r'),
|
||||
array('foo', 'foo bar', ' bar'),
|
||||
@@ -703,13 +660,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array('fòô bàř', 'fòô bàř', 'bà', 'UTF-8'),
|
||||
array('fòô bàř', 'fòô bàř', 'fòô bà', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForIsAlpha()
|
||||
public function isAlphaProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array(true, ''),
|
||||
array(true, 'foobar'),
|
||||
array(false, 'foo bar'),
|
||||
@@ -721,13 +676,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array(false, 'ҠѨњ¨ˆфгШ', 'UTF-8'),
|
||||
array(true, '丹尼爾', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForIsAlphanumeric()
|
||||
public function isAlphanumericProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array(true, ''),
|
||||
array(true, 'foobar1'),
|
||||
array(false, 'foo bar'),
|
||||
@@ -742,13 +695,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array(true, 'دانيال1', 'UTF-8'),
|
||||
array(false, 'دانيال1 ', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForIsBlank()
|
||||
public function isBlankProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array(true, ''),
|
||||
array(true, ' '),
|
||||
array(true, "\n\t "),
|
||||
@@ -762,13 +713,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array(false, ' z', 'UTF-8'),
|
||||
array(false, ' 1', 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForIsJson()
|
||||
public function isJsonProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array(false, ''),
|
||||
array(false, '123'),
|
||||
array(true, '{"foo": "bar"}'),
|
||||
@@ -784,13 +733,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array(true, '["fòô"]', 'UTF-8'),
|
||||
array(false, '{"fòô": "bàř"]', 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForIsLowerCase()
|
||||
public function isLowerCaseProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array(true, ''),
|
||||
array(true, 'foobar'),
|
||||
array(false, 'foo bar'),
|
||||
@@ -800,13 +747,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array(false, 'fòô bàř', 'UTF-8'),
|
||||
array(false, 'fòôbÀŘ', 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForIsSerialized()
|
||||
public function isSerializedProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array(false, ''),
|
||||
array(true, 'a:1:{s:3:"foo";s:3:"bar";}'),
|
||||
array(false, 'a:1:{s:3:"foo";s:3:"bar"}'),
|
||||
@@ -815,13 +760,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array(false, 'a:1:{s:5:"fòô";s:5:"bàř"}', 'UTF-8'),
|
||||
array(true, serialize(array('fòô' => 'bár')), 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForIsUpperCase()
|
||||
public function isUpperCaseProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array(true, ''),
|
||||
array(true, 'FOOBAR'),
|
||||
array(false, 'FOO BAR'),
|
||||
@@ -831,13 +774,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array(false, 'FÒÔ BÀŘ', 'UTF-8'),
|
||||
array(false, 'FÒÔBàř', 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForIsHexadecimal()
|
||||
public function isHexadecimalProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array(true, ''),
|
||||
array(true, 'abcdef'),
|
||||
array(true, 'ABCDEF'),
|
||||
@@ -852,13 +793,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array(false, '0123456789x', 'UTF-8'),
|
||||
array(false, 'ABCDEFx', 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForCount()
|
||||
public function countProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array(0, '', 'foo'),
|
||||
array(0, 'foo', 'bar'),
|
||||
array(1, 'foo bar', 'foo'),
|
||||
@@ -866,29 +805,47 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array(0, '', 'fòô', 'UTF-8'),
|
||||
array(0, 'fòô', 'bàř', 'UTF-8'),
|
||||
array(1, 'fòô bàř', 'fòô', 'UTF-8'),
|
||||
array(2, 'fôòô bàř', 'ô', 'UTF-8')
|
||||
array(2, 'fôòô bàř', 'ô', 'UTF-8'),
|
||||
array(0, 'fÔÒÔ bàř', 'ô', 'UTF-8'),
|
||||
array(0, 'foo', 'BAR', false),
|
||||
array(1, 'foo bar', 'FOo', false),
|
||||
array(2, 'foo bar', 'O', false),
|
||||
array(1, 'fòô bàř', 'fÒÔ', false, 'UTF-8'),
|
||||
array(2, 'fôòô bàř', 'Ô', false, 'UTF-8'),
|
||||
array(2, 'συγγραφέας', 'Σ', false, 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForReplace()
|
||||
public function replaceProvider()
|
||||
{
|
||||
$testData = array(
|
||||
return array(
|
||||
array('', '', '', ''),
|
||||
array('foo', '', '', 'foo'),
|
||||
array('foo', '\s', '\s', 'foo'),
|
||||
array('foo bar', 'foo bar', '', ''),
|
||||
array('bar', 'foo bar', 'foo ', ''),
|
||||
array('far bar', 'foo bar', 'foo', 'far'),
|
||||
array('bar bar', 'foo bar foo bar', 'foo ', ''),
|
||||
array('', '', '', '', 'UTF-8'),
|
||||
array('fòô', '', '', 'fòô', 'UTF-8'),
|
||||
array('fòô', '\s', '\s', 'fòô', 'UTF-8'),
|
||||
array('fòô bàř', 'fòô bàř', '', '', 'UTF-8'),
|
||||
array('bàř', 'fòô bàř', 'fòô ', '', 'UTF-8'),
|
||||
array('far bàř', 'fòô bàř', 'fòô', 'far', 'UTF-8'),
|
||||
array('bàř bàř', 'fòô bàř fòô bàř', 'fòô ', '', 'UTF-8'),
|
||||
);
|
||||
}
|
||||
|
||||
return $testData;
|
||||
public function regexReplaceProvider()
|
||||
{
|
||||
return array(
|
||||
array('', '', '', ''),
|
||||
array('bar', 'foo', 'f[o]+', 'bar'),
|
||||
array('bar', 'foo bar', 'f[O]+\s', '', 'i'),
|
||||
array('foo', 'bar', '[[:alpha:]]{3}', 'foo'),
|
||||
array('', '', '', '', 'msr', 'UTF-8'),
|
||||
array('bàř', 'fòô ', 'f[òô]+\s', 'bàř', 'msr', 'UTF-8'),
|
||||
array('fòô', 'bàř', '[[:alpha:]]{3}', 'fòô', 'msr', 'UTF-8')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@ use Stringy\StaticStringy as S;
|
||||
class StaticStringyTestCase extends CommonTest
|
||||
{
|
||||
/**
|
||||
* @dataProvider stringsForUpperCaseFirst
|
||||
* @dataProvider upperCaseFirstProvider()
|
||||
*/
|
||||
public function testUpperCaseFirst($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -18,7 +18,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForLowerCaseFirst
|
||||
* @dataProvider lowerCaseFirstProvider()
|
||||
*/
|
||||
public function testLowerCaseFirst($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -28,7 +28,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForCamelize
|
||||
* @dataProvider camelizeProvider()
|
||||
*/
|
||||
public function testCamelize($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -38,7 +38,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForUpperCamelize
|
||||
* @dataProvider upperCamelizeProvider()
|
||||
*/
|
||||
public function testUpperCamelize($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -48,7 +48,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForDasherize
|
||||
* @dataProvider dasherizeProvider()
|
||||
*/
|
||||
public function testDasherize($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -58,7 +58,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForUnderscored
|
||||
* @dataProvider underscoredProvider()
|
||||
*/
|
||||
public function testUnderscored($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -68,7 +68,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForSwapCase
|
||||
* @dataProvider swapCaseProvider()
|
||||
*/
|
||||
public function testSwapCase($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -78,7 +78,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForTitleize
|
||||
* @dataProvider titleizeProvider()
|
||||
*/
|
||||
public function testTitleize($expected, $str, $ignore = null,
|
||||
$encoding = null)
|
||||
@@ -89,7 +89,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForHumanize
|
||||
* @dataProvider humanizeProvider()
|
||||
*/
|
||||
public function testHumanize($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -99,7 +99,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForTidy
|
||||
* @dataProvider tidyProvider()
|
||||
*/
|
||||
public function testTidy($expected, $str)
|
||||
{
|
||||
@@ -109,7 +109,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForCollapseWhitespace
|
||||
* @dataProvider collapseWhitespaceProvider()
|
||||
*/
|
||||
public function testCollapseWhitespace($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -119,7 +119,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForToAscii
|
||||
* @dataProvider toAsciiProvider()
|
||||
*/
|
||||
public function testToAscii($expected, $str)
|
||||
{
|
||||
@@ -129,7 +129,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForPad
|
||||
* @dataProvider padProvider()
|
||||
*/
|
||||
public function testPad($expected, $str, $length, $padStr = ' ',
|
||||
$padType = 'right', $encoding = null)
|
||||
@@ -140,7 +140,15 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForPadLeft
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testPadException()
|
||||
{
|
||||
$result = S::pad('string', 5, 'foo', 'bar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider padLeftProvider()
|
||||
*/
|
||||
public function testPadLeft($expected, $str, $length, $padStr = ' ',
|
||||
$encoding = null)
|
||||
@@ -151,7 +159,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForPadRight
|
||||
* @dataProvider padRightProvider()
|
||||
*/
|
||||
public function testPadRight($expected, $str, $length, $padStr = ' ',
|
||||
$encoding = null)
|
||||
@@ -162,7 +170,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForPadBoth
|
||||
* @dataProvider padBothProvider()
|
||||
*/
|
||||
public function testPadBoth($expected, $str, $length, $padStr = ' ',
|
||||
$encoding = null)
|
||||
@@ -173,10 +181,10 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForStartsWith
|
||||
* @dataProvider startsWithProvider()
|
||||
*/
|
||||
public function testStartsWith($expected, $str, $substring,
|
||||
$caseSensitive = true, $encoding = null)
|
||||
$caseSensitive = true, $encoding = null)
|
||||
{
|
||||
$result = S::startsWith($str, $substring, $caseSensitive, $encoding);
|
||||
$this->assertInternalType('boolean', $result);
|
||||
@@ -184,10 +192,10 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForEndsWith
|
||||
* @dataProvider endsWithProvider()
|
||||
*/
|
||||
public function testEndsWith($expected, $str, $substring,
|
||||
$caseSensitive = true, $encoding = null)
|
||||
$caseSensitive = true, $encoding = null)
|
||||
{
|
||||
$result = S::endsWith($str, $substring, $caseSensitive, $encoding);
|
||||
$this->assertInternalType('boolean', $result);
|
||||
@@ -195,7 +203,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForToSpaces
|
||||
* @dataProvider toSpacesProvider()
|
||||
*/
|
||||
public function testToSpaces($expected, $str, $tabLength = 4)
|
||||
{
|
||||
@@ -205,7 +213,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForToTabs
|
||||
* @dataProvider toTabsProvider()
|
||||
*/
|
||||
public function testToTabs($expected, $str, $tabLength = 4)
|
||||
{
|
||||
@@ -215,7 +223,27 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForSlugify
|
||||
* @dataProvider toLowerCaseProvider()
|
||||
*/
|
||||
public function testToLowerCase($expected, $str, $encoding = null)
|
||||
{
|
||||
$result = S::toLowerCase($str, $encoding);
|
||||
$this->assertInternalType('string', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider toUpperCaseProvider()
|
||||
*/
|
||||
public function testToUpperCase($expected, $str, $encoding = null)
|
||||
{
|
||||
$result = S::toUpperCase($str, $encoding);
|
||||
$this->assertInternalType('string', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider slugifyProvider()
|
||||
*/
|
||||
public function testSlugify($expected, $str)
|
||||
{
|
||||
@@ -225,17 +253,18 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForContains
|
||||
* @dataProvider containsProvider()
|
||||
*/
|
||||
public function testContains($expected, $haystack, $needle, $encoding = null)
|
||||
public function testContains($expected, $haystack, $needle,
|
||||
$caseSensitive = true, $encoding = null)
|
||||
{
|
||||
$result = S::contains($haystack, $needle, $encoding);
|
||||
$result = S::contains($haystack, $needle, $caseSensitive, $encoding);
|
||||
$this->assertInternalType('boolean', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForSurround
|
||||
* @dataProvider surroundProvider()
|
||||
*/
|
||||
public function testSurround($expected, $str, $substring)
|
||||
{
|
||||
@@ -245,7 +274,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForInsert
|
||||
* @dataProvider insertProvider()
|
||||
*/
|
||||
public function testInsert($expected, $str, $substring, $index,
|
||||
$encoding = null)
|
||||
@@ -256,7 +285,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForTruncate
|
||||
* @dataProvider truncateProvider()
|
||||
*/
|
||||
public function testTruncate($expected, $str, $length, $substring = '',
|
||||
$encoding = null)
|
||||
@@ -267,7 +296,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForSafeTruncate
|
||||
* @dataProvider safeTruncateProvider()
|
||||
*/
|
||||
public function testSafeTruncate($expected, $str, $length, $substring = '',
|
||||
$encoding = null)
|
||||
@@ -278,7 +307,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForReverse
|
||||
* @dataProvider reverseProvider()
|
||||
*/
|
||||
public function testReverse($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -288,7 +317,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForShuffle
|
||||
* @dataProvider shuffleProvider()
|
||||
*/
|
||||
public function testShuffle($str, $encoding = null)
|
||||
{
|
||||
@@ -309,7 +338,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForTrim
|
||||
* @dataProvider trimProvider()
|
||||
*/
|
||||
public function testTrim($expected, $str)
|
||||
{
|
||||
@@ -319,7 +348,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForLongestCommonPrefix
|
||||
* @dataProvider longestCommonPrefixProvider()
|
||||
*/
|
||||
public function testLongestCommonPrefix($expected, $str, $otherStr,
|
||||
$encoding = null)
|
||||
@@ -330,7 +359,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForLongestCommonSuffix
|
||||
* @dataProvider longestCommonSuffixProvider()
|
||||
*/
|
||||
public function testLongestCommonSuffix($expected, $str, $otherStr,
|
||||
$encoding = null)
|
||||
@@ -341,7 +370,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForLongestCommonSubstring
|
||||
* @dataProvider longestCommonSubstringProvider()
|
||||
*/
|
||||
public function testLongestCommonSubstring($expected, $str, $otherStr,
|
||||
$encoding = null)
|
||||
@@ -352,7 +381,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForLength
|
||||
* @dataProvider lengthProvider()
|
||||
*/
|
||||
public function testLength($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -362,7 +391,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForSubstr
|
||||
* @dataProvider substrProvider()
|
||||
*/
|
||||
public function testSubstr($expected, $str, $start, $length = null,
|
||||
$encoding = null)
|
||||
@@ -373,7 +402,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForAt
|
||||
* @dataProvider atProvider()
|
||||
*/
|
||||
public function testAt($expected, $str, $index, $encoding = null)
|
||||
{
|
||||
@@ -383,7 +412,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForFirst
|
||||
* @dataProvider firstProvider()
|
||||
*/
|
||||
public function testFirst($expected, $str, $n, $encoding = null)
|
||||
{
|
||||
@@ -393,7 +422,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForLast
|
||||
* @dataProvider lastProvider()
|
||||
*/
|
||||
public function testLast($expected, $str, $n, $encoding = null)
|
||||
{
|
||||
@@ -403,7 +432,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForEnsureLeft
|
||||
* @dataProvider ensureLeftProvider()
|
||||
*/
|
||||
public function testEnsureLeft($expected, $str, $substring, $encoding = null)
|
||||
{
|
||||
@@ -413,7 +442,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForEnsureRight
|
||||
* @dataProvider ensureRightProvider()
|
||||
*/
|
||||
public function testEnsureRight($expected, $str, $substring, $encoding = null)
|
||||
{
|
||||
@@ -423,7 +452,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForRemoveLeft
|
||||
* @dataProvider removeLeftProvider()
|
||||
*/
|
||||
public function testRemoveLeft($expected, $str, $substring, $encoding = null)
|
||||
{
|
||||
@@ -433,7 +462,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForRemoveRight
|
||||
* @dataProvider removeRightProvider()
|
||||
*/
|
||||
public function testRemoveRight($expected, $str, $substring, $encoding = null)
|
||||
{
|
||||
@@ -443,7 +472,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsAlpha
|
||||
* @dataProvider isAlphaProvider()
|
||||
*/
|
||||
public function testIsAlpha($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -453,7 +482,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsAlphanumeric
|
||||
* @dataProvider isAlphanumericProvider()
|
||||
*/
|
||||
public function testIsAlphanumeric($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -463,7 +492,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsBlank
|
||||
* @dataProvider isBlankProvider()
|
||||
*/
|
||||
public function testIsBlank($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -471,9 +500,9 @@ class StaticStringyTestCase extends CommonTest
|
||||
$this->assertInternalType('boolean', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsJson
|
||||
* @dataProvider isJsonProvider()
|
||||
*/
|
||||
public function testIsJson($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -483,7 +512,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsLowerCase
|
||||
* @dataProvider isLowerCaseProvider()
|
||||
*/
|
||||
public function testIsLowerCase($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -493,7 +522,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsSerialized
|
||||
* @dataProvider isSerializedProvider()
|
||||
*/
|
||||
public function testIsSerialized($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -503,7 +532,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsUpperCase
|
||||
* @dataProvider isUpperCaseProvider()
|
||||
*/
|
||||
public function testIsUpperCase($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -513,7 +542,7 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsHexadecimal
|
||||
* @dataProvider isHexadecimalProvider()
|
||||
*/
|
||||
public function testIsHexadecimal($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -523,22 +552,34 @@ class StaticStringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForCount
|
||||
* @dataProvider countProvider()
|
||||
*/
|
||||
public function testCount($expected, $str, $substring, $encoding = null)
|
||||
public function testCount($expected, $str, $substring, $caseSensitive = true,
|
||||
$encoding = null)
|
||||
{
|
||||
$result = S::count($str, $substring, $encoding);
|
||||
$result = S::count($str, $substring, $caseSensitive, $encoding);
|
||||
$this->assertInternalType('int', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForReplace
|
||||
* @dataProvider replaceProvider()
|
||||
*/
|
||||
public function testReplace($expected, $str, $search, $replace,
|
||||
public function testReplace($expected, $str, $search, $replacement,
|
||||
$encoding = null)
|
||||
{
|
||||
$result = S::replace($str, $search, $replace, $encoding);
|
||||
$result = S::replace($str, $search, $replacement, $encoding);
|
||||
$this->assertInternalType('string', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider regexReplaceProvider()
|
||||
*/
|
||||
public function testRegexReplace($expected, $str, $pattern, $replacement,
|
||||
$options = 'msr', $encoding = null)
|
||||
{
|
||||
$result = S::regexReplace($str, $pattern, $replacement, $options, $encoding);
|
||||
$this->assertInternalType('string', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForUpperCaseFirst
|
||||
* @dataProvider upperCaseFirstProvider()
|
||||
*/
|
||||
public function testUpperCaseFirst($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -42,7 +42,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForLowerCaseFirst
|
||||
* @dataProvider lowerCaseFirstProvider()
|
||||
*/
|
||||
public function testLowerCaseFirst($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -54,7 +54,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForCamelize
|
||||
* @dataProvider camelizeProvider()
|
||||
*/
|
||||
public function testCamelize($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -66,7 +66,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForUpperCamelize
|
||||
* @dataProvider upperCamelizeProvider()
|
||||
*/
|
||||
public function testUpperCamelize($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -78,7 +78,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForDasherize
|
||||
* @dataProvider dasherizeProvider()
|
||||
*/
|
||||
public function testDasherize($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -90,7 +90,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForUnderscored
|
||||
* @dataProvider underscoredProvider()
|
||||
*/
|
||||
public function testUnderscored($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -102,7 +102,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForSwapCase
|
||||
* @dataProvider swapCaseProvider()
|
||||
*/
|
||||
public function testSwapCase($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -114,7 +114,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForTitleize
|
||||
* @dataProvider titleizeProvider()
|
||||
*/
|
||||
public function testTitleize($expected, $str, $ignore = null,
|
||||
$encoding = null)
|
||||
@@ -127,7 +127,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForHumanize
|
||||
* @dataProvider humanizeProvider()
|
||||
*/
|
||||
public function testHumanize($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -139,7 +139,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForTidy
|
||||
* @dataProvider tidyProvider()
|
||||
*/
|
||||
public function testTidy($expected, $str)
|
||||
{
|
||||
@@ -151,7 +151,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForCollapseWhitespace
|
||||
* @dataProvider collapseWhitespaceProvider()
|
||||
*/
|
||||
public function testCollapseWhitespace($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -163,7 +163,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForToAscii
|
||||
* @dataProvider toAsciiProvider()
|
||||
*/
|
||||
public function testToAscii($expected, $str)
|
||||
{
|
||||
@@ -175,7 +175,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForPad
|
||||
* @dataProvider padProvider()
|
||||
*/
|
||||
public function testPad($expected, $str, $length, $padStr = ' ',
|
||||
$padType = 'right', $encoding = null)
|
||||
@@ -188,7 +188,16 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForPadLeft
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testPadException()
|
||||
{
|
||||
$stringy = S::create('foo');
|
||||
$result = $stringy->pad(5, 'foo', 'bar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider padLeftProvider()
|
||||
*/
|
||||
public function testPadLeft($expected, $str, $length, $padStr = ' ',
|
||||
$encoding = null)
|
||||
@@ -201,7 +210,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForPadRight
|
||||
* @dataProvider padRightProvider()
|
||||
*/
|
||||
public function testPadRight($expected, $str, $length, $padStr = ' ',
|
||||
$encoding = null)
|
||||
@@ -214,7 +223,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForPadBoth
|
||||
* @dataProvider padBothProvider()
|
||||
*/
|
||||
public function testPadBoth($expected, $str, $length, $padStr = ' ',
|
||||
$encoding = null)
|
||||
@@ -227,10 +236,10 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForStartsWith
|
||||
* @dataProvider startsWithProvider()
|
||||
*/
|
||||
public function testStartsWith($expected, $str, $substring,
|
||||
$caseSensitive = true, $encoding = null)
|
||||
$caseSensitive = true, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->startsWith($substring, $caseSensitive);
|
||||
@@ -240,10 +249,10 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForEndsWith
|
||||
* @dataProvider endsWithProvider()
|
||||
*/
|
||||
public function testEndsWith($expected, $str, $substring,
|
||||
$caseSensitive = true, $encoding = null)
|
||||
$caseSensitive = true, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->endsWith($substring, $caseSensitive);
|
||||
@@ -253,7 +262,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForToSpaces
|
||||
* @dataProvider toSpacesProvider()
|
||||
*/
|
||||
public function testToSpaces($expected, $str, $tabLength = 4)
|
||||
{
|
||||
@@ -265,7 +274,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForToTabs
|
||||
* @dataProvider toTabsProvider()
|
||||
*/
|
||||
public function testToTabs($expected, $str, $tabLength = 4)
|
||||
{
|
||||
@@ -277,7 +286,31 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForSlugify
|
||||
* @dataProvider toLowerCaseProvider()
|
||||
*/
|
||||
public function testToLowerCase($expected, $str, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->toLowerCase();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider toUpperCaseProvider()
|
||||
*/
|
||||
public function testToUpperCase($expected, $str, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->toUpperCase();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider slugifyProvider()
|
||||
*/
|
||||
public function testSlugify($expected, $str)
|
||||
{
|
||||
@@ -289,19 +322,20 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForContains
|
||||
* @dataProvider containsProvider()
|
||||
*/
|
||||
public function testContains($expected, $haystack, $needle, $encoding = null)
|
||||
public function testContains($expected, $haystack, $needle,
|
||||
$caseSensitive = true, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($haystack, $encoding);
|
||||
$result = $stringy->contains($needle);
|
||||
$result = $stringy->contains($needle, $caseSensitive);
|
||||
$this->assertInternalType('boolean', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($haystack, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForSurround
|
||||
* @dataProvider surroundProvider()
|
||||
*/
|
||||
public function testSurround($expected, $str, $substring)
|
||||
{
|
||||
@@ -313,7 +347,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForInsert
|
||||
* @dataProvider insertProvider()
|
||||
*/
|
||||
public function testInsert($expected, $str, $substring, $index,
|
||||
$encoding = null)
|
||||
@@ -326,7 +360,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForTruncate
|
||||
* @dataProvider truncateProvider()
|
||||
*/
|
||||
public function testTruncate($expected, $str, $length, $substring = '',
|
||||
$encoding = null)
|
||||
@@ -339,7 +373,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForReverse
|
||||
* @dataProvider reverseProvider()
|
||||
*/
|
||||
public function testReverse($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -351,7 +385,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForShuffle
|
||||
* @dataProvider shuffleProvider()
|
||||
*/
|
||||
public function testShuffle($str, $encoding = null)
|
||||
{
|
||||
@@ -374,7 +408,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForTrim
|
||||
* @dataProvider trimProvider()
|
||||
*/
|
||||
public function testTrim($expected, $str)
|
||||
{
|
||||
@@ -386,7 +420,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForLongestCommonPrefix
|
||||
* @dataProvider longestCommonPrefixProvider()
|
||||
*/
|
||||
public function testLongestCommonPrefix($expected, $str, $otherStr,
|
||||
$encoding = null)
|
||||
@@ -399,7 +433,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForLongestCommonSubstring
|
||||
* @dataProvider longestCommonSubstringProvider()
|
||||
*/
|
||||
public function testLongestCommonSubstring($expected, $str, $otherStr,
|
||||
$encoding = null)
|
||||
@@ -412,7 +446,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForLength
|
||||
* @dataProvider lengthProvider()
|
||||
*/
|
||||
public function testLength($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -424,7 +458,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForSubstr
|
||||
* @dataProvider substrProvider()
|
||||
*/
|
||||
public function testSubstr($expected, $str, $start, $length = null,
|
||||
$encoding = null)
|
||||
@@ -437,7 +471,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForAt
|
||||
* @dataProvider atProvider()
|
||||
*/
|
||||
public function testAt($expected, $str, $index, $encoding = null)
|
||||
{
|
||||
@@ -449,7 +483,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForFirst
|
||||
* @dataProvider firstProvider()
|
||||
*/
|
||||
public function testFirst($expected, $str, $n, $encoding = null)
|
||||
{
|
||||
@@ -461,7 +495,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForLast
|
||||
* @dataProvider lastProvider()
|
||||
*/
|
||||
public function testLast($expected, $str, $n, $encoding = null)
|
||||
{
|
||||
@@ -473,7 +507,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForEnsureLeft
|
||||
* @dataProvider ensureLeftProvider()
|
||||
*/
|
||||
public function testEnsureLeft($expected, $str, $substring, $encoding = null)
|
||||
{
|
||||
@@ -485,7 +519,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForEnsureRight
|
||||
* @dataProvider ensureRightProvider()
|
||||
*/
|
||||
public function testEnsureRight($expected, $str, $substring, $encoding = null)
|
||||
{
|
||||
@@ -497,7 +531,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForRemoveLeft
|
||||
* @dataProvider removeLeftProvider()
|
||||
*/
|
||||
public function testRemoveLeft($expected, $str, $substring, $encoding = null)
|
||||
{
|
||||
@@ -509,7 +543,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForRemoveRight
|
||||
* @dataProvider removeRightProvider()
|
||||
*/
|
||||
public function testRemoveRight($expected, $str, $substring, $encoding = null)
|
||||
{
|
||||
@@ -521,7 +555,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsAlpha
|
||||
* @dataProvider isAlphaProvider()
|
||||
*/
|
||||
public function testIsAlpha($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -533,7 +567,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsAlphanumeric
|
||||
* @dataProvider isAlphanumericProvider()
|
||||
*/
|
||||
public function testIsAlphanumeric($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -545,7 +579,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsBlank
|
||||
* @dataProvider isBlankProvider()
|
||||
*/
|
||||
public function testIsBlank($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -557,7 +591,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsJson
|
||||
* @dataProvider isJsonProvider()
|
||||
*/
|
||||
public function testIsJson($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -569,7 +603,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsLowerCase
|
||||
* @dataProvider isLowerCaseProvider()
|
||||
*/
|
||||
public function testIsLowerCase($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -581,7 +615,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsSerialized
|
||||
* @dataProvider isSerializedProvider()
|
||||
*/
|
||||
public function testIsSerialized($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -593,7 +627,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsUpperCase
|
||||
* @dataProvider isUpperCaseProvider()
|
||||
*/
|
||||
public function testIsUpperCase($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -605,7 +639,7 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsHexadecimal
|
||||
* @dataProvider isHexadecimalProvider()
|
||||
*/
|
||||
public function testIsHexadecimal($expected, $str, $encoding = null)
|
||||
{
|
||||
@@ -617,25 +651,39 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForCount
|
||||
* @dataProvider countProvider()
|
||||
*/
|
||||
public function testCount($expected, $str, $substring, $encoding = null)
|
||||
public function testCount($expected, $str, $substring, $caseSensitive = true,
|
||||
$encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->count($substring);
|
||||
$result = $stringy->count($substring, $caseSensitive);
|
||||
$this->assertInternalType('int', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForReplace
|
||||
* @dataProvider replaceProvider()
|
||||
*/
|
||||
public function testReplace($expected, $str, $search, $replace,
|
||||
public function testReplace($expected, $str, $search, $replacement,
|
||||
$encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->replace($search, $replace);
|
||||
$result = $stringy->replace($search, $replacement);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider regexReplaceProvider()
|
||||
*/
|
||||
public function testregexReplace($expected, $str, $pattern, $replacement,
|
||||
$options = 'msr', $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->regexReplace($pattern, $replacement, $options);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
|
Reference in New Issue
Block a user