From 0d92d7e810c42858f78ede7ad60e107ff5ddb62a Mon Sep 17 00:00:00 2001 From: "Daniel St. Jules" Date: Wed, 22 Jul 2015 18:15:54 -0700 Subject: [PATCH] Remove StaticStringy --- phpunit.xml.dist | 1 - src/StaticStringy.php | 979 ------------------------------ tests/CommonTest.php | 1130 ----------------------------------- tests/StaticStringyTest.php | 710 ---------------------- tests/StringyTest.php | 1126 +++++++++++++++++++++++++++++++++- 5 files changed, 1125 insertions(+), 2821 deletions(-) delete mode 100644 src/StaticStringy.php delete mode 100644 tests/CommonTest.php delete mode 100644 tests/StaticStringyTest.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 987dbbf..27cb585 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -7,7 +7,6 @@ tests/CommonTest.php tests/StringyTest.php - tests/StaticStringyTest.php tests/CreateTest.php diff --git a/src/StaticStringy.php b/src/StaticStringy.php deleted file mode 100644 index c3a5659..0000000 --- a/src/StaticStringy.php +++ /dev/null @@ -1,979 +0,0 @@ -chars(); - } - - /** - * Converts the first character of the supplied string to upper case. - * - * @param string $str String to modify - * @param string $encoding The character encoding - * @return string String with the first character being upper case - */ - public static function upperCaseFirst($str, $encoding = null) - { - return (string) Stringy::create($str, $encoding)->upperCaseFirst(); - } - - /** - * Converts the first character of the supplied string to lower case. - * - * @param string $str String to modify - * @param string $encoding The character encoding - * @return string String with the first character being lower case - */ - public static function lowerCaseFirst($str, $encoding = null) - { - return (string) Stringy::create($str, $encoding)->lowerCaseFirst(); - } - - /** - * Returns a camelCase version of the string. Trims surrounding spaces, - * capitalizes letters following digits, spaces, dashes and underscores, - * and removes spaces, dashes, as well as underscores. - * - * @param string $str String to convert to camelCase - * @param string $encoding The character encoding - * @return string String in camelCase - */ - public static function camelize($str, $encoding = null) - { - return (string) Stringy::create($str, $encoding)->camelize(); - } - - /** - * Returns an UpperCamelCase version of the supplied string. It trims - * surrounding spaces, capitalizes letters following digits, spaces, dashes - * and underscores, and removes spaces, dashes, underscores. - * - * @param string $str String to convert to UpperCamelCase - * @param string $encoding The character encoding - * @return string String in UpperCamelCase - */ - public static function upperCamelize($str, $encoding = null) - { - return (string) Stringy::create($str, $encoding)->upperCamelize(); - } - - /** - * Returns a lowercase and trimmed string separated by dashes. Dashes are - * inserted before uppercase characters (with the exception of the first - * character of the string), and in place of spaces as well as underscores. - * - * @param string $str String to convert - * @param string $encoding The character encoding - * @return string Dasherized string - */ - public static function dasherize($str, $encoding = null) - { - return (string) Stringy::create($str, $encoding)->dasherize(); - } - - /** - * Returns a lowercase and trimmed string separated by underscores. - * Underscores are inserted before uppercase characters (with the exception - * of the first character of the string), and in place of spaces as well as - * dashes. - * - * @param string $str String to convert - * @param string $encoding The character encoding - * @return string Underscored string - */ - public static function underscored($str, $encoding = null) - { - return (string) Stringy::create($str, $encoding)->underscored(); - } - - /** - * Returns a lowercase and trimmed string separated by the given delimiter. - * Delimiters are inserted before uppercase characters (with the exception - * of the first character of the string), and in place of spaces, dashes, - * and underscores. Alpha delimiters are not converted to lowercase. - * - * @param string $str String to convert - * @param string $delimiter Sequence used to separate parts of the string - * @param string $encoding The character encoding - * @return string String with delimiter - */ - public static function delimit($str, $delimiter, $encoding = null) - { - return (string) Stringy::create($str, $encoding)->delimit($delimiter); - } - - /** - * Returns a case swapped version of the string. - * - * @param string $str String to swap case - * @param string $encoding The character encoding - * @return string String with each character's case swapped - */ - public static function swapCase($str, $encoding = null) - { - return (string) Stringy::create($str, $encoding)->swapCase(); - } - - /** - * Returns a trimmed string with the first letter of each word capitalized. - * Ignores the case of other letters, preserving any acronyms. Also accepts - * an array, $ignore, allowing you to list words not to be capitalized. - * - * @param string $str String to titleize - * @param string $encoding The character encoding - * @param array $ignore An array of words not to capitalize - * @return string Titleized string - */ - public static function titleize($str, $ignore = null, $encoding = null) - { - return (string) Stringy::create($str, $encoding)->titleize($ignore); - } - - /** - * Capitalizes the first word of the string, replaces underscores with - * spaces, and strips '_id'. - * - * @param string $str String to humanize - * @param string $encoding The character encoding - * @return string A humanized string - */ - public static function humanize($str, $encoding = null) - { - return (string) Stringy::create($str, $encoding)->humanize(); - } - - /** - * Returns a string with smart quotes, ellipsis characters, and dashes from - * Windows-1252 (commonly used in Word documents) replaced by their ASCII - * equivalents. - * - * @param string $str String to remove special chars - * @return string String with those characters removed - */ - public static function tidy($str) - { - return (string) Stringy::create($str)->tidy(); - } - - /** - * Trims the string and replaces consecutive whitespace characters with a - * 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 $encoding The character encoding - * @return string The trimmed string with condensed whitespace - */ - public static function collapseWhitespace($str, $encoding = null) - { - return (string) Stringy::create($str, $encoding)->collapseWhitespace(); - } - - /** - * Returns an ASCII version of the string. A set of non-ASCII characters are - * replaced with their closest ASCII counterparts, and the rest are removed - * unless instructed otherwise. - * - * @param string $str A string with non-ASCII characters - * @param bool $removeUnsupported Whether or not to remove the - * unsupported characters - * @return string A string containing only ASCII characters - */ - public static function toAscii($str, $removeUnsupported = true) - { - return (string) Stringy::create($str)->toAscii($removeUnsupported); - } - - /** - * Pads the string to a given length with $padStr. If length is less than - * or equal to the length of the string, no padding takes places. The - * default string used for padding is a space, and the default type (one of - * 'left', 'right', 'both') is 'right'. Throws an InvalidArgumentException - * if $padType isn't one of those 3 values. - * - * @param string $str String to pad - * @param int $length Desired string length after padding - * @param string $padStr String used to pad, defaults to space - * @param string $padType One of 'left', 'right', 'both' - * @param string $encoding The character encoding - * @return string The padded string - * @throws \InvalidArgumentException If $padType isn't one of 'right', - * 'left' or 'both' - */ - public static function pad($str, $length, $padStr = ' ', $padType = 'right', - $encoding = null) - { - return (string) Stringy::create($str, $encoding) - ->pad($length, $padStr, $padType); - } - - /** - * Returns a new string of a given length such that the beginning of the - * string is padded. Alias for pad() with a $padType of 'left'. - * - * @param string $str String to pad - * @param int $length Desired string length after padding - * @param string $padStr String used to pad, defaults to space - * @param string $encoding The character encoding - * @return string The padded string - */ - public static function padLeft($str, $length, $padStr = ' ', $encoding = null) - { - return (string) Stringy::create($str, $encoding) - ->padLeft($length, $padStr); - } - - /** - * 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 string $str String to pad - * @param int $length Desired string length after padding - * @param string $padStr String used to pad, defaults to space - * @param string $encoding The character encoding - * @return string The padded string - */ - public static function padRight($str, $length, $padStr = ' ', $encoding = null) - { - return (string) Stringy::create($str, $encoding) - ->padRight($length, $padStr); - } - - /** - * Returns a new string of a given length such that both sides of the - * string are padded. Alias for pad() with a $padType of 'both'. - * - * @param string $str String to pad - * @param int $length Desired string length after padding - * @param string $padStr String used to pad, defaults to space - * @param string $encoding The character encoding - * @return string The padded string - */ - public static function padBoth($str, $length, $padStr = ' ', $encoding = null) - { - return (string) Stringy::create($str, $encoding) - ->padBoth($length, $padStr); - } - - /** - * Returns true if the string begins with $substring, false otherwise. By - * default, the comparison is case-sensitive, but can be made insensitive - * by setting $caseSensitive to false. - * - * @param string $str String to check the start of - * @param string $substring The 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 $str starts with $substring - */ - public static function startsWith($str, $substring, $caseSensitive = true, - $encoding = null) - { - return Stringy::create($str, $encoding) - ->startsWith($substring, $caseSensitive); - } - - /** - * Returns true if the string ends with $substring, false otherwise. By - * default, the comparison is case-sensitive, but can be made insensitive - * by setting $caseSensitive to false. - * - * @param string $str String to check the end of - * @param string $substring The 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 $str ends with $substring - */ - public static function endsWith($str, $substring, $caseSensitive = true, - $encoding = null) - { - return Stringy::create($str, $encoding) - ->endsWith($substring, $caseSensitive); - } - - /** - * Converts each tab in the string to some number of spaces, as defined by - * $tabLength. By default, each tab is converted to 4 consecutive spaces. - * - * @param string $str String to convert tabs to spaces - * @param int $tabLength Number of spaces to replace each tab with - * @return string String with tabs switched to spaces - */ - public static function toSpaces($str, $tabLength = 4) - { - return (string) Stringy::create($str)->toSpaces($tabLength); - } - - /** - * Converts each occurrence of some consecutive number of spaces, as - * defined by $tabLength, to a tab. By default, each 4 consecutive spaces - * are converted to a tab. - * - * @param string $str String to convert spaces to tabs - * @param int $tabLength Number of spaces to replace with a tab - * @return string String with spaces switched to tabs - */ - public static function toTabs($str, $tabLength = 4) - { - return (string) Stringy::create($str)->toTabs($tabLength); - } - - /** - * 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 (string) Stringy::create($str, $encoding)->toLowerCase(); - } - - /** - * Converts the first character of each word in the string to uppercase. - * - * @param string $str String to convert case - * @param string $encoding The character encoding - * @return string The title-cased string - */ - public static function toTitleCase($str, $encoding = null) - { - return (string) Stringy::create($str, $encoding)->toTitleCase(); - } - - /** - * 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 (string) Stringy::create($str, $encoding)->toUpperCase(); - } - - /** - * Converts the string into an URL slug. This includes replacing non-ASCII - * characters with their closest ASCII equivalents, removing remaining - * non-ASCII and non-alphanumeric characters, and replacing whitespace with - * $replacement. The replacement defaults to a single dash, and the string - * is also converted to lowercase. - * - * @param string $str Text to transform into an URL slug - * @param string $replacement The string used to replace whitespace - * @return string The corresponding URL slug - */ - public static function slugify($str, $replacement = '-') - { - return (string) Stringy::create($str)->slugify($replacement); - } - - /** - * 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 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, $caseSensitive = true, - $encoding = null) - { - return Stringy::create($haystack, $encoding) - ->contains($needle, $caseSensitive); - } - - /** - * Returns true if the string contains any $needles, 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 array $needles Substrings 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 any $needles - */ - public static function containsAny($haystack, $needles, - $caseSensitive = true, $encoding = null) - { - return Stringy::create($haystack, $encoding) - ->containsAny($needles, $caseSensitive); - } - - /** - * Returns true if the string contains all $needles, 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 array $needles Substrings 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 all $needles - */ - public static function containsAll($haystack, $needles, - $caseSensitive = true, $encoding = null) - { - return Stringy::create($haystack, $encoding) - ->containsAll($needles, $caseSensitive); - } - - /** - * Returns the index of the first occurrence of $needle in the string, - * and false if not found. Accepts an optional offset from which to begin - * the search. - * - * @param string $haystack String to search - * @param string $needle Substring to look for - * @param int $offset Offset from which to search - * @return int|bool The occurrence's index if found, otherwise false - */ - public static function indexOf($haystack, $needle, $offset = 0, - $encoding = null) - { - return Stringy::create($haystack, $encoding) - ->indexOf($needle, $offset); - } - - /** - * Returns the index of the last occurrence of $needle in the string, - * and false if not found. Accepts an optional offset from which to begin - * the search. - * - * @param string $haystack String to search - * @param string $needle Substring to look for - * @param int $offset Offset from which to search - * @return int|bool The last occurrence's index if found, otherwise false - */ - public static function indexOfLast($haystack, $needle, $offset = 0, - $encoding = null) - { - return Stringy::create($haystack, $encoding) - ->indexOfLast($needle, $offset); - } - - /** - * Surrounds a string with the given substring. - * - * @param string $str The string to surround - * @param string $substring The substring to add to both sides - * @return string The string with the substring prepended and appended - */ - public static function surround($str, $substring) - { - return (string) Stringy::create($str)->surround($substring); - } - - /** - * Inserts $substring into the string at the $index provided. - * - * @param string $str String to insert into - * @param string $substring String to be inserted - * @param int $index The index at which to insert the substring - * @param string $encoding The character encoding - * @return string The resulting string after the insertion - */ - public static function insert($str, $substring, $index, $encoding = null) - { - return (string) Stringy::create($str, $encoding) - ->insert($substring, $index); - } - - /** - * Truncates the string to a given length. If $substring is provided, and - * truncating occurs, the string is further truncated so that the substring - * may be appended without exceeding the desired length. - * - * @param string $str String to truncate - * @param int $length Desired length of the truncated string - * @param string $substring The substring to append if it can fit - * @param string $encoding The character encoding - * @return string The resulting string after truncating - */ - public static function truncate($str, $length, $substring = '', - $encoding = null) - { - return (string) Stringy::create($str, $encoding) - ->truncate($length, $substring); - } - - /** - * Truncates the string to a given length, while ensuring that it does not - * split words. If $substring is provided, and truncating occurs, the - * string is further truncated so that the substring may be appended without - * exceeding the desired length. - * - * @param string $str String to truncate - * @param int $length Desired length of the truncated string - * @param string $substring The substring to append if it can fit - * @param string $encoding The character encoding - * @return string The resulting string after truncating - */ - public static function safeTruncate($str, $length, $substring = '', - $encoding = null) - { - return (string) Stringy::create($str, $encoding) - ->safeTruncate($length, $substring); - } - - /** - * Returns a reversed string. A multibyte version of strrev(). - * - * @param string $str String to reverse - * @param string $encoding The character encoding - * @return string The reversed string - */ - public static function reverse($str, $encoding = null) - { - return (string) Stringy::create($str, $encoding)->reverse(); - } - - /** - * A multibyte str_shuffle() function. It returns a string with its - * characters in random order. - * - * @param string $str String to shuffle - * @param string $encoding The character encoding - * @return string The shuffled string - */ - public static function shuffle($str, $encoding = null) - { - return (string) Stringy::create($str, $encoding)->shuffle(); - } - - /** - * Returns a string with whitespace removed from the start and end of the - * string. Supports the removal of unicode whitespace. Accepts an optional - * string of characters to strip instead of the defaults. - * - * @param string $str String to trim - * @param string $chars Optional string of characters to strip - * @param string $encoding The character encoding - * @return string Trimmed $str - */ - public static function trim($str, $chars = null, $encoding = null) - { - return (string) Stringy::create($str, $encoding)->trim($chars); - } - - /** - * Returns a string with whitespace removed from the start of the string. - * Supports the removal of unicode whitespace. Accepts an optional - * string of characters to strip instead of the defaults. - * - * @param string $str String to trim - * @param string $chars Optional string of characters to strip - * @param string $encoding The character encoding - * @return string Trimmed $str - */ - public static function trimLeft($str, $chars = null, $encoding = null) - { - return (string) Stringy::create($str, $encoding)->trimLeft($chars); - } - - /** - * Returns a string with whitespace removed from the end of the string. - * Supports the removal of unicode whitespace. Accepts an optional - * string of characters to strip instead of the defaults. - * - * @param string $str String to trim - * @param string $chars Optional string of characters to strip - * @param string $encoding The character encoding - * @return string Trimmed $str - */ - public static function trimRight($str, $chars = null, $encoding = null) - { - return (string) Stringy::create($str, $encoding)->trimRight($chars); - } - - /** - * Returns the longest common prefix between the string and $otherStr. - * - * @param string $str First string for comparison - * @param string $otherStr Second string for comparison - * @param string $encoding The character encoding - * @return string The longest common prefix - */ - public static function longestCommonPrefix($str, $otherStr, $encoding = null) - { - return (string) Stringy::create($str, $encoding) - ->longestCommonPrefix($otherStr); - } - - /** - * Returns the longest common suffix between the string and $otherStr. - * - * @param string $str First string for comparison - * @param string $otherStr Second string for comparison - * @param string $encoding The character encoding - * @return string The longest common suffix - */ - public static function longestCommonSuffix($str, $otherStr, $encoding = null) - { - return (string) Stringy::create($str, $encoding) - ->longestCommonSuffix($otherStr); - } - - /** - * Returns the longest common substring between the string and $otherStr. - * In the case of ties, it returns that which occurs first. - * - * @param string $str First string for comparison - * @param string $otherStr Second string for comparison - * @param string $encoding The character encoding - * @return string The longest common substring - */ - public static function longestCommonSubstring($str, $otherStr, - $encoding = null) - { - return (string) Stringy::create($str, $encoding) - ->longestCommonSubstring($otherStr); - } - - /** - * Returns the length of the string. An alias for PHP's mb_strlen() function. - * - * @param string $str The string to get the length of - * @param string $encoding The character encoding - * @return int The number of characters in $str given the encoding - */ - public static function length($str, $encoding = null) - { - return Stringy::create($str, $encoding)->length(); - } - - /** - * Returns the substring beginning at $start with the specified $length. - * It differs from the mb_substr() function in that providing a $length of - * null will return the rest of the string, rather than an empty string. - * - * @param string $str The string to get the length of - * @param int $start Position of the first character to use - * @param int $length Maximum number of characters used - * @param string $encoding The character encoding - * @return string The substring of $str - */ - public static function substr($str, $start, $length = null, $encoding = null) - { - return (string) Stringy::create($str, $encoding)->substr($start, $length); - } - - /** - * Returns the character at $index, with indexes starting at 0. - * - * @param string $str The string from which to get the char - * @param int $index Position of the character - * @param string $encoding The character encoding - * @return string The character at $index - */ - public static function at($str, $index, $encoding = null) - { - return (string) Stringy::create($str, $encoding)->at($index); - } - - /** - * Returns the first $n characters of the string. - * - * @param string $str The string from which to get the substring - * @param int $n Number of chars to retrieve from the start - * @param string $encoding The character encoding - * @return string The first $n characters - */ - public static function first($str, $n, $encoding = null) - { - return (string) Stringy::create($str, $encoding)->first($n); - } - - /** - * Returns the last $n characters of the string. - * - * @param string $str The string from which to get the substring - * @param int $n Number of chars to retrieve from the end - * @param string $encoding The character encoding - * @return string The last $n characters - */ - public static function last($str, $n, $encoding = null) - { - return (string) Stringy::create($str, $encoding)->last($n); - } - - /** - * Ensures that the string begins with $substring. If it doesn't, it's - * prepended. - * - * @param string $str The string to modify - * @param string $substring The substring to add if not present - * @param string $encoding The character encoding - * @return string The string prefixed by the $substring - */ - public static function ensureLeft($str, $substring, $encoding = null) - { - return (string) Stringy::create($str, $encoding)->ensureLeft($substring); - } - - /** - * Ensures that the string begins with $substring. If it doesn't, it's - * appended. - * - * @param string $str The string to modify - * @param string $substring The substring to add if not present - * @param string $encoding The character encoding - * @return string The string suffixed by the $substring - */ - public static function ensureRight($str, $substring, $encoding = null) - { - return (string) Stringy::create($str, $encoding)->ensureRight($substring); - } - - /** - * Returns a new string with the prefix $substring removed, if present. - * - * @param string $str String from which to remove the prefix - * @param string $substring The prefix to remove - * @param string $encoding The character encoding - * @return string The string without the prefix $substring - */ - public static function removeLeft($str, $substring, $encoding = null) - { - return (string) Stringy::create($str, $encoding)->removeLeft($substring); - } - - /** - * Returns a new string with the suffix $substring removed, if present. - * - * @param string $str String from which to remove the suffix - * @param string $substring The suffix to remove - * @param string $encoding The character encoding - * @return string The string without the suffix $substring - */ - public static function removeRight($str, $substring, $encoding = null) - { - return (string) Stringy::create($str, $encoding)->removeRight($substring); - } - - /** - * Returns true if the string contains a lower case char, false - * otherwise. - * - * @param string $str String to check - * @param string $encoding The character encoding - * @return bool Whether or not $str contains a lower case character. - */ - public static function hasLowerCase($str, $encoding = null) - { - return Stringy::create($str, $encoding)->hasLowerCase(); - } - - /** - * Returns true if the string contains an upper case char, false - * otherwise. - * - * @param string $str String to check - * @param string $encoding The character encoding - * @return bool Whether or not $str contains an upper case character. - */ - public static function hasUpperCase($str, $encoding = null) - { - return Stringy::create($str, $encoding)->hasUpperCase(); - } - - /** - * Returns true if the string contains only alphabetic chars, false - * otherwise. - * - * @param string $str String to check - * @param string $encoding The character encoding - * @return bool Whether or not $str contains only alphabetic chars - */ - public static function isAlpha($str, $encoding = null) - { - return Stringy::create($str, $encoding)->isAlpha(); - } - - /** - * Returns true if the string contains only alphabetic and numeric chars, - * false otherwise. - * - * @param string $str String to check - * @param string $encoding The character encoding - * @return bool Whether or not $str contains only alphanumeric chars - */ - public static function isAlphanumeric($str, $encoding = null) - { - return Stringy::create($str, $encoding)->isAlphanumeric(); - } - - /** - * Returns true if the string contains only whitespace chars, false - * otherwise. - * - * @param string $str String to check - * @param string $encoding The character encoding - * @return bool Whether or not $str contains only whitespace characters - */ - public static function isBlank($str, $encoding = null) - { - return Stringy::create($str, $encoding)->isBlank(); - } - - /** - * Returns true if the string is JSON, false otherwise. - * - * @param string $str String to check - * @param string $encoding The character encoding - * @return bool Whether or not $str is JSON - */ - public static function isJson($str, $encoding = null) - { - return Stringy::create($str, $encoding)->isJson(); - } - - /** - * Returns true if the string contains only lower case chars, false - * otherwise. - * - * @param string $str String to check - * @param string $encoding The character encoding - * @return bool Whether or not $str contains only lower case characters - */ - public static function isLowerCase($str, $encoding = null) - { - return Stringy::create($str, $encoding)->isLowerCase(); - } - - /** - * Returns true if the string is serialized, false otherwise. - * - * @param string $str String to check - * @param string $encoding The character encoding - * @return bool Whether or not $str is serialized - */ - public static function isSerialized($str, $encoding = null) - { - return Stringy::create($str, $encoding)->isSerialized(); - } - - /** - * Returns true if the string contains only upper case chars, false - * otherwise. - * - * @param string $str String to check - * @param string $encoding The character encoding - * @return bool Whether or not $str contains only upper case characters - */ - public static function isUpperCase($str, $encoding = null) - { - return Stringy::create($str, $encoding)->isUpperCase(); - } - - /** - * Returns true if the string contains only hexadecimal chars, false - * otherwise. - * - * @param string $str String to check - * @param string $encoding The character encoding - * @return bool Whether or not $str contains only hexadecimal characters - */ - public static function isHexadecimal($str, $encoding = null) - { - return Stringy::create($str, $encoding)->isHexadecimal(); - } - - /** - * 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. - * - * @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 countSubstr($str, $substring, $caseSensitive = true, - $encoding = null) - { - return Stringy::create($str, $encoding) - ->countSubstr($substring, $caseSensitive); - } - - /** - * 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 $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, $replacement, $encoding = null) - { - return (string) Stringy::create($str, $encoding) - ->replace($search, $replacement); - } - - /** - * 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 (string) Stringy::create($str, $encoding) - ->regexReplace($pattern, $replacement, $options, $encoding); - } - - /** - * Convert all applicable characters to HTML entities. - * - * @param string $str The string to encode. - * @param int|null $flags See http://php.net/manual/en/function.htmlentities.php - * @param string $encoding The character encoding - * @return Stringy Object with the resulting $str after being html encoded. - */ - public static function htmlEncode($str, $flags = ENT_COMPAT, $encoding = null) - { - return (string) Stringy::create($str, $encoding)->htmlEncode($flags); - } - - /** - * Convert all HTML entities to their applicable characters. - * - * @param string $str The string to decode. - * @param int|null $flags See http://php.net/manual/en/function.html-entity-decode.php - * @param string $encoding The character encoding - * @return Stringy Object with the resulting $str after being html decoded. - */ - public static function htmlDecode($str, $flags = ENT_COMPAT, $encoding = null) - { - return (string) Stringy::create($str, $encoding)->htmlDecode($flags); - } -} diff --git a/tests/CommonTest.php b/tests/CommonTest.php deleted file mode 100644 index 285deb5..0000000 --- a/tests/CommonTest.php +++ /dev/null @@ -1,1130 +0,0 @@ -assertInstanceOf('Stringy\Stringy', $actual); - } - - public function indexOfProvider() - { - return array( - array(2, 'This is the string', 'is'), - array(2, 'This is the string', 'is', 0, 'UTF-8'), - array(false, 'This is the string', 'not-found', 0, 'UTF-8'), - array(32, 'This is the string... and there is another thing', 'is', 10, 'UTF-8'), - ); - } - - public function indexOfLastProvider() - { - return array( - array(5, 'This is the string', 'is'), - array(5, 'This is the string', 'is', 0, 'UTF-8'), - array(false, 'This is the string', 'not-found', 0, 'UTF-8'), - array(32, 'This is the string... and there is another thing', 'is', 0, 'UTF-8'), - ); - } - - public function charsProvider() - { - return array( - array(array(), ''), - array(array('T', 'e', 's', 't'), 'Test'), - array(array('F', 'ò', 'ô', ' ', 'B', 'à', 'ř'), 'Fòô Bàř', 'UTF-8') - ); - } - - public function upperCaseFirstProvider() - { - return array( - array('Test', 'Test'), - array('Test', 'test'), - array('1a', '1a'), - array('Σ test', 'σ test', 'UTF-8'), - array(' σ test', ' σ test', 'UTF-8') - ); - } - - public function lowerCaseFirstProvider() - { - return array( - array('test', 'Test'), - array('test', 'test'), - array('1a', '1a'), - array('σ test', 'Σ test', 'UTF-8'), - array(' Σ test', ' Σ test', 'UTF-8') - ); - } - - public function camelizeProvider() - { - return array( - array('camelCase', 'CamelCase'), - array('camelCase', 'Camel-Case'), - array('camelCase', 'camel case'), - array('camelCase', 'camel -case'), - array('camelCase', 'camel - case'), - array('camelCase', 'camel_case'), - array('camelCTest', 'camel c test'), - array('stringWith1Number', 'string_with1number'), - array('stringWith22Numbers', 'string-with-2-2 numbers'), - array('1Camel2Case', '1camel2case'), - array('camelΣase', 'camel σase', 'UTF-8'), - array('στανιλCase', 'Στανιλ case', 'UTF-8'), - array('σamelCase', 'σamel Case', 'UTF-8') - ); - } - - public function upperCamelizeProvider() - { - return array( - array('CamelCase', 'camelCase'), - array('CamelCase', 'Camel-Case'), - array('CamelCase', 'camel case'), - array('CamelCase', 'camel -case'), - array('CamelCase', 'camel - case'), - array('CamelCase', 'camel_case'), - array('CamelCTest', 'camel c test'), - array('StringWith1Number', 'string_with1number'), - array('StringWith22Numbers', 'string-with-2-2 numbers'), - array('1Camel2Case', '1camel2case'), - array('CamelΣase', 'camel σase', 'UTF-8'), - array('ΣτανιλCase', 'στανιλ case', 'UTF-8'), - array('ΣamelCase', 'Σamel Case', 'UTF-8') - ); - } - - public function dasherizeProvider() - { - return array( - array('test-case', 'testCase'), - array('test-case', 'Test-Case'), - array('test-case', 'test case'), - array('-test-case', '-test -case'), - array('test-case', 'test - case'), - array('test-case', 'test_case'), - array('test-c-test', 'test c test'), - array('test-d-case', 'TestDCase'), - array('test-c-c-test', 'TestCCTest'), - array('string-with1number', 'string_with1number'), - array('string-with-2-2-numbers', 'String-with_2_2 numbers'), - array('1test2case', '1test2case'), - array('dash-σase', 'dash Σase', 'UTF-8'), - array('στανιλ-case', 'Στανιλ case', 'UTF-8'), - array('σash-case', 'Σash Case', 'UTF-8') - ); - } - - public function underscoredProvider() - { - return array( - array('test_case', 'testCase'), - array('test_case', 'Test-Case'), - array('test_case', 'test case'), - array('test_case', 'test -case'), - array('_test_case', '-test - case'), - array('test_case', 'test_case'), - array('test_c_test', ' test c test'), - array('test_u_case', 'TestUCase'), - array('test_c_c_test', 'TestCCTest'), - array('string_with1number', 'string_with1number'), - array('string_with_2_2_numbers', 'String-with_2_2 numbers'), - array('1test2case', '1test2case'), - array('test_σase', 'test Σase', 'UTF-8'), - array('στανιλ_case', 'Στανιλ case', 'UTF-8'), - array('σash_case', 'Σash Case', 'UTF-8') - ); - } - - public function delimitProvider() - { - return array( - array('test*case', 'testCase', '*'), - array('test&case', 'Test-Case', '&'), - array('test#case', 'test case', '#'), - array('test**case', 'test -case', '**'), - array('~!~test~!~case', '-test - case', '~!~'), - array('test*case', 'test_case', '*'), - array('test%c%test', ' test c test', '%'), - array('test+u+case', 'TestUCase', '+'), - array('test=c=c=test', 'TestCCTest', '='), - array('string#>with1number', 'string_with1number', '#>'), - array('1test2case', '1test2case', '*'), - array('test ύα σase', 'test Σase', ' ύα ', 'UTF-8',), - array('στανιλαcase', 'Στανιλ case', 'α', 'UTF-8',), - array('σashΘcase', 'Σash Case', 'Θ', 'UTF-8') - ); - } - - public function swapCaseProvider() - { - return array( - array('TESTcASE', 'testCase'), - array('tEST-cASE', 'Test-Case'), - array(' - σASH cASE', ' - Σash Case', 'UTF-8'), - array('νΤΑΝΙΛ', 'Ντανιλ', 'UTF-8') - ); - } - - public function titleizeProvider() - { - $ignore = array('at', 'by', 'for', 'in', 'of', 'on', 'out', 'to', 'the'); - - 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') - ); - } - - public function humanizeProvider() - { - return array( - array('Author', 'author_id'), - array('Test user', ' _test_user_'), - array('Συγγραφέας', ' συγγραφέας_id ', 'UTF-8') - ); - } - - public function tidyProvider() - { - return array( - array('"I see..."', '“I see…”'), - array("'This too'", "‘This too’"), - array('test-dash', 'test—dash'), - array('Ο συγγραφέας είπε...', 'Ο συγγραφέας είπε…') - ); - } - - public function collapseWhitespaceProvider() - { - return array( - array('foo bar', ' foo bar '), - array('test string', 'test string'), - array('Ο συγγραφέας', ' Ο συγγραφέας '), - array('123', ' 123 '), - array('', ' ', 'UTF-8'), // no-break space (U+00A0) - array('', '           ', 'UTF-8'), // spaces U+2000 to U+200A - array('', ' ', 'UTF-8'), // narrow no-break space (U+202F) - array('', ' ', 'UTF-8'), // medium mathematical space (U+205F) - array('', ' ', 'UTF-8'), // ideographic space (U+3000) - array('1 2 3', '  1  2  3  ', 'UTF-8'), - array('', ' '), - array('', ''), - ); - } - - public function toAsciiProvider() - { - return array( - array('foo bar', 'fòô bàř'), - array(' TEST ', ' ŤÉŚŢ '), - array('f = z = 3', 'φ = ź = 3'), - array('perevirka', 'перевірка'), - array('lysaya gora', 'лысая гора'), - array('shchuka', 'щука'), - array('', '漢字'), - array('xin chao the gioi', 'xin chào thế giới'), - array('XIN CHAO THE GIOI', 'XIN CHÀO THẾ GIỚI'), - array('dam phat chet luon', 'đấm phát chết luôn'), - array(' ', ' '), // no-break space (U+00A0) - array(' ', '           '), // spaces U+2000 to U+200A - array(' ', ' '), // narrow no-break space (U+202F) - array(' ', ' '), // medium mathematical space (U+205F) - array(' ', ' '), // ideographic space (U+3000) - array('', '𐍉'), // some uncommon, unsupported character (U+10349) - array('𐍉', '𐍉', false), - ); - } - - public function padProvider() - { - return array( - // length <= str - array('foo bar', 'foo bar', -1), - array('foo bar', 'foo bar', 7), - array('fòô bàř', 'fòô bàř', 7, ' ', 'right', 'UTF-8'), - - // right - array('foo bar ', 'foo bar', 9), - array('foo bar_*', 'foo bar', 9, '_*', 'right'), - array('fòô bàř¬ø¬', 'fòô bàř', 10, '¬ø', 'right', 'UTF-8'), - - // left - array(' foo bar', 'foo bar', 9, ' ', 'left'), - array('_*foo bar', 'foo bar', 9, '_*', 'left'), - array('¬ø¬fòô bàř', 'fòô bàř', 10, '¬ø', 'left', 'UTF-8'), - - // both - array('foo bar ', 'foo bar', 8, ' ', 'both'), - array('¬fòô bàř¬ø', 'fòô bàř', 10, '¬ø', 'both', 'UTF-8'), - array('¬øfòô bàř¬øÿ', 'fòô bàř', 12, '¬øÿ', 'both', 'UTF-8') - ); - } - - public function padLeftProvider() - { - return array( - array(' foo bar', 'foo bar', 9), - array('_*foo bar', 'foo bar', 9, '_*'), - array('_*_foo bar', 'foo bar', 10, '_*'), - array(' fòô bàř', 'fòô bàř', 9, ' ', 'UTF-8'), - array('¬øfòô bàř', 'fòô bàř', 9, '¬ø', 'UTF-8'), - array('¬ø¬fòô bàř', 'fòô bàř', 10, '¬ø', 'UTF-8'), - array('¬ø¬øfòô bàř', 'fòô bàř', 11, '¬ø', 'UTF-8'), - ); - } - - public function padRightProvider() - { - return array( - array('foo bar ', 'foo bar', 9), - array('foo bar_*', 'foo bar', 9, '_*'), - array('foo bar_*_', 'foo bar', 10, '_*'), - array('fòô bàř ', 'fòô bàř', 9, ' ', 'UTF-8'), - array('fòô bàř¬ø', 'fòô bàř', 9, '¬ø', 'UTF-8'), - array('fòô bàř¬ø¬', 'fòô bàř', 10, '¬ø', 'UTF-8'), - array('fòô bàř¬ø¬ø', 'fòô bàř', 11, '¬ø', 'UTF-8'), - ); - } - - public function padBothProvider() - { - return array( - array('foo bar ', 'foo bar', 8), - array(' foo bar ', 'foo bar', 9, ' '), - array('fòô bàř ', 'fòô bàř', 8, ' ', 'UTF-8'), - array(' fòô bàř ', 'fòô bàř', 9, ' ', 'UTF-8'), - array('fòô bàř¬', 'fòô bàř', 8, '¬ø', 'UTF-8'), - array('¬fòô bàř¬', 'fòô bàř', 9, '¬ø', 'UTF-8'), - array('¬fòô bàř¬ø', 'fòô bàř', 10, '¬ø', 'UTF-8'), - array('¬øfòô bàř¬ø', 'fòô bàř', 11, '¬ø', 'UTF-8'), - array('¬fòô bàř¬ø', 'fòô bàř', 10, '¬øÿ', 'UTF-8'), - array('¬øfòô bàř¬ø', 'fòô bàř', 11, '¬øÿ', 'UTF-8'), - array('¬øfòô bàř¬øÿ', 'fòô bàř', 12, '¬øÿ', 'UTF-8') - ); - } - - public function startsWithProvider() - { - return array( - array(true, 'foo bars', 'foo bar'), - array(true, 'FOO bars', 'foo bar', false), - array(true, 'FOO bars', 'foo BAR', false), - array(true, 'FÒÔ bàřs', 'fòô bàř', false, 'UTF-8'), - array(true, 'fòô bàřs', 'fòô BÀŘ', false, 'UTF-8'), - array(false, 'foo bar', 'bar'), - array(false, 'foo bar', 'foo bars'), - array(false, 'FOO bar', 'foo bars'), - array(false, 'FOO bars', 'foo BAR'), - array(false, 'FÒÔ bàřs', 'fòô bàř', true, 'UTF-8'), - array(false, 'fòô bàřs', 'fòô BÀŘ', true, 'UTF-8'), - ); - } - - public function endsWithProvider() - { - return array( - array(true, 'foo bars', 'o bars'), - array(true, 'FOO bars', 'o bars', false), - array(true, 'FOO bars', 'o BARs', false), - array(true, 'FÒÔ bàřs', 'ô bàřs', false, 'UTF-8'), - array(true, 'fòô bàřs', 'ô BÀŘs', false, 'UTF-8'), - array(false, 'foo bar', 'foo'), - array(false, 'foo bar', 'foo bars'), - array(false, 'FOO bar', 'foo bars'), - array(false, 'FOO bars', 'foo BARS'), - array(false, 'FÒÔ bàřs', 'fòô bàřs', true, 'UTF-8'), - array(false, 'fòô bàřs', 'fòô BÀŘS', true, 'UTF-8'), - ); - } - - public function toSpacesProvider() - { - return array( - array(' foo bar ', ' foo bar '), - array(' foo bar ', ' foo bar ', 5), - array(' foo bar ', ' foo bar ', 2), - array('foobar', ' foo bar ', 0), - array(" foo\n bar", " foo\n bar"), - array(" fòô\n bàř", " fòô\n bàř") - ); - } - - public function toTabsProvider() - { - 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àř") - ); - } - - public function toLowerCaseProvider() - { - 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 toTitleCaseProvider() - { - 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-bar', 'foo -.-"-...bar'), - array('another-foo-bar', 'another..& 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('numbers-1234', 'numbers 1234'), - array('perevirka-ryadka', 'перевірка рядка'), - array('bukvar-s-bukvoy-y', 'букварь с буквой ы'), - array('podekhal-k-podezdu-moego-doma', 'подъехал к подъезду моего дома'), - array('foo:bar:baz', 'Foo bar baz', ':'), - array('a_string_with_underscores', 'A_string with_underscores', '_'), - array('a_string_with_dashes', 'A string-with-dashes', '_'), - array('a\string\with\dashes', 'A string-with-dashes', '\\'), - array('an_odd_string', '-- An odd__ string-_', '_') - ); - } - - public function containsProvider() - { - return array( - array(true, 'Str contains foo bar', 'foo bar'), - array(true, '12398!@(*%!@# @!%#*&^%', ' @!%#*&^%'), - array(true, 'Ο συγγραφέας είπε', 'συγγραφέας', 'UTF-8'), - array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'å´¥©', true, 'UTF-8'), - array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'å˚ ∆', true, 'UTF-8'), - array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'øœ¬', true, 'UTF-8'), - array(false, 'Str contains foo bar', 'Foo bar'), - array(false, 'Str contains foo bar', 'foobar'), - array(false, 'Str contains foo bar', 'foo bar '), - array(false, 'Ο συγγραφέας είπε', ' συγγραφέας ', true, 'UTF-8'), - array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', ' ßå˚', true, 'UTF-8'), - array(true, 'Str 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, 'Str contains foo bar', 'foobar', false), - array(false, 'Str contains foo bar', 'foo bar ', false), - array(false, 'Ο συγγραφέας είπε', ' συγγραφέας ', false, 'UTF-8'), - array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', ' ßÅ˚', false, 'UTF-8') - ); - } - - public function containsAnyProvider() - { - // One needle - $singleNeedle = array_map(function ($array) { - $array[2] = array($array[2]); - return $array; - }, $this->containsProvider()); - - $provider = array( - // No needles - array(false, 'Str contains foo bar', array()), - // Multiple needles - array(true, 'Str contains foo bar', array('foo', 'bar')), - array(true, '12398!@(*%!@# @!%#*&^%', array(' @!%#*', '&^%')), - array(true, 'Ο συγγραφέας είπε', array('συγγρ', 'αφέας'), 'UTF-8'), - array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('å´¥', '©'), true, 'UTF-8'), - array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('å˚ ', '∆'), true, 'UTF-8'), - array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('øœ', '¬'), true, 'UTF-8'), - array(false, 'Str contains foo bar', array('Foo', 'Bar')), - array(false, 'Str contains foo bar', array('foobar', 'bar ')), - array(false, 'Str contains foo bar', array('foo bar ', ' foo')), - array(false, 'Ο συγγραφέας είπε', array(' συγγραφέας ', ' συγγραφ '), true, 'UTF-8'), - array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array(' ßå˚', ' ß '), true, 'UTF-8'), - array(true, 'Str contains foo bar', array('Foo bar', 'bar'), false), - array(true, '12398!@(*%!@# @!%#*&^%', array(' @!%#*&^%', '*&^%'), false), - array(true, 'Ο συγγραφέας είπε', array('ΣΥΓΓΡΑΦΈΑΣ', 'ΑΦΈΑ'), false, 'UTF-8'), - array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('Å´¥©', '¥©'), false, 'UTF-8'), - array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('Å˚ ∆', ' ∆'), false, 'UTF-8'), - array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('ØŒ¬', 'Œ'), false, 'UTF-8'), - array(false, 'Str contains foo bar', array('foobar', 'none'), false), - array(false, 'Str contains foo bar', array('foo bar ', ' ba '), false), - array(false, 'Ο συγγραφέας είπε', array(' συγγραφέας ', ' ραφέ '), false, 'UTF-8'), - array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array(' ßÅ˚', ' Å˚ '), false, 'UTF-8'), - ); - - return array_merge($singleNeedle, $provider); - } - - public function containsAllProvider() - { - // One needle - $singleNeedle = array_map(function ($array) { - $array[2] = array($array[2]); - return $array; - }, $this->containsProvider()); - - $provider = array( - // One needle - array(false, 'Str contains foo bar', array()), - // Multiple needles - array(true, 'Str contains foo bar', array('foo', 'bar')), - array(true, '12398!@(*%!@# @!%#*&^%', array(' @!%#*', '&^%')), - array(true, 'Ο συγγραφέας είπε', array('συγγρ', 'αφέας'), 'UTF-8'), - array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('å´¥', '©'), true, 'UTF-8'), - array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('å˚ ', '∆'), true, 'UTF-8'), - array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('øœ', '¬'), true, 'UTF-8'), - array(false, 'Str contains foo bar', array('Foo', 'bar')), - array(false, 'Str contains foo bar', array('foobar', 'bar')), - array(false, 'Str contains foo bar', array('foo bar ', 'bar')), - array(false, 'Ο συγγραφέας είπε', array(' συγγραφέας ', ' συγγραφ '), true, 'UTF-8'), - array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array(' ßå˚', ' ß '), true, 'UTF-8'), - array(true, 'Str contains foo bar', array('Foo bar', 'bar'), false), - array(true, '12398!@(*%!@# @!%#*&^%', array(' @!%#*&^%', '*&^%'), false), - array(true, 'Ο συγγραφέας είπε', array('ΣΥΓΓΡΑΦΈΑΣ', 'ΑΦΈΑ'), false, 'UTF-8'), - array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('Å´¥©', '¥©'), false, 'UTF-8'), - array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('Å˚ ∆', ' ∆'), false, 'UTF-8'), - array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('ØŒ¬', 'Œ'), false, 'UTF-8'), - array(false, 'Str contains foo bar', array('foobar', 'none'), false), - array(false, 'Str contains foo bar', array('foo bar ', ' ba'), false), - array(false, 'Ο συγγραφέας είπε', array(' συγγραφέας ', ' ραφέ '), false, 'UTF-8'), - array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array(' ßÅ˚', ' Å˚ '), false, 'UTF-8'), - ); - - return array_merge($singleNeedle, $provider); - } - - public function surroundProvider() - { - return array( - array('__foobar__', 'foobar', '__'), - array('test', 'test', ''), - array('**', '', '*'), - array('¬fòô bàř¬', 'fòô bàř', '¬'), - array('ßå∆˚ test ßå∆˚', ' test ', 'ßå∆˚') - ); - } - - public function insertProvider() - { - return array( - array('foo bar', 'oo bar', 'f', 0), - array('foo bar', 'f bar', 'oo', 1), - array('f bar', 'f bar', 'oo', 20), - array('foo bar', 'foo ba', 'r', 6), - array('fòô bàř', 'òô bàř', 'f', 0, 'UTF-8'), - array('fòô bàř', 'f bàř', 'òô', 1, 'UTF-8'), - array('fòô bàř', 'fòô bà', 'ř', 6, 'UTF-8') - ); - } - - public function truncateProvider() - { - 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), - array('Test fo', 'Test foo bar', 7), - array('Test', 'Test foo bar', 4), - array('Test foo bar', 'Test foo bar', 12, '...'), - array('Test foo...', 'Test foo bar', 11, '...'), - array('Test ...', 'Test foo bar', 8, '...'), - array('Test...', 'Test foo bar', 7, '...'), - array('T...', 'Test foo bar', 4, '...'), - array('Test fo....', 'Test foo bar', 11, '....'), - array('Test fòô bàř', 'Test fòô bàř', 12, '', 'UTF-8'), - array('Test fòô bà', 'Test fòô bàř', 11, '', 'UTF-8'), - array('Test fòô', 'Test fòô bàř', 8, '', 'UTF-8'), - array('Test fò', 'Test fòô bàř', 7, '', 'UTF-8'), - array('Test', 'Test fòô bàř', 4, '', 'UTF-8'), - array('Test fòô bàř', 'Test fòô bàř', 12, 'ϰϰ', 'UTF-8'), - array('Test fòô ϰϰ', 'Test fòô bàř', 11, 'ϰϰ', 'UTF-8'), - array('Test fϰϰ', 'Test fòô bàř', 8, 'ϰϰ', 'UTF-8'), - array('Test ϰϰ', 'Test fòô bàř', 7, 'ϰϰ', 'UTF-8'), - array('Teϰϰ', 'Test fòô bàř', 4, 'ϰϰ', 'UTF-8'), - array('What are your pl...', 'What are your plans today?', 19, '...') - ); - } - - public function safeTruncateProvider() - { - return array( - array('Test foo bar', 'Test foo bar', 12), - array('Test foo', 'Test foo bar', 11), - array('Test foo', 'Test foo bar', 8), - array('Test', 'Test foo bar', 7), - array('Test', 'Test foo bar', 4), - array('Test foo bar', 'Test foo bar', 12, '...'), - array('Test foo...', 'Test foo bar', 11, '...'), - array('Test...', 'Test foo bar', 8, '...'), - array('Test...', 'Test foo bar', 7, '...'), - array('...', 'Test foo bar', 4, '...'), - array('Test....', 'Test foo bar', 11, '....'), - array('Test fòô bàř', 'Test fòô bàř', 12, '', 'UTF-8'), - array('Test fòô', 'Test fòô bàř', 11, '', 'UTF-8'), - array('Test fòô', 'Test fòô bàř', 8, '', 'UTF-8'), - array('Test', 'Test fòô bàř', 7, '', 'UTF-8'), - array('Test', 'Test fòô bàř', 4, '', 'UTF-8'), - array('Test fòô bàř', 'Test fòô bàř', 12, 'ϰϰ', 'UTF-8'), - array('Test fòôϰϰ', 'Test fòô bàř', 11, 'ϰϰ', 'UTF-8'), - array('Testϰϰ', 'Test fòô bàř', 8, 'ϰϰ', 'UTF-8'), - array('Testϰϰ', 'Test fòô bàř', 7, 'ϰϰ', 'UTF-8'), - array('ϰϰ', 'Test fòô bàř', 4, 'ϰϰ', 'UTF-8'), - array('What are your plans...', 'What are your plans today?', 22, '...') - ); - } - - public function reverseProvider() - { - return array( - array('', ''), - array('raboof', 'foobar'), - array('řàbôòf', 'fòôbàř', 'UTF-8'), - array('řàb ôòf', 'fòô bàř', 'UTF-8'), - array('∂∆ ˚åß', 'ßå˚ ∆∂', 'UTF-8') - ); - } - - public function shuffleProvider() - { - return array( - array('foo bar'), - array('∂∆ ˚åß', 'UTF-8'), - array('å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'UTF-8') - ); - } - - public function trimProvider() - { - return array( - array('foo bar', ' foo bar '), - array('foo bar', ' foo bar'), - array('foo bar', 'foo bar '), - array('foo bar', "\n\t foo bar \n\t"), - array('fòô bàř', ' fòô bàř '), - array('fòô bàř', ' fòô bàř'), - array('fòô bàř', 'fòô bàř '), - array(' foo bar ', "\n\t foo bar \n\t", "\n\t"), - array('fòô bàř', "\n\t fòô bàř \n\t", null, 'UTF-8'), - array('fòô', ' fòô ', null, 'UTF-8'), // narrow no-break space (U+202F) - array('fòô', '  fòô  ', null, 'UTF-8'), // medium mathematical space (U+205F) - array('fòô', '           fòô', null, 'UTF-8') // spaces U+2000 to U+200A - ); - } - - public function trimLeftProvider() - { - return array( - array('foo bar ', ' foo bar '), - array('foo bar', ' foo bar'), - array('foo bar ', 'foo bar '), - array("foo bar \n\t", "\n\t foo bar \n\t"), - array('fòô bàř ', ' fòô bàř '), - array('fòô bàř', ' fòô bàř'), - array('fòô bàř ', 'fòô bàř '), - array('foo bar', '--foo bar', '-'), - array('fòô bàř', 'òòfòô bàř', 'ò', 'UTF-8'), - array("fòô bàř \n\t", "\n\t fòô bàř \n\t", null, 'UTF-8'), - array('fòô ', ' fòô ', null, 'UTF-8'), // narrow no-break space (U+202F) - array('fòô  ', '  fòô  ', null, 'UTF-8'), // medium mathematical space (U+205F) - array('fòô', '           fòô', null, 'UTF-8') // spaces U+2000 to U+200A - ); - } - - public function trimRightProvider() - { - return array( - array(' foo bar', ' foo bar '), - array('foo bar', 'foo bar '), - array(' foo bar', ' foo bar'), - array("\n\t foo bar", "\n\t foo bar \n\t"), - array(' fòô bàř', ' fòô bàř '), - array('fòô bàř', 'fòô bàř '), - array(' fòô bàř', ' fòô bàř'), - array('foo bar', 'foo bar--', '-'), - array('fòô bàř', 'fòô bàřòò', 'ò', 'UTF-8'), - array("\n\t fòô bàř", "\n\t fòô bàř \n\t", null, 'UTF-8'), - array(' fòô', ' fòô ', null, 'UTF-8'), // narrow no-break space (U+202F) - array('  fòô', '  fòô  ', null, 'UTF-8'), // medium mathematical space (U+205F) - array('fòô', 'fòô           ', null, 'UTF-8') // spaces U+2000 to U+200A - ); - } - - public function longestCommonPrefixProvider() - { - return array( - array('foo', 'foobar', 'foo bar'), - array('foo bar', 'foo bar', 'foo bar'), - array('f', 'foo bar', 'far boo'), - array('', 'toy car', 'foo bar'), - array('', 'foo bar', ''), - array('fòô', 'fòôbar', 'fòô bar', 'UTF-8'), - array('fòô bar', 'fòô bar', 'fòô bar', 'UTF-8'), - array('fò', 'fòô bar', 'fòr bar', 'UTF-8'), - array('', 'toy car', 'fòô bar', 'UTF-8'), - array('', 'fòô bar', '', 'UTF-8'), - ); - } - - public function longestCommonSuffixProvider() - { - return array( - array('bar', 'foobar', 'foo bar'), - array('foo bar', 'foo bar', 'foo bar'), - array('ar', 'foo bar', 'boo far'), - array('', 'foo bad', 'foo bar'), - array('', 'foo bar', ''), - array('bàř', 'fòôbàř', 'fòô bàř', 'UTF-8'), - array('fòô bàř', 'fòô bàř', 'fòô bàř', 'UTF-8'), - array(' bàř', 'fòô bàř', 'fòr bàř', 'UTF-8'), - array('', 'toy car', 'fòô bàř', 'UTF-8'), - array('', 'fòô bàř', '', 'UTF-8'), - ); - } - - public function longestCommonSubstringProvider() - { - return array( - array('foo', 'foobar', 'foo bar'), - array('foo bar', 'foo bar', 'foo bar'), - array('oo ', 'foo bar', 'boo far'), - array('foo ba', 'foo bad', 'foo bar'), - array('', 'foo bar', ''), - array('fòô', 'fòôbàř', 'fòô bàř', 'UTF-8'), - array('fòô bàř', 'fòô bàř', 'fòô bàř', 'UTF-8'), - array(' bàř', 'fòô bàř', 'fòr bàř', 'UTF-8'), - array(' ', 'toy car', 'fòô bàř', 'UTF-8'), - array('', 'fòô bàř', '', 'UTF-8'), - ); - } - - public function lengthProvider() - { - return array( - array(11, ' foo bar '), - array(1, 'f'), - array(0, ''), - array(7, 'fòô bàř', 'UTF-8') - ); - } - - public function substrProvider() - { - return array( - array('foo bar', 'foo bar', 0), - array('bar', 'foo bar', 4), - array('bar', 'foo bar', 4, null), - array('o b', 'foo bar', 2, 3), - array('', 'foo bar', 4, 0), - array('fòô bàř', 'fòô bàř', 0, null, 'UTF-8'), - array('bàř', 'fòô bàř', 4, null, 'UTF-8'), - array('ô b', 'fòô bàř', 2, 3, 'UTF-8'), - array('', 'fòô bàř', 4, 0, 'UTF-8') - ); - } - - public function atProvider() - { - return array( - array('f', 'foo bar', 0), - array('o', 'foo bar', 1), - array('r', 'foo bar', 6), - array('', 'foo bar', 7), - array('f', 'fòô bàř', 0, 'UTF-8'), - array('ò', 'fòô bàř', 1, 'UTF-8'), - array('ř', 'fòô bàř', 6, 'UTF-8'), - array('', 'fòô bàř', 7, 'UTF-8'), - ); - } - - public function firstProvider() - { - return array( - array('', 'foo bar', -5), - array('', 'foo bar', 0), - array('f', 'foo bar', 1), - array('foo', 'foo bar', 3), - array('foo bar', 'foo bar', 7), - array('foo bar', 'foo bar', 8), - array('', 'fòô bàř', -5, 'UTF-8'), - array('', 'fòô bàř', 0, 'UTF-8'), - array('f', 'fòô bàř', 1, 'UTF-8'), - array('fòô', 'fòô bàř', 3, 'UTF-8'), - array('fòô bàř', 'fòô bàř', 7, 'UTF-8'), - array('fòô bàř', 'fòô bàř', 8, 'UTF-8'), - ); - } - - public function lastProvider() - { - return array( - array('', 'foo bar', -5), - array('', 'foo bar', 0), - array('r', 'foo bar', 1), - array('bar', 'foo bar', 3), - array('foo bar', 'foo bar', 7), - array('foo bar', 'foo bar', 8), - array('', 'fòô bàř', -5, 'UTF-8'), - array('', 'fòô bàř', 0, 'UTF-8'), - array('ř', 'fòô bàř', 1, 'UTF-8'), - array('bàř', 'fòô bàř', 3, 'UTF-8'), - array('fòô bàř', 'fòô bàř', 7, 'UTF-8'), - array('fòô bàř', 'fòô bàř', 8, 'UTF-8'), - ); - } - - public function ensureLeftProvider() - { - return array( - array('foobar', 'foobar', 'f'), - array('foobar', 'foobar', 'foo'), - array('foo/foobar', 'foobar', 'foo/'), - array('http://foobar', 'foobar', 'http://'), - array('http://foobar', 'http://foobar', 'http://'), - array('fòôbàř', 'fòôbàř', 'f', 'UTF-8'), - array('fòôbàř', 'fòôbàř', 'fòô', 'UTF-8'), - array('fòô/fòôbàř', 'fòôbàř', 'fòô/', 'UTF-8'), - array('http://fòôbàř', 'fòôbàř', 'http://', 'UTF-8'), - array('http://fòôbàř', 'http://fòôbàř', 'http://', 'UTF-8'), - ); - } - - public function ensureRightProvider() - { - return array( - array('foobar', 'foobar', 'r'), - array('foobar', 'foobar', 'bar'), - array('foobar/bar', 'foobar', '/bar'), - array('foobar.com/', 'foobar', '.com/'), - array('foobar.com/', 'foobar.com/', '.com/'), - array('fòôbàř', 'fòôbàř', 'ř', 'UTF-8'), - array('fòôbàř', 'fòôbàř', 'bàř', 'UTF-8'), - array('fòôbàř/bàř', 'fòôbàř', '/bàř', 'UTF-8'), - array('fòôbàř.com/', 'fòôbàř', '.com/', 'UTF-8'), - array('fòôbàř.com/', 'fòôbàř.com/', '.com/', 'UTF-8'), - ); - } - - public function removeLeftProvider() - { - return array( - array('foo bar', 'foo bar', ''), - array('oo bar', 'foo bar', 'f'), - array('bar', 'foo bar', 'foo '), - array('foo bar', 'foo bar', 'oo'), - array('foo bar', 'foo bar', 'oo bar'), - array('oo bar', 'foo bar', Stringy::create('foo bar')->first(1), 'UTF-8'), - array('oo bar', 'foo bar', Stringy::create('foo bar')->at(0), 'UTF-8'), - array('fòô bàř', 'fòô bàř', '', 'UTF-8'), - array('òô bàř', 'fòô bàř', 'f', 'UTF-8'), - array('bàř', 'fòô bàř', 'fòô ', 'UTF-8'), - array('fòô bàř', 'fòô bàř', 'òô', 'UTF-8'), - array('fòô bàř', 'fòô bàř', 'òô bàř', 'UTF-8') - ); - } - - public function removeRightProvider() - { - return array( - array('foo bar', 'foo bar', ''), - array('foo ba', 'foo bar', 'r'), - array('foo', 'foo bar', ' bar'), - array('foo bar', 'foo bar', 'ba'), - array('foo bar', 'foo bar', 'foo ba'), - array('foo ba', 'foo bar', Stringy::create('foo bar')->last(1), 'UTF-8'), - array('foo ba', 'foo bar', Stringy::create('foo bar')->at(6), 'UTF-8'), - array('fòô bàř', 'fòô bàř', '', 'UTF-8'), - array('fòô bà', 'fòô bàř', 'ř', 'UTF-8'), - array('fòô', 'fòô bàř', ' bàř', 'UTF-8'), - array('fòô bàř', 'fòô bàř', 'bà', 'UTF-8'), - array('fòô bàř', 'fòô bàř', 'fòô bà', 'UTF-8') - ); - } - - public function isAlphaProvider() - { - return array( - array(true, ''), - array(true, 'foobar'), - array(false, 'foo bar'), - array(false, 'foobar2'), - array(true, 'fòôbàř', 'UTF-8'), - array(false, 'fòô bàř', 'UTF-8'), - array(false, 'fòôbàř2', 'UTF-8'), - array(true, 'ҠѨњфгШ', 'UTF-8'), - array(false, 'ҠѨњ¨ˆфгШ', 'UTF-8'), - array(true, '丹尼爾', 'UTF-8') - ); - } - - public function isAlphanumericProvider() - { - return array( - array(true, ''), - array(true, 'foobar1'), - array(false, 'foo bar'), - array(false, 'foobar2"'), - array(false, "\nfoobar\n"), - array(true, 'fòôbàř1', 'UTF-8'), - array(false, 'fòô bàř', 'UTF-8'), - array(false, 'fòôbàř2"', 'UTF-8'), - array(true, 'ҠѨњфгШ', 'UTF-8'), - array(false, 'ҠѨњ¨ˆфгШ', 'UTF-8'), - array(true, '丹尼爾111', 'UTF-8'), - array(true, 'دانيال1', 'UTF-8'), - array(false, 'دانيال1 ', 'UTF-8') - ); - } - - public function isBlankProvider() - { - return array( - array(true, ''), - array(true, ' '), - array(true, "\n\t "), - array(true, "\n\t \v\f"), - array(false, "\n\t a \v\f"), - array(false, "\n\t ' \v\f"), - array(false, "\n\t 2 \v\f"), - array(true, '', 'UTF-8'), - array(true, ' ', 'UTF-8'), // no-break space (U+00A0) - array(true, '           ', 'UTF-8'), // spaces U+2000 to U+200A - array(true, ' ', 'UTF-8'), // narrow no-break space (U+202F) - array(true, ' ', 'UTF-8'), // medium mathematical space (U+205F) - array(true, ' ', 'UTF-8'), // ideographic space (U+3000) - array(false, ' z', 'UTF-8'), - array(false, ' 1', 'UTF-8'), - ); - } - - public function isJsonProvider() - { - return array( - array(true, ''), - array(true, '123'), - array(true, '{"foo": "bar"}'), - array(false, '{"foo":"bar",}'), - array(false, '{"foo"}'), - array(true, '["foo"]'), - array(false, '{"foo": "bar"]'), - array(true, '123', 'UTF-8'), - array(true, '{"fòô": "bàř"}', 'UTF-8'), - array(false, '{"fòô":"bàř",}', 'UTF-8'), - array(false, '{"fòô"}', 'UTF-8'), - array(false, '["fòô": "bàř"]', 'UTF-8'), - array(true, '["fòô"]', 'UTF-8'), - array(false, '{"fòô": "bàř"]', 'UTF-8'), - ); - } - - public function isLowerCaseProvider() - { - return array( - array(true, ''), - array(true, 'foobar'), - array(false, 'foo bar'), - array(false, 'Foobar'), - array(true, 'fòôbàř', 'UTF-8'), - array(false, 'fòôbàř2', 'UTF-8'), - array(false, 'fòô bàř', 'UTF-8'), - array(false, 'fòôbÀŘ', 'UTF-8'), - ); - } - - public function hasLowerCaseProvider() - { - return array( - array(false, ''), - array(true, 'foobar'), - array(false, 'FOO BAR'), - array(true, 'fOO BAR'), - array(true, 'foO BAR'), - array(true, 'FOO BAr'), - array(true, 'Foobar'), - array(false, 'FÒÔBÀŘ', 'UTF-8'), - array(true, 'fòôbàř', 'UTF-8'), - array(true, 'fòôbàř2', 'UTF-8'), - array(true, 'Fòô bàř', 'UTF-8'), - array(true, 'fòôbÀŘ', 'UTF-8'), - ); - } - - public function isSerializedProvider() - { - return array( - array(false, ''), - array(true, 'a:1:{s:3:"foo";s:3:"bar";}'), - array(false, 'a:1:{s:3:"foo";s:3:"bar"}'), - array(true, serialize(array('foo' => 'bar'))), - array(true, 'a:1:{s:5:"fòô";s:5:"bàř";}', 'UTF-8'), - array(false, 'a:1:{s:5:"fòô";s:5:"bàř"}', 'UTF-8'), - array(true, serialize(array('fòô' => 'bár')), 'UTF-8'), - ); - } - - public function isUpperCaseProvider() - { - return array( - array(true, ''), - array(true, 'FOOBAR'), - array(false, 'FOO BAR'), - array(false, 'fOOBAR'), - array(true, 'FÒÔBÀŘ', 'UTF-8'), - array(false, 'FÒÔBÀŘ2', 'UTF-8'), - array(false, 'FÒÔ BÀŘ', 'UTF-8'), - array(false, 'FÒÔBàř', 'UTF-8'), - ); - } - - public function hasUpperCaseProvider() - { - return array( - array(false, ''), - array(true, 'FOOBAR'), - array(false, 'foo bar'), - array(true, 'Foo bar'), - array(true, 'FOo bar'), - array(true, 'foo baR'), - array(true, 'fOOBAR'), - array(false, 'fòôbàř', 'UTF-8'), - array(true, 'FÒÔBÀŘ', 'UTF-8'), - array(true, 'FÒÔBÀŘ2', 'UTF-8'), - array(true, 'fÒÔ BÀŘ', 'UTF-8'), - array(true, 'FÒÔBàř', 'UTF-8'), - ); - } - - public function isHexadecimalProvider() - { - return array( - array(true, ''), - array(true, 'abcdef'), - array(true, 'ABCDEF'), - array(true, '0123456789'), - array(true, '0123456789AbCdEf'), - array(false, '0123456789x'), - array(false, 'ABCDEFx'), - array(true, 'abcdef', 'UTF-8'), - array(true, 'ABCDEF', 'UTF-8'), - array(true, '0123456789', 'UTF-8'), - array(true, '0123456789AbCdEf', 'UTF-8'), - array(false, '0123456789x', 'UTF-8'), - array(false, 'ABCDEFx', 'UTF-8'), - ); - } - - public function countSubstrProvider() - { - return array( - array(0, '', 'foo'), - array(0, 'foo', 'bar'), - array(1, 'foo bar', 'foo'), - array(2, 'foo bar', 'o'), - 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(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') - ); - } - - public function replaceProvider() - { - return array( - array('', '', '', ''), - array('foo', '', '', 'foo'), - array('foo', '\s', '\s', 'foo'), - array('foo bar', 'foo bar', '', ''), - array('foo bar', 'foo bar', 'f(o)o', '\1'), - array('\1 bar', 'foo bar', 'foo', '\1'), - 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'), - ); - } - - public function regexReplaceProvider() - { - return array( - array('', '', '', ''), - array('bar', 'foo', 'f[o]+', 'bar'), - array('o bar', 'foo bar', 'f(o)o', '\1'), - 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') - ); - } - - public function htmlEncodeProvider() - { - return array( - array('&', '&'), - array('"', '"'), - array(''', "'", ENT_QUOTES), - array('<', '<'), - array('>', '>'), - ); - } - - public function htmlDecodeProvider() - { - return array( - array('&', '&'), - array('"', '"'), - array("'", ''', ENT_QUOTES), - array('<', '<'), - array('>', '>'), - ); - } -} diff --git a/tests/StaticStringyTest.php b/tests/StaticStringyTest.php deleted file mode 100644 index 5d17bc6..0000000 --- a/tests/StaticStringyTest.php +++ /dev/null @@ -1,710 +0,0 @@ -assertEquals($expected, $result); - } - - /** - * @dataProvider indexOfLastProvider() - */ - public function testIndexOfLast($expected, $str, $subStr, $offset = 0, $encoding = null) - { - $result = S::indexOfLast($str, $subStr, $offset, $encoding); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider charsProvider() - */ - public function testChars($expected, $str, $encoding = null) - { - $result = S::chars($str, $encoding); - $this->assertInternalType('array', $result); - foreach ($result as $char) { - $this->assertInternalType('string', $char); - } - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider upperCaseFirstProvider() - */ - public function testUpperCaseFirst($expected, $str, $encoding = null) - { - $result = S::upperCaseFirst($str, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider lowerCaseFirstProvider() - */ - public function testLowerCaseFirst($expected, $str, $encoding = null) - { - $result = S::lowerCaseFirst($str, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider camelizeProvider() - */ - public function testCamelize($expected, $str, $encoding = null) - { - $result = S::camelize($str, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider upperCamelizeProvider() - */ - public function testUpperCamelize($expected, $str, $encoding = null) - { - $result = S::upperCamelize($str, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider dasherizeProvider() - */ - public function testDasherize($expected, $str, $encoding = null) - { - $result = S::dasherize($str, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider underscoredProvider() - */ - public function testUnderscored($expected, $str, $encoding = null) - { - $result = S::underscored($str, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider swapCaseProvider() - */ - public function testSwapCase($expected, $str, $encoding = null) - { - $result = S::swapCase($str, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider titleizeProvider() - */ - public function testTitleize($expected, $str, $ignore = null, - $encoding = null) - { - $result = S::titleize($str, $ignore, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider humanizeProvider() - */ - public function testHumanize($expected, $str, $encoding = null) - { - $result = S::humanize($str, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider tidyProvider() - */ - public function testTidy($expected, $str) - { - $result = S::tidy($str); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider collapseWhitespaceProvider() - */ - public function testCollapseWhitespace($expected, $str, $encoding = null) - { - $result = S::collapseWhitespace($str, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider toAsciiProvider() - */ - public function testToAscii($expected, $str, $removeUnsupported = true) - { - $result = S::toAscii($str, $removeUnsupported); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider padProvider() - */ - public function testPad($expected, $str, $length, $padStr = ' ', - $padType = 'right', $encoding = null) - { - $result = S::pad($str, $length, $padStr, $padType, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @expectedException \InvalidArgumentException - */ - public function testPadException() - { - $result = S::pad('string', 5, 'foo', 'bar'); - } - - /** - * @dataProvider padLeftProvider() - */ - public function testPadLeft($expected, $str, $length, $padStr = ' ', - $encoding = null) - { - $result = S::padLeft($str, $length, $padStr, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider padRightProvider() - */ - public function testPadRight($expected, $str, $length, $padStr = ' ', - $encoding = null) - { - $result = S::padRight($str, $length, $padStr, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider padBothProvider() - */ - public function testPadBoth($expected, $str, $length, $padStr = ' ', - $encoding = null) - { - $result = S::padBoth($str, $length, $padStr, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider startsWithProvider() - */ - public function testStartsWith($expected, $str, $substring, - $caseSensitive = true, $encoding = null) - { - $result = S::startsWith($str, $substring, $caseSensitive, $encoding); - $this->assertInternalType('boolean', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider endsWithProvider() - */ - public function testEndsWith($expected, $str, $substring, - $caseSensitive = true, $encoding = null) - { - $result = S::endsWith($str, $substring, $caseSensitive, $encoding); - $this->assertInternalType('boolean', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider toSpacesProvider() - */ - public function testToSpaces($expected, $str, $tabLength = 4) - { - $result = S::toSpaces($str, $tabLength); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider toTabsProvider() - */ - public function testToTabs($expected, $str, $tabLength = 4) - { - $result = S::toTabs($str, $tabLength); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider toLowerCaseProvider() - */ - public function testToLowerCase($expected, $str, $encoding = null) - { - $result = S::toLowerCase($str, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider toTitleCaseProvider() - */ - public function testToTitleCase($expected, $str, $encoding = null) - { - $result = S::toTitleCase($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, $replacement = '-') - { - $result = S::slugify($str, $replacement); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider containsProvider() - */ - public function testContains($expected, $haystack, $needle, - $caseSensitive = true, $encoding = null) - { - $result = S::contains($haystack, $needle, $caseSensitive, $encoding); - $this->assertInternalType('boolean', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider containsAnyProvider() - */ - public function testcontainsAny($expected, $haystack, $needles, - $caseSensitive = true, $encoding = null) - { - $result = S::containsAny($haystack, $needles, $caseSensitive, $encoding); - $this->assertInternalType('boolean', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider containsAllProvider() - */ - public function testContainsAll($expected, $haystack, $needles, - $caseSensitive = true, $encoding = null) - { - $result = S::containsAll($haystack, $needles, $caseSensitive, $encoding); - $this->assertInternalType('boolean', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider surroundProvider() - */ - public function testSurround($expected, $str, $substring) - { - $result = S::surround($str, $substring); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider insertProvider() - */ - public function testInsert($expected, $str, $substring, $index, - $encoding = null) - { - $result = S::insert($str, $substring, $index, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider truncateProvider() - */ - public function testTruncate($expected, $str, $length, $substring = '', - $encoding = null) - { - $result = S::truncate($str, $length, $substring, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider safeTruncateProvider() - */ - public function testSafeTruncate($expected, $str, $length, $substring = '', - $encoding = null) - { - $result = S::safeTruncate($str, $length, $substring, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider reverseProvider() - */ - public function testReverse($expected, $str, $encoding = null) - { - $result = S::reverse($str, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider shuffleProvider() - */ - public function testShuffle($str, $encoding = null) - { - $result = S::shuffle($str, $encoding); - $encoding = $encoding ?: mb_internal_encoding(); - - $this->assertInternalType('string', $result); - $this->assertEquals(mb_strlen($str, $encoding), - mb_strlen($result, $encoding)); - - // We'll make sure that the chars are present after shuffle - for ($i = 0; $i < mb_strlen($str, $encoding); $i++) { - $char = mb_substr($str, $i, 1, $encoding); - $countBefore = mb_substr_count($str, $char, $encoding); - $countAfter = mb_substr_count($result, $char, $encoding); - $this->assertEquals($countBefore, $countAfter); - } - } - - /** - * @dataProvider trimProvider() - */ - public function testTrim($expected, $str, $chars = null, $encoding = null) - { - $result = S::trim($str, $chars, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider trimLeftProvider() - */ - public function testTrimLeft($expected, $str, $chars = null, - $encoding = null) - { - $result = S::trimLeft($str, $chars, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider trimRightProvider() - */ - public function testTrimRight($expected, $str, $chars = null, - $encoding = null) - { - $result = S::trimRight($str, $chars, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider longestCommonPrefixProvider() - */ - public function testLongestCommonPrefix($expected, $str, $otherStr, - $encoding = null) - { - $result = S::longestCommonPrefix($str, $otherStr, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider longestCommonSuffixProvider() - */ - public function testLongestCommonSuffix($expected, $str, $otherStr, - $encoding = null) - { - $result = S::longestCommonSuffix($str, $otherStr, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider longestCommonSubstringProvider() - */ - public function testLongestCommonSubstring($expected, $str, $otherStr, - $encoding = null) - { - $result = S::longestCommonSubstring($str, $otherStr, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider lengthProvider() - */ - public function testLength($expected, $str, $encoding = null) - { - $result = S::length($str, $encoding); - $this->assertEquals($expected, $result); - $this->assertInternalType('int', $result); - } - - /** - * @dataProvider substrProvider() - */ - public function testSubstr($expected, $str, $start, $length = null, - $encoding = null) - { - $result = S::substr($str, $start, $length, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider atProvider() - */ - public function testAt($expected, $str, $index, $encoding = null) - { - $result = S::at($str, $index, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider firstProvider() - */ - public function testFirst($expected, $str, $n, $encoding = null) - { - $result = S::first($str, $n, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider lastProvider() - */ - public function testLast($expected, $str, $n, $encoding = null) - { - $result = S::last($str, $n, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider ensureLeftProvider() - */ - public function testEnsureLeft($expected, $str, $substring, $encoding = null) - { - $result = S::ensureLeft($str, $substring, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider ensureRightProvider() - */ - public function testEnsureRight($expected, $str, $substring, $encoding = null) - { - $result = S::ensureRight($str, $substring, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider removeLeftProvider() - */ - public function testRemoveLeft($expected, $str, $substring, $encoding = null) - { - $result = S::removeLeft($str, $substring, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider removeRightProvider() - */ - public function testRemoveRight($expected, $str, $substring, $encoding = null) - { - $result = S::removeRight($str, $substring, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider isAlphaProvider() - */ - public function testIsAlpha($expected, $str, $encoding = null) - { - $result = S::isAlpha($str, $encoding); - $this->assertInternalType('boolean', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider isAlphanumericProvider() - */ - public function testIsAlphanumeric($expected, $str, $encoding = null) - { - $result = S::isAlphanumeric($str, $encoding); - $this->assertInternalType('boolean', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider isBlankProvider() - */ - public function testIsBlank($expected, $str, $encoding = null) - { - $result = S::isBlank($str, $encoding); - $this->assertInternalType('boolean', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider isJsonProvider() - */ - public function testIsJson($expected, $str, $encoding = null) - { - $result = S::isJson($str, $encoding); - $this->assertInternalType('boolean', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider isLowerCaseProvider() - */ - public function testIsLowerCase($expected, $str, $encoding = null) - { - $result = S::isLowerCase($str, $encoding); - $this->assertInternalType('boolean', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider hasLowerCaseProvider() - */ - public function testHasLowerCase($expected, $str, $encoding = null) - { - $result = S::hasLowerCase($str, $encoding); - $this->assertInternalType('boolean', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider isSerializedProvider() - */ - public function testIsSerialized($expected, $str, $encoding = null) - { - $result = S::isSerialized($str, $encoding); - $this->assertInternalType('boolean', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider isUpperCaseProvider() - */ - public function testIsUpperCase($expected, $str, $encoding = null) - { - $result = S::isUpperCase($str, $encoding); - $this->assertInternalType('boolean', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider hasUpperCaseProvider() - */ - public function testHasUpperCase($expected, $str, $encoding = null) - { - $result = S::hasUpperCase($str, $encoding); - $this->assertInternalType('boolean', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider isHexadecimalProvider() - */ - public function testIsHexadecimal($expected, $str, $encoding = null) - { - $result = S::isHexadecimal($str, $encoding); - $this->assertInternalType('boolean', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider countSubstrProvider() - */ - public function testCountSubstr($expected, $str, $substring, - $caseSensitive = true, $encoding = null) - { - $result = S::countSubstr($str, $substring, $caseSensitive, $encoding); - $this->assertInternalType('int', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider replaceProvider() - */ - public function testReplace($expected, $str, $search, $replacement, - $encoding = null) - { - $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); - } - - /** - * @dataProvider htmlEncodeProvider() - */ - public function testHtmlEncode($expected, $str, $flags = ENT_COMPAT, $encoding = null) - { - $result = S::htmlEncode($str, $flags, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } - - /** - * @dataProvider htmlDecodeProvider() - */ - public function testHtmlDecode($expected, $str, $flags = ENT_COMPAT, $encoding = null) - { - $result = S::htmlDecode($str, $flags, $encoding); - $this->assertInternalType('string', $result); - $this->assertEquals($expected, $result); - } -} diff --git a/tests/StringyTest.php b/tests/StringyTest.php index b5edc43..48194bd 100644 --- a/tests/StringyTest.php +++ b/tests/StringyTest.php @@ -4,8 +4,18 @@ require __DIR__ . '/../src/Stringy.php'; use Stringy\Stringy as S; -class StringyTestCase extends CommonTest +class StringyTestCase extends PHPUnit_Framework_TestCase { + /** + * Asserts that a variable is of a Stringy instance. + * + * @param mixed $actual + */ + public function assertStringy($actual) + { + $this->assertInstanceOf('Stringy\Stringy', $actual); + } + public function testConstruct() { $stringy = new S('foo bar', 'UTF-8'); @@ -162,6 +172,16 @@ class StringyTestCase extends CommonTest $this->assertEquals($expected, $result); } + public function indexOfProvider() + { + return array( + array(2, 'This is the string', 'is'), + array(2, 'This is the string', 'is', 0, 'UTF-8'), + array(false, 'This is the string', 'not-found', 0, 'UTF-8'), + array(32, 'This is the string... and there is another thing', 'is', 10, 'UTF-8'), + ); + } + /** * @dataProvider indexOfLastProvider() */ @@ -171,6 +191,16 @@ class StringyTestCase extends CommonTest $this->assertEquals($expected, $result); } + public function indexOfLastProvider() + { + return array( + array(5, 'This is the string', 'is'), + array(5, 'This is the string', 'is', 0, 'UTF-8'), + array(false, 'This is the string', 'not-found', 0, 'UTF-8'), + array(32, 'This is the string... and there is another thing', 'is', 0, 'UTF-8'), + ); + } + /** * @dataProvider charsProvider() */ @@ -184,6 +214,15 @@ class StringyTestCase extends CommonTest $this->assertEquals($expected, $result); } + public function charsProvider() + { + return array( + array(array(), ''), + array(array('T', 'e', 's', 't'), 'Test'), + array(array('F', 'ò', 'ô', ' ', 'B', 'à', 'ř'), 'Fòô Bàř', 'UTF-8') + ); + } + /** * @dataProvider upperCaseFirstProvider() */ @@ -194,6 +233,17 @@ class StringyTestCase extends CommonTest $this->assertEquals($expected, $result); } + public function upperCaseFirstProvider() + { + return array( + array('Test', 'Test'), + array('Test', 'test'), + array('1a', '1a'), + array('Σ test', 'σ test', 'UTF-8'), + array(' σ test', ' σ test', 'UTF-8') + ); + } + /** * @dataProvider lowerCaseFirstProvider() */ @@ -206,6 +256,17 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function lowerCaseFirstProvider() + { + return array( + array('test', 'Test'), + array('test', 'test'), + array('1a', '1a'), + array('σ test', 'Σ test', 'UTF-8'), + array(' Σ test', ' Σ test', 'UTF-8') + ); + } + /** * @dataProvider camelizeProvider() */ @@ -218,6 +279,25 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function camelizeProvider() + { + return array( + array('camelCase', 'CamelCase'), + array('camelCase', 'Camel-Case'), + array('camelCase', 'camel case'), + array('camelCase', 'camel -case'), + array('camelCase', 'camel - case'), + array('camelCase', 'camel_case'), + array('camelCTest', 'camel c test'), + array('stringWith1Number', 'string_with1number'), + array('stringWith22Numbers', 'string-with-2-2 numbers'), + array('1Camel2Case', '1camel2case'), + array('camelΣase', 'camel σase', 'UTF-8'), + array('στανιλCase', 'Στανιλ case', 'UTF-8'), + array('σamelCase', 'σamel Case', 'UTF-8') + ); + } + /** * @dataProvider upperCamelizeProvider() */ @@ -230,6 +310,25 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function upperCamelizeProvider() + { + return array( + array('CamelCase', 'camelCase'), + array('CamelCase', 'Camel-Case'), + array('CamelCase', 'camel case'), + array('CamelCase', 'camel -case'), + array('CamelCase', 'camel - case'), + array('CamelCase', 'camel_case'), + array('CamelCTest', 'camel c test'), + array('StringWith1Number', 'string_with1number'), + array('StringWith22Numbers', 'string-with-2-2 numbers'), + array('1Camel2Case', '1camel2case'), + array('CamelΣase', 'camel σase', 'UTF-8'), + array('ΣτανιλCase', 'στανιλ case', 'UTF-8'), + array('ΣamelCase', 'Σamel Case', 'UTF-8') + ); + } + /** * @dataProvider dasherizeProvider() */ @@ -242,6 +341,27 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function dasherizeProvider() + { + return array( + array('test-case', 'testCase'), + array('test-case', 'Test-Case'), + array('test-case', 'test case'), + array('-test-case', '-test -case'), + array('test-case', 'test - case'), + array('test-case', 'test_case'), + array('test-c-test', 'test c test'), + array('test-d-case', 'TestDCase'), + array('test-c-c-test', 'TestCCTest'), + array('string-with1number', 'string_with1number'), + array('string-with-2-2-numbers', 'String-with_2_2 numbers'), + array('1test2case', '1test2case'), + array('dash-σase', 'dash Σase', 'UTF-8'), + array('στανιλ-case', 'Στανιλ case', 'UTF-8'), + array('σash-case', 'Σash Case', 'UTF-8') + ); + } + /** * @dataProvider underscoredProvider() */ @@ -254,6 +374,27 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function underscoredProvider() + { + return array( + array('test_case', 'testCase'), + array('test_case', 'Test-Case'), + array('test_case', 'test case'), + array('test_case', 'test -case'), + array('_test_case', '-test - case'), + array('test_case', 'test_case'), + array('test_c_test', ' test c test'), + array('test_u_case', 'TestUCase'), + array('test_c_c_test', 'TestCCTest'), + array('string_with1number', 'string_with1number'), + array('string_with_2_2_numbers', 'String-with_2_2 numbers'), + array('1test2case', '1test2case'), + array('test_σase', 'test Σase', 'UTF-8'), + array('στανιλ_case', 'Στανιλ case', 'UTF-8'), + array('σash_case', 'Σash Case', 'UTF-8') + ); + } + /** * @dataProvider delimitProvider() */ @@ -266,6 +407,26 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function delimitProvider() + { + return array( + array('test*case', 'testCase', '*'), + array('test&case', 'Test-Case', '&'), + array('test#case', 'test case', '#'), + array('test**case', 'test -case', '**'), + array('~!~test~!~case', '-test - case', '~!~'), + array('test*case', 'test_case', '*'), + array('test%c%test', ' test c test', '%'), + array('test+u+case', 'TestUCase', '+'), + array('test=c=c=test', 'TestCCTest', '='), + array('string#>with1number', 'string_with1number', '#>'), + array('1test2case', '1test2case', '*'), + array('test ύα σase', 'test Σase', ' ύα ', 'UTF-8',), + array('στανιλαcase', 'Στανιλ case', 'α', 'UTF-8',), + array('σashΘcase', 'Σash Case', 'Θ', 'UTF-8') + ); + } + /** * @dataProvider swapCaseProvider() */ @@ -278,6 +439,16 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function swapCaseProvider() + { + return array( + array('TESTcASE', 'testCase'), + array('tEST-cASE', 'Test-Case'), + array(' - σASH cASE', ' - Σash Case', 'UTF-8'), + array('νΤΑΝΙΛ', 'Ντανιλ', 'UTF-8') + ); + } + /** * @dataProvider titleizeProvider() */ @@ -291,6 +462,19 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function titleizeProvider() + { + $ignore = array('at', 'by', 'for', 'in', 'of', 'on', 'out', 'to', 'the'); + + 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') + ); + } + /** * @dataProvider humanizeProvider() */ @@ -303,6 +487,15 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function humanizeProvider() + { + return array( + array('Author', 'author_id'), + array('Test user', ' _test_user_'), + array('Συγγραφέας', ' συγγραφέας_id ', 'UTF-8') + ); + } + /** * @dataProvider tidyProvider() */ @@ -315,6 +508,16 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function tidyProvider() + { + return array( + array('"I see..."', '“I see…”'), + array("'This too'", "‘This too’"), + array('test-dash', 'test—dash'), + array('Ο συγγραφέας είπε...', 'Ο συγγραφέας είπε…') + ); + } + /** * @dataProvider collapseWhitespaceProvider() */ @@ -327,6 +530,24 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function collapseWhitespaceProvider() + { + return array( + array('foo bar', ' foo bar '), + array('test string', 'test string'), + array('Ο συγγραφέας', ' Ο συγγραφέας '), + array('123', ' 123 '), + array('', ' ', 'UTF-8'), // no-break space (U+00A0) + array('', '           ', 'UTF-8'), // spaces U+2000 to U+200A + array('', ' ', 'UTF-8'), // narrow no-break space (U+202F) + array('', ' ', 'UTF-8'), // medium mathematical space (U+205F) + array('', ' ', 'UTF-8'), // ideographic space (U+3000) + array('1 2 3', '  1  2  3  ', 'UTF-8'), + array('', ' '), + array('', ''), + ); + } + /** * @dataProvider toAsciiProvider() */ @@ -339,6 +560,29 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function toAsciiProvider() + { + return array( + array('foo bar', 'fòô bàř'), + array(' TEST ', ' ŤÉŚŢ '), + array('f = z = 3', 'φ = ź = 3'), + array('perevirka', 'перевірка'), + array('lysaya gora', 'лысая гора'), + array('shchuka', 'щука'), + array('', '漢字'), + array('xin chao the gioi', 'xin chào thế giới'), + array('XIN CHAO THE GIOI', 'XIN CHÀO THẾ GIỚI'), + array('dam phat chet luon', 'đấm phát chết luôn'), + array(' ', ' '), // no-break space (U+00A0) + array(' ', '           '), // spaces U+2000 to U+200A + array(' ', ' '), // narrow no-break space (U+202F) + array(' ', ' '), // medium mathematical space (U+205F) + array(' ', ' '), // ideographic space (U+3000) + array('', '𐍉'), // some uncommon, unsupported character (U+10349) + array('𐍉', '𐍉', false), + ); + } + /** * @dataProvider padProvider() */ @@ -352,6 +596,31 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function padProvider() + { + return array( + // length <= str + array('foo bar', 'foo bar', -1), + array('foo bar', 'foo bar', 7), + array('fòô bàř', 'fòô bàř', 7, ' ', 'right', 'UTF-8'), + + // right + array('foo bar ', 'foo bar', 9), + array('foo bar_*', 'foo bar', 9, '_*', 'right'), + array('fòô bàř¬ø¬', 'fòô bàř', 10, '¬ø', 'right', 'UTF-8'), + + // left + array(' foo bar', 'foo bar', 9, ' ', 'left'), + array('_*foo bar', 'foo bar', 9, '_*', 'left'), + array('¬ø¬fòô bàř', 'fòô bàř', 10, '¬ø', 'left', 'UTF-8'), + + // both + array('foo bar ', 'foo bar', 8, ' ', 'both'), + array('¬fòô bàř¬ø', 'fòô bàř', 10, '¬ø', 'both', 'UTF-8'), + array('¬øfòô bàř¬øÿ', 'fòô bàř', 12, '¬øÿ', 'both', 'UTF-8') + ); + } + /** * @expectedException \InvalidArgumentException */ @@ -374,6 +643,19 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function padLeftProvider() + { + return array( + array(' foo bar', 'foo bar', 9), + array('_*foo bar', 'foo bar', 9, '_*'), + array('_*_foo bar', 'foo bar', 10, '_*'), + array(' fòô bàř', 'fòô bàř', 9, ' ', 'UTF-8'), + array('¬øfòô bàř', 'fòô bàř', 9, '¬ø', 'UTF-8'), + array('¬ø¬fòô bàř', 'fòô bàř', 10, '¬ø', 'UTF-8'), + array('¬ø¬øfòô bàř', 'fòô bàř', 11, '¬ø', 'UTF-8'), + ); + } + /** * @dataProvider padRightProvider() */ @@ -387,6 +669,19 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function padRightProvider() + { + return array( + array('foo bar ', 'foo bar', 9), + array('foo bar_*', 'foo bar', 9, '_*'), + array('foo bar_*_', 'foo bar', 10, '_*'), + array('fòô bàř ', 'fòô bàř', 9, ' ', 'UTF-8'), + array('fòô bàř¬ø', 'fòô bàř', 9, '¬ø', 'UTF-8'), + array('fòô bàř¬ø¬', 'fòô bàř', 10, '¬ø', 'UTF-8'), + array('fòô bàř¬ø¬ø', 'fòô bàř', 11, '¬ø', 'UTF-8'), + ); + } + /** * @dataProvider padBothProvider() */ @@ -400,6 +695,23 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function padBothProvider() + { + return array( + array('foo bar ', 'foo bar', 8), + array(' foo bar ', 'foo bar', 9, ' '), + array('fòô bàř ', 'fòô bàř', 8, ' ', 'UTF-8'), + array(' fòô bàř ', 'fòô bàř', 9, ' ', 'UTF-8'), + array('fòô bàř¬', 'fòô bàř', 8, '¬ø', 'UTF-8'), + array('¬fòô bàř¬', 'fòô bàř', 9, '¬ø', 'UTF-8'), + array('¬fòô bàř¬ø', 'fòô bàř', 10, '¬ø', 'UTF-8'), + array('¬øfòô bàř¬ø', 'fòô bàř', 11, '¬ø', 'UTF-8'), + array('¬fòô bàř¬ø', 'fòô bàř', 10, '¬øÿ', 'UTF-8'), + array('¬øfòô bàř¬ø', 'fòô bàř', 11, '¬øÿ', 'UTF-8'), + array('¬øfòô bàř¬øÿ', 'fòô bàř', 12, '¬øÿ', 'UTF-8') + ); + } + /** * @dataProvider startsWithProvider() */ @@ -413,6 +725,23 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function startsWithProvider() + { + return array( + array(true, 'foo bars', 'foo bar'), + array(true, 'FOO bars', 'foo bar', false), + array(true, 'FOO bars', 'foo BAR', false), + array(true, 'FÒÔ bàřs', 'fòô bàř', false, 'UTF-8'), + array(true, 'fòô bàřs', 'fòô BÀŘ', false, 'UTF-8'), + array(false, 'foo bar', 'bar'), + array(false, 'foo bar', 'foo bars'), + array(false, 'FOO bar', 'foo bars'), + array(false, 'FOO bars', 'foo BAR'), + array(false, 'FÒÔ bàřs', 'fòô bàř', true, 'UTF-8'), + array(false, 'fòô bàřs', 'fòô BÀŘ', true, 'UTF-8'), + ); + } + /** * @dataProvider endsWithProvider() */ @@ -426,6 +755,23 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function endsWithProvider() + { + return array( + array(true, 'foo bars', 'o bars'), + array(true, 'FOO bars', 'o bars', false), + array(true, 'FOO bars', 'o BARs', false), + array(true, 'FÒÔ bàřs', 'ô bàřs', false, 'UTF-8'), + array(true, 'fòô bàřs', 'ô BÀŘs', false, 'UTF-8'), + array(false, 'foo bar', 'foo'), + array(false, 'foo bar', 'foo bars'), + array(false, 'FOO bar', 'foo bars'), + array(false, 'FOO bars', 'foo BARS'), + array(false, 'FÒÔ bàřs', 'fòô bàřs', true, 'UTF-8'), + array(false, 'fòô bàřs', 'fòô BÀŘS', true, 'UTF-8'), + ); + } + /** * @dataProvider toSpacesProvider() */ @@ -438,6 +784,18 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function toSpacesProvider() + { + return array( + array(' foo bar ', ' foo bar '), + array(' foo bar ', ' foo bar ', 5), + array(' foo bar ', ' foo bar ', 2), + array('foobar', ' foo bar ', 0), + array(" foo\n bar", " foo\n bar"), + array(" fòô\n bàř", " fòô\n bàř") + ); + } + /** * @dataProvider toTabsProvider() */ @@ -450,6 +808,17 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function toTabsProvider() + { + 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àř") + ); + } + /** * @dataProvider toLowerCaseProvider() */ @@ -462,6 +831,17 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function toLowerCaseProvider() + { + 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'), + ); + } + /** * @dataProvider toTitleCaseProvider() */ @@ -474,6 +854,17 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function toTitleCaseProvider() + { + 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'), + ); + } + /** * @dataProvider toUpperCaseProvider() */ @@ -486,6 +877,17 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + 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'), + ); + } + /** * @dataProvider slugifyProvider() */ @@ -498,6 +900,27 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function slugifyProvider() + { + return array( + array('foo-bar', ' foo bar '), + array('foo-bar', 'foo -.-"-...bar'), + array('another-foo-bar', 'another..& 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('numbers-1234', 'numbers 1234'), + array('perevirka-ryadka', 'перевірка рядка'), + array('bukvar-s-bukvoy-y', 'букварь с буквой ы'), + array('podekhal-k-podezdu-moego-doma', 'подъехал к подъезду моего дома'), + array('foo:bar:baz', 'Foo bar baz', ':'), + array('a_string_with_underscores', 'A_string with_underscores', '_'), + array('a_string_with_dashes', 'A string-with-dashes', '_'), + array('a\string\with\dashes', 'A string-with-dashes', '\\'), + array('an_odd_string', '-- An odd__ string-_', '_') + ); + } + /** * @dataProvider containsProvider() */ @@ -511,6 +934,33 @@ class StringyTestCase extends CommonTest $this->assertEquals($haystack, $stringy); } + public function containsProvider() + { + return array( + array(true, 'Str contains foo bar', 'foo bar'), + array(true, '12398!@(*%!@# @!%#*&^%', ' @!%#*&^%'), + array(true, 'Ο συγγραφέας είπε', 'συγγραφέας', 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'å´¥©', true, 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'å˚ ∆', true, 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'øœ¬', true, 'UTF-8'), + array(false, 'Str contains foo bar', 'Foo bar'), + array(false, 'Str contains foo bar', 'foobar'), + array(false, 'Str contains foo bar', 'foo bar '), + array(false, 'Ο συγγραφέας είπε', ' συγγραφέας ', true, 'UTF-8'), + array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', ' ßå˚', true, 'UTF-8'), + array(true, 'Str 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, 'Str contains foo bar', 'foobar', false), + array(false, 'Str contains foo bar', 'foo bar ', false), + array(false, 'Ο συγγραφέας είπε', ' συγγραφέας ', false, 'UTF-8'), + array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', ' ßÅ˚', false, 'UTF-8') + ); + } + /** * @dataProvider containsAnyProvider() */ @@ -524,6 +974,44 @@ class StringyTestCase extends CommonTest $this->assertEquals($haystack, $stringy); } + public function containsAnyProvider() + { + // One needle + $singleNeedle = array_map(function ($array) { + $array[2] = array($array[2]); + return $array; + }, $this->containsProvider()); + + $provider = array( + // No needles + array(false, 'Str contains foo bar', array()), + // Multiple needles + array(true, 'Str contains foo bar', array('foo', 'bar')), + array(true, '12398!@(*%!@# @!%#*&^%', array(' @!%#*', '&^%')), + array(true, 'Ο συγγραφέας είπε', array('συγγρ', 'αφέας'), 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('å´¥', '©'), true, 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('å˚ ', '∆'), true, 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('øœ', '¬'), true, 'UTF-8'), + array(false, 'Str contains foo bar', array('Foo', 'Bar')), + array(false, 'Str contains foo bar', array('foobar', 'bar ')), + array(false, 'Str contains foo bar', array('foo bar ', ' foo')), + array(false, 'Ο συγγραφέας είπε', array(' συγγραφέας ', ' συγγραφ '), true, 'UTF-8'), + array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array(' ßå˚', ' ß '), true, 'UTF-8'), + array(true, 'Str contains foo bar', array('Foo bar', 'bar'), false), + array(true, '12398!@(*%!@# @!%#*&^%', array(' @!%#*&^%', '*&^%'), false), + array(true, 'Ο συγγραφέας είπε', array('ΣΥΓΓΡΑΦΈΑΣ', 'ΑΦΈΑ'), false, 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('Å´¥©', '¥©'), false, 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('Å˚ ∆', ' ∆'), false, 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('ØŒ¬', 'Œ'), false, 'UTF-8'), + array(false, 'Str contains foo bar', array('foobar', 'none'), false), + array(false, 'Str contains foo bar', array('foo bar ', ' ba '), false), + array(false, 'Ο συγγραφέας είπε', array(' συγγραφέας ', ' ραφέ '), false, 'UTF-8'), + array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array(' ßÅ˚', ' Å˚ '), false, 'UTF-8'), + ); + + return array_merge($singleNeedle, $provider); + } + /** * @dataProvider containsAllProvider() */ @@ -537,6 +1025,44 @@ class StringyTestCase extends CommonTest $this->assertEquals($haystack, $stringy); } + public function containsAllProvider() + { + // One needle + $singleNeedle = array_map(function ($array) { + $array[2] = array($array[2]); + return $array; + }, $this->containsProvider()); + + $provider = array( + // One needle + array(false, 'Str contains foo bar', array()), + // Multiple needles + array(true, 'Str contains foo bar', array('foo', 'bar')), + array(true, '12398!@(*%!@# @!%#*&^%', array(' @!%#*', '&^%')), + array(true, 'Ο συγγραφέας είπε', array('συγγρ', 'αφέας'), 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('å´¥', '©'), true, 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('å˚ ', '∆'), true, 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('øœ', '¬'), true, 'UTF-8'), + array(false, 'Str contains foo bar', array('Foo', 'bar')), + array(false, 'Str contains foo bar', array('foobar', 'bar')), + array(false, 'Str contains foo bar', array('foo bar ', 'bar')), + array(false, 'Ο συγγραφέας είπε', array(' συγγραφέας ', ' συγγραφ '), true, 'UTF-8'), + array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array(' ßå˚', ' ß '), true, 'UTF-8'), + array(true, 'Str contains foo bar', array('Foo bar', 'bar'), false), + array(true, '12398!@(*%!@# @!%#*&^%', array(' @!%#*&^%', '*&^%'), false), + array(true, 'Ο συγγραφέας είπε', array('ΣΥΓΓΡΑΦΈΑΣ', 'ΑΦΈΑ'), false, 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('Å´¥©', '¥©'), false, 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('Å˚ ∆', ' ∆'), false, 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('ØŒ¬', 'Œ'), false, 'UTF-8'), + array(false, 'Str contains foo bar', array('foobar', 'none'), false), + array(false, 'Str contains foo bar', array('foo bar ', ' ba'), false), + array(false, 'Ο συγγραφέας είπε', array(' συγγραφέας ', ' ραφέ '), false, 'UTF-8'), + array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array(' ßÅ˚', ' Å˚ '), false, 'UTF-8'), + ); + + return array_merge($singleNeedle, $provider); + } + /** * @dataProvider surroundProvider() */ @@ -549,6 +1075,17 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function surroundProvider() + { + return array( + array('__foobar__', 'foobar', '__'), + array('test', 'test', ''), + array('**', '', '*'), + array('¬fòô bàř¬', 'fòô bàř', '¬'), + array('ßå∆˚ test ßå∆˚', ' test ', 'ßå∆˚') + ); + } + /** * @dataProvider insertProvider() */ @@ -562,6 +1099,19 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function insertProvider() + { + return array( + array('foo bar', 'oo bar', 'f', 0), + array('foo bar', 'f bar', 'oo', 1), + array('f bar', 'f bar', 'oo', 20), + array('foo bar', 'foo ba', 'r', 6), + array('fòô bàř', 'òô bàř', 'f', 0, 'UTF-8'), + array('fòô bàř', 'f bàř', 'òô', 1, 'UTF-8'), + array('fòô bàř', 'fòô bà', 'ř', 6, 'UTF-8') + ); + } + /** * @dataProvider truncateProvider() */ @@ -575,6 +1125,34 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function truncateProvider() + { + 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), + array('Test fo', 'Test foo bar', 7), + array('Test', 'Test foo bar', 4), + array('Test foo bar', 'Test foo bar', 12, '...'), + array('Test foo...', 'Test foo bar', 11, '...'), + array('Test ...', 'Test foo bar', 8, '...'), + array('Test...', 'Test foo bar', 7, '...'), + array('T...', 'Test foo bar', 4, '...'), + array('Test fo....', 'Test foo bar', 11, '....'), + array('Test fòô bàř', 'Test fòô bàř', 12, '', 'UTF-8'), + array('Test fòô bà', 'Test fòô bàř', 11, '', 'UTF-8'), + array('Test fòô', 'Test fòô bàř', 8, '', 'UTF-8'), + array('Test fò', 'Test fòô bàř', 7, '', 'UTF-8'), + array('Test', 'Test fòô bàř', 4, '', 'UTF-8'), + array('Test fòô bàř', 'Test fòô bàř', 12, 'ϰϰ', 'UTF-8'), + array('Test fòô ϰϰ', 'Test fòô bàř', 11, 'ϰϰ', 'UTF-8'), + array('Test fϰϰ', 'Test fòô bàř', 8, 'ϰϰ', 'UTF-8'), + array('Test ϰϰ', 'Test fòô bàř', 7, 'ϰϰ', 'UTF-8'), + array('Teϰϰ', 'Test fòô bàř', 4, 'ϰϰ', 'UTF-8'), + array('What are your pl...', 'What are your plans today?', 19, '...') + ); + } + /** * @dataProvider safeTruncateProvider() */ @@ -588,6 +1166,34 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function safeTruncateProvider() + { + return array( + array('Test foo bar', 'Test foo bar', 12), + array('Test foo', 'Test foo bar', 11), + array('Test foo', 'Test foo bar', 8), + array('Test', 'Test foo bar', 7), + array('Test', 'Test foo bar', 4), + array('Test foo bar', 'Test foo bar', 12, '...'), + array('Test foo...', 'Test foo bar', 11, '...'), + array('Test...', 'Test foo bar', 8, '...'), + array('Test...', 'Test foo bar', 7, '...'), + array('...', 'Test foo bar', 4, '...'), + array('Test....', 'Test foo bar', 11, '....'), + array('Test fòô bàř', 'Test fòô bàř', 12, '', 'UTF-8'), + array('Test fòô', 'Test fòô bàř', 11, '', 'UTF-8'), + array('Test fòô', 'Test fòô bàř', 8, '', 'UTF-8'), + array('Test', 'Test fòô bàř', 7, '', 'UTF-8'), + array('Test', 'Test fòô bàř', 4, '', 'UTF-8'), + array('Test fòô bàř', 'Test fòô bàř', 12, 'ϰϰ', 'UTF-8'), + array('Test fòôϰϰ', 'Test fòô bàř', 11, 'ϰϰ', 'UTF-8'), + array('Testϰϰ', 'Test fòô bàř', 8, 'ϰϰ', 'UTF-8'), + array('Testϰϰ', 'Test fòô bàř', 7, 'ϰϰ', 'UTF-8'), + array('ϰϰ', 'Test fòô bàř', 4, 'ϰϰ', 'UTF-8'), + array('What are your plans...', 'What are your plans today?', 22, '...') + ); + } + /** * @dataProvider reverseProvider() */ @@ -600,6 +1206,17 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function reverseProvider() + { + return array( + array('', ''), + array('raboof', 'foobar'), + array('řàbôòf', 'fòôbàř', 'UTF-8'), + array('řàb ôòf', 'fòô bàř', 'UTF-8'), + array('∂∆ ˚åß', 'ßå˚ ∆∂', 'UTF-8') + ); + } + /** * @dataProvider shuffleProvider() */ @@ -623,6 +1240,15 @@ class StringyTestCase extends CommonTest } } + public function shuffleProvider() + { + return array( + array('foo bar'), + array('∂∆ ˚åß', 'UTF-8'), + array('å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'UTF-8') + ); + } + /** * @dataProvider trimProvider() */ @@ -635,6 +1261,24 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function trimProvider() + { + return array( + array('foo bar', ' foo bar '), + array('foo bar', ' foo bar'), + array('foo bar', 'foo bar '), + array('foo bar', "\n\t foo bar \n\t"), + array('fòô bàř', ' fòô bàř '), + array('fòô bàř', ' fòô bàř'), + array('fòô bàř', 'fòô bàř '), + array(' foo bar ', "\n\t foo bar \n\t", "\n\t"), + array('fòô bàř', "\n\t fòô bàř \n\t", null, 'UTF-8'), + array('fòô', ' fòô ', null, 'UTF-8'), // narrow no-break space (U+202F) + array('fòô', '  fòô  ', null, 'UTF-8'), // medium mathematical space (U+205F) + array('fòô', '           fòô', null, 'UTF-8') // spaces U+2000 to U+200A + ); + } + /** * @dataProvider trimLeftProvider() */ @@ -648,6 +1292,25 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function trimLeftProvider() + { + return array( + array('foo bar ', ' foo bar '), + array('foo bar', ' foo bar'), + array('foo bar ', 'foo bar '), + array("foo bar \n\t", "\n\t foo bar \n\t"), + array('fòô bàř ', ' fòô bàř '), + array('fòô bàř', ' fòô bàř'), + array('fòô bàř ', 'fòô bàř '), + array('foo bar', '--foo bar', '-'), + array('fòô bàř', 'òòfòô bàř', 'ò', 'UTF-8'), + array("fòô bàř \n\t", "\n\t fòô bàř \n\t", null, 'UTF-8'), + array('fòô ', ' fòô ', null, 'UTF-8'), // narrow no-break space (U+202F) + array('fòô  ', '  fòô  ', null, 'UTF-8'), // medium mathematical space (U+205F) + array('fòô', '           fòô', null, 'UTF-8') // spaces U+2000 to U+200A + ); + } + /** * @dataProvider trimRightProvider() */ @@ -661,6 +1324,25 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function trimRightProvider() + { + return array( + array(' foo bar', ' foo bar '), + array('foo bar', 'foo bar '), + array(' foo bar', ' foo bar'), + array("\n\t foo bar", "\n\t foo bar \n\t"), + array(' fòô bàř', ' fòô bàř '), + array('fòô bàř', 'fòô bàř '), + array(' fòô bàř', ' fòô bàř'), + array('foo bar', 'foo bar--', '-'), + array('fòô bàř', 'fòô bàřòò', 'ò', 'UTF-8'), + array("\n\t fòô bàř", "\n\t fòô bàř \n\t", null, 'UTF-8'), + array(' fòô', ' fòô ', null, 'UTF-8'), // narrow no-break space (U+202F) + array('  fòô', '  fòô  ', null, 'UTF-8'), // medium mathematical space (U+205F) + array('fòô', 'fòô           ', null, 'UTF-8') // spaces U+2000 to U+200A + ); + } + /** * @dataProvider longestCommonPrefixProvider() */ @@ -674,6 +1356,22 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function longestCommonPrefixProvider() + { + return array( + array('foo', 'foobar', 'foo bar'), + array('foo bar', 'foo bar', 'foo bar'), + array('f', 'foo bar', 'far boo'), + array('', 'toy car', 'foo bar'), + array('', 'foo bar', ''), + array('fòô', 'fòôbar', 'fòô bar', 'UTF-8'), + array('fòô bar', 'fòô bar', 'fòô bar', 'UTF-8'), + array('fò', 'fòô bar', 'fòr bar', 'UTF-8'), + array('', 'toy car', 'fòô bar', 'UTF-8'), + array('', 'fòô bar', '', 'UTF-8'), + ); + } + /** * @dataProvider longestCommonSuffixProvider() */ @@ -687,6 +1385,22 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function longestCommonSuffixProvider() + { + return array( + array('bar', 'foobar', 'foo bar'), + array('foo bar', 'foo bar', 'foo bar'), + array('ar', 'foo bar', 'boo far'), + array('', 'foo bad', 'foo bar'), + array('', 'foo bar', ''), + array('bàř', 'fòôbàř', 'fòô bàř', 'UTF-8'), + array('fòô bàř', 'fòô bàř', 'fòô bàř', 'UTF-8'), + array(' bàř', 'fòô bàř', 'fòr bàř', 'UTF-8'), + array('', 'toy car', 'fòô bàř', 'UTF-8'), + array('', 'fòô bàř', '', 'UTF-8'), + ); + } + /** * @dataProvider longestCommonSubstringProvider() */ @@ -700,6 +1414,22 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function longestCommonSubstringProvider() + { + return array( + array('foo', 'foobar', 'foo bar'), + array('foo bar', 'foo bar', 'foo bar'), + array('oo ', 'foo bar', 'boo far'), + array('foo ba', 'foo bad', 'foo bar'), + array('', 'foo bar', ''), + array('fòô', 'fòôbàř', 'fòô bàř', 'UTF-8'), + array('fòô bàř', 'fòô bàř', 'fòô bàř', 'UTF-8'), + array(' bàř', 'fòô bàř', 'fòr bàř', 'UTF-8'), + array(' ', 'toy car', 'fòô bàř', 'UTF-8'), + array('', 'fòô bàř', '', 'UTF-8'), + ); + } + /** * @dataProvider lengthProvider() */ @@ -712,6 +1442,16 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function lengthProvider() + { + return array( + array(11, ' foo bar '), + array(1, 'f'), + array(0, ''), + array(7, 'fòô bàř', 'UTF-8') + ); + } + /** * @dataProvider substrProvider() */ @@ -725,6 +1465,21 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function substrProvider() + { + return array( + array('foo bar', 'foo bar', 0), + array('bar', 'foo bar', 4), + array('bar', 'foo bar', 4, null), + array('o b', 'foo bar', 2, 3), + array('', 'foo bar', 4, 0), + array('fòô bàř', 'fòô bàř', 0, null, 'UTF-8'), + array('bàř', 'fòô bàř', 4, null, 'UTF-8'), + array('ô b', 'fòô bàř', 2, 3, 'UTF-8'), + array('', 'fòô bàř', 4, 0, 'UTF-8') + ); + } + /** * @dataProvider atProvider() */ @@ -737,6 +1492,20 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function atProvider() + { + return array( + array('f', 'foo bar', 0), + array('o', 'foo bar', 1), + array('r', 'foo bar', 6), + array('', 'foo bar', 7), + array('f', 'fòô bàř', 0, 'UTF-8'), + array('ò', 'fòô bàř', 1, 'UTF-8'), + array('ř', 'fòô bàř', 6, 'UTF-8'), + array('', 'fòô bàř', 7, 'UTF-8'), + ); + } + /** * @dataProvider firstProvider() */ @@ -749,6 +1518,24 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function firstProvider() + { + return array( + array('', 'foo bar', -5), + array('', 'foo bar', 0), + array('f', 'foo bar', 1), + array('foo', 'foo bar', 3), + array('foo bar', 'foo bar', 7), + array('foo bar', 'foo bar', 8), + array('', 'fòô bàř', -5, 'UTF-8'), + array('', 'fòô bàř', 0, 'UTF-8'), + array('f', 'fòô bàř', 1, 'UTF-8'), + array('fòô', 'fòô bàř', 3, 'UTF-8'), + array('fòô bàř', 'fòô bàř', 7, 'UTF-8'), + array('fòô bàř', 'fòô bàř', 8, 'UTF-8'), + ); + } + /** * @dataProvider lastProvider() */ @@ -761,6 +1548,24 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function lastProvider() + { + return array( + array('', 'foo bar', -5), + array('', 'foo bar', 0), + array('r', 'foo bar', 1), + array('bar', 'foo bar', 3), + array('foo bar', 'foo bar', 7), + array('foo bar', 'foo bar', 8), + array('', 'fòô bàř', -5, 'UTF-8'), + array('', 'fòô bàř', 0, 'UTF-8'), + array('ř', 'fòô bàř', 1, 'UTF-8'), + array('bàř', 'fòô bàř', 3, 'UTF-8'), + array('fòô bàř', 'fòô bàř', 7, 'UTF-8'), + array('fòô bàř', 'fòô bàř', 8, 'UTF-8'), + ); + } + /** * @dataProvider ensureLeftProvider() */ @@ -773,6 +1578,22 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function ensureLeftProvider() + { + return array( + array('foobar', 'foobar', 'f'), + array('foobar', 'foobar', 'foo'), + array('foo/foobar', 'foobar', 'foo/'), + array('http://foobar', 'foobar', 'http://'), + array('http://foobar', 'http://foobar', 'http://'), + array('fòôbàř', 'fòôbàř', 'f', 'UTF-8'), + array('fòôbàř', 'fòôbàř', 'fòô', 'UTF-8'), + array('fòô/fòôbàř', 'fòôbàř', 'fòô/', 'UTF-8'), + array('http://fòôbàř', 'fòôbàř', 'http://', 'UTF-8'), + array('http://fòôbàř', 'http://fòôbàř', 'http://', 'UTF-8'), + ); + } + /** * @dataProvider ensureRightProvider() */ @@ -785,6 +1606,22 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function ensureRightProvider() + { + return array( + array('foobar', 'foobar', 'r'), + array('foobar', 'foobar', 'bar'), + array('foobar/bar', 'foobar', '/bar'), + array('foobar.com/', 'foobar', '.com/'), + array('foobar.com/', 'foobar.com/', '.com/'), + array('fòôbàř', 'fòôbàř', 'ř', 'UTF-8'), + array('fòôbàř', 'fòôbàř', 'bàř', 'UTF-8'), + array('fòôbàř/bàř', 'fòôbàř', '/bàř', 'UTF-8'), + array('fòôbàř.com/', 'fòôbàř', '.com/', 'UTF-8'), + array('fòôbàř.com/', 'fòôbàř.com/', '.com/', 'UTF-8'), + ); + } + /** * @dataProvider removeLeftProvider() */ @@ -797,6 +1634,24 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function removeLeftProvider() + { + return array( + array('foo bar', 'foo bar', ''), + array('oo bar', 'foo bar', 'f'), + array('bar', 'foo bar', 'foo '), + array('foo bar', 'foo bar', 'oo'), + array('foo bar', 'foo bar', 'oo bar'), + array('oo bar', 'foo bar', S::create('foo bar')->first(1), 'UTF-8'), + array('oo bar', 'foo bar', S::create('foo bar')->at(0), 'UTF-8'), + array('fòô bàř', 'fòô bàř', '', 'UTF-8'), + array('òô bàř', 'fòô bàř', 'f', 'UTF-8'), + array('bàř', 'fòô bàř', 'fòô ', 'UTF-8'), + array('fòô bàř', 'fòô bàř', 'òô', 'UTF-8'), + array('fòô bàř', 'fòô bàř', 'òô bàř', 'UTF-8') + ); + } + /** * @dataProvider removeRightProvider() */ @@ -809,6 +1664,24 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function removeRightProvider() + { + return array( + array('foo bar', 'foo bar', ''), + array('foo ba', 'foo bar', 'r'), + array('foo', 'foo bar', ' bar'), + array('foo bar', 'foo bar', 'ba'), + array('foo bar', 'foo bar', 'foo ba'), + array('foo ba', 'foo bar', S::create('foo bar')->last(1), 'UTF-8'), + array('foo ba', 'foo bar', S::create('foo bar')->at(6), 'UTF-8'), + array('fòô bàř', 'fòô bàř', '', 'UTF-8'), + array('fòô bà', 'fòô bàř', 'ř', 'UTF-8'), + array('fòô', 'fòô bàř', ' bàř', 'UTF-8'), + array('fòô bàř', 'fòô bàř', 'bà', 'UTF-8'), + array('fòô bàř', 'fòô bàř', 'fòô bà', 'UTF-8') + ); + } + /** * @dataProvider isAlphaProvider() */ @@ -821,6 +1694,22 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function isAlphaProvider() + { + return array( + array(true, ''), + array(true, 'foobar'), + array(false, 'foo bar'), + array(false, 'foobar2'), + array(true, 'fòôbàř', 'UTF-8'), + array(false, 'fòô bàř', 'UTF-8'), + array(false, 'fòôbàř2', 'UTF-8'), + array(true, 'ҠѨњфгШ', 'UTF-8'), + array(false, 'ҠѨњ¨ˆфгШ', 'UTF-8'), + array(true, '丹尼爾', 'UTF-8') + ); + } + /** * @dataProvider isAlphanumericProvider() */ @@ -833,6 +1722,25 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function isAlphanumericProvider() + { + return array( + array(true, ''), + array(true, 'foobar1'), + array(false, 'foo bar'), + array(false, 'foobar2"'), + array(false, "\nfoobar\n"), + array(true, 'fòôbàř1', 'UTF-8'), + array(false, 'fòô bàř', 'UTF-8'), + array(false, 'fòôbàř2"', 'UTF-8'), + array(true, 'ҠѨњфгШ', 'UTF-8'), + array(false, 'ҠѨњ¨ˆфгШ', 'UTF-8'), + array(true, '丹尼爾111', 'UTF-8'), + array(true, 'دانيال1', 'UTF-8'), + array(false, 'دانيال1 ', 'UTF-8') + ); + } + /** * @dataProvider isBlankProvider() */ @@ -845,6 +1753,27 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function isBlankProvider() + { + return array( + array(true, ''), + array(true, ' '), + array(true, "\n\t "), + array(true, "\n\t \v\f"), + array(false, "\n\t a \v\f"), + array(false, "\n\t ' \v\f"), + array(false, "\n\t 2 \v\f"), + array(true, '', 'UTF-8'), + array(true, ' ', 'UTF-8'), // no-break space (U+00A0) + array(true, '           ', 'UTF-8'), // spaces U+2000 to U+200A + array(true, ' ', 'UTF-8'), // narrow no-break space (U+202F) + array(true, ' ', 'UTF-8'), // medium mathematical space (U+205F) + array(true, ' ', 'UTF-8'), // ideographic space (U+3000) + array(false, ' z', 'UTF-8'), + array(false, ' 1', 'UTF-8'), + ); + } + /** * @dataProvider isJsonProvider() */ @@ -857,6 +1786,26 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function isJsonProvider() + { + return array( + array(true, ''), + array(true, '123'), + array(true, '{"foo": "bar"}'), + array(false, '{"foo":"bar",}'), + array(false, '{"foo"}'), + array(true, '["foo"]'), + array(false, '{"foo": "bar"]'), + array(true, '123', 'UTF-8'), + array(true, '{"fòô": "bàř"}', 'UTF-8'), + array(false, '{"fòô":"bàř",}', 'UTF-8'), + array(false, '{"fòô"}', 'UTF-8'), + array(false, '["fòô": "bàř"]', 'UTF-8'), + array(true, '["fòô"]', 'UTF-8'), + array(false, '{"fòô": "bàř"]', 'UTF-8'), + ); + } + /** * @dataProvider isLowerCaseProvider() */ @@ -869,6 +1818,20 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function isLowerCaseProvider() + { + return array( + array(true, ''), + array(true, 'foobar'), + array(false, 'foo bar'), + array(false, 'Foobar'), + array(true, 'fòôbàř', 'UTF-8'), + array(false, 'fòôbàř2', 'UTF-8'), + array(false, 'fòô bàř', 'UTF-8'), + array(false, 'fòôbÀŘ', 'UTF-8'), + ); + } + /** * @dataProvider hasLowerCaseProvider() */ @@ -881,6 +1844,24 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function hasLowerCaseProvider() + { + return array( + array(false, ''), + array(true, 'foobar'), + array(false, 'FOO BAR'), + array(true, 'fOO BAR'), + array(true, 'foO BAR'), + array(true, 'FOO BAr'), + array(true, 'Foobar'), + array(false, 'FÒÔBÀŘ', 'UTF-8'), + array(true, 'fòôbàř', 'UTF-8'), + array(true, 'fòôbàř2', 'UTF-8'), + array(true, 'Fòô bàř', 'UTF-8'), + array(true, 'fòôbÀŘ', 'UTF-8'), + ); + } + /** * @dataProvider isSerializedProvider() */ @@ -893,6 +1874,19 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function isSerializedProvider() + { + return array( + array(false, ''), + array(true, 'a:1:{s:3:"foo";s:3:"bar";}'), + array(false, 'a:1:{s:3:"foo";s:3:"bar"}'), + array(true, serialize(array('foo' => 'bar'))), + array(true, 'a:1:{s:5:"fòô";s:5:"bàř";}', 'UTF-8'), + array(false, 'a:1:{s:5:"fòô";s:5:"bàř"}', 'UTF-8'), + array(true, serialize(array('fòô' => 'bár')), 'UTF-8'), + ); + } + /** * @dataProvider isUpperCaseProvider() */ @@ -905,6 +1899,20 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function isUpperCaseProvider() + { + return array( + array(true, ''), + array(true, 'FOOBAR'), + array(false, 'FOO BAR'), + array(false, 'fOOBAR'), + array(true, 'FÒÔBÀŘ', 'UTF-8'), + array(false, 'FÒÔBÀŘ2', 'UTF-8'), + array(false, 'FÒÔ BÀŘ', 'UTF-8'), + array(false, 'FÒÔBàř', 'UTF-8'), + ); + } + /** * @dataProvider hasUpperCaseProvider() */ @@ -917,6 +1925,24 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function hasUpperCaseProvider() + { + return array( + array(false, ''), + array(true, 'FOOBAR'), + array(false, 'foo bar'), + array(true, 'Foo bar'), + array(true, 'FOo bar'), + array(true, 'foo baR'), + array(true, 'fOOBAR'), + array(false, 'fòôbàř', 'UTF-8'), + array(true, 'FÒÔBÀŘ', 'UTF-8'), + array(true, 'FÒÔBÀŘ2', 'UTF-8'), + array(true, 'fÒÔ BÀŘ', 'UTF-8'), + array(true, 'FÒÔBàř', 'UTF-8'), + ); + } + /** * @dataProvider isHexadecimalProvider() */ @@ -929,6 +1955,25 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function isHexadecimalProvider() + { + return array( + array(true, ''), + array(true, 'abcdef'), + array(true, 'ABCDEF'), + array(true, '0123456789'), + array(true, '0123456789AbCdEf'), + array(false, '0123456789x'), + array(false, 'ABCDEFx'), + array(true, 'abcdef', 'UTF-8'), + array(true, 'ABCDEF', 'UTF-8'), + array(true, '0123456789', 'UTF-8'), + array(true, '0123456789AbCdEf', 'UTF-8'), + array(false, '0123456789x', 'UTF-8'), + array(false, 'ABCDEFx', 'UTF-8'), + ); + } + /** * @dataProvider countSubstrProvider() */ @@ -942,6 +1987,27 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function countSubstrProvider() + { + return array( + array(0, '', 'foo'), + array(0, 'foo', 'bar'), + array(1, 'foo bar', 'foo'), + array(2, 'foo bar', 'o'), + 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(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') + ); + } + /** * @dataProvider replaceProvider() */ @@ -955,6 +2021,28 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function replaceProvider() + { + return array( + array('', '', '', ''), + array('foo', '', '', 'foo'), + array('foo', '\s', '\s', 'foo'), + array('foo bar', 'foo bar', '', ''), + array('foo bar', 'foo bar', 'f(o)o', '\1'), + array('\1 bar', 'foo bar', 'foo', '\1'), + 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'), + ); + } + /** * @dataProvider regexReplaceProvider() */ @@ -968,6 +2056,20 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function regexReplaceProvider() + { + return array( + array('', '', '', ''), + array('bar', 'foo', 'f[o]+', 'bar'), + array('o bar', 'foo bar', 'f(o)o', '\1'), + 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') + ); + } + /** * @dataProvider htmlEncodeProvider() */ @@ -980,6 +2082,17 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + public function htmlEncodeProvider() + { + return array( + array('&', '&'), + array('"', '"'), + array(''', "'", ENT_QUOTES), + array('<', '<'), + array('>', '>'), + ); + } + /** * @dataProvider htmlDecodeProvider() */ @@ -991,4 +2104,15 @@ class StringyTestCase extends CommonTest $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } + + public function htmlDecodeProvider() + { + return array( + array('&', '&'), + array('"', '"'), + array("'", ''', ENT_QUOTES), + array('<', '<'), + array('>', '>'), + ); + } }