mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-08-12 00:04:11 +02:00
Move curly braces and remove closing tags to accommodate PSR-1 and PSR-2
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace Stringy;
|
||||
|
||||
class Stringy {
|
||||
|
||||
class Stringy
|
||||
{
|
||||
/**
|
||||
* Converts the first character of the supplied string to upper case.
|
||||
*
|
||||
@@ -11,7 +11,8 @@ class Stringy {
|
||||
* @param string $encoding The character encoding
|
||||
* @return string String with the first character being upper case
|
||||
*/
|
||||
public static function upperCaseFirst($str, $encoding = null) {
|
||||
public static function upperCaseFirst($str, $encoding = null)
|
||||
{
|
||||
$encoding = $encoding ?: mb_internal_encoding();
|
||||
|
||||
$first = mb_substr($str, 0, 1, $encoding);
|
||||
@@ -27,7 +28,8 @@ class Stringy {
|
||||
* @param string $encoding The character encoding
|
||||
* @return string String with the first character being lower case
|
||||
*/
|
||||
public static function lowerCaseFirst($str, $encoding = null) {
|
||||
public static function lowerCaseFirst($str, $encoding = null)
|
||||
{
|
||||
$encoding = $encoding ?: mb_internal_encoding();
|
||||
|
||||
$first = mb_substr($str, 0, 1, $encoding);
|
||||
@@ -45,7 +47,8 @@ class Stringy {
|
||||
* @param string $encoding The character encoding
|
||||
* @return string String in camelCase
|
||||
*/
|
||||
public static function camelize($str, $encoding = null) {
|
||||
public static function camelize($str, $encoding = null)
|
||||
{
|
||||
$encoding = $encoding ?: mb_internal_encoding();
|
||||
|
||||
$camelCase = preg_replace_callback(
|
||||
@@ -76,7 +79,8 @@ class Stringy {
|
||||
* @param string $encoding The character encoding
|
||||
* @return string String in UpperCamelCase
|
||||
*/
|
||||
public static function upperCamelize($str, $encoding = null) {
|
||||
public static function upperCamelize($str, $encoding = null)
|
||||
{
|
||||
$encoding = $encoding ?: mb_internal_encoding();
|
||||
$camelCase = self::camelize($str, $encoding);
|
||||
|
||||
@@ -92,7 +96,8 @@ class Stringy {
|
||||
* @param string $encoding The character encoding
|
||||
* @return string Dasherized string
|
||||
*/
|
||||
public static function dasherize($str, $encoding = null) {
|
||||
public static function dasherize($str, $encoding = null)
|
||||
{
|
||||
$encoding = $encoding ?: mb_internal_encoding();
|
||||
mb_regex_encoding($encoding);
|
||||
|
||||
@@ -112,7 +117,8 @@ class Stringy {
|
||||
* @param string $encoding The character encoding
|
||||
* @return string Underscored string
|
||||
*/
|
||||
public static function underscored($str, $encoding = null) {
|
||||
public static function underscored($str, $encoding = null)
|
||||
{
|
||||
$encoding = $encoding ?: mb_internal_encoding();
|
||||
mb_regex_encoding($encoding);
|
||||
|
||||
@@ -129,7 +135,8 @@ class Stringy {
|
||||
* @param string $encoding The character encoding
|
||||
* @return string String with each character's case swapped
|
||||
*/
|
||||
public static function swapCase($str, $encoding = null) {
|
||||
public static function swapCase($str, $encoding = null)
|
||||
{
|
||||
$encoding = $encoding ?: mb_internal_encoding();
|
||||
|
||||
$swapped = preg_replace_callback(
|
||||
@@ -157,7 +164,8 @@ class Stringy {
|
||||
* @param array $ignore An array of words not to capitalize
|
||||
* @return string Titleized string
|
||||
*/
|
||||
public static function titleize($str, $ignore = null, $encoding = null) {
|
||||
public static function titleize($str, $ignore = null, $encoding = null)
|
||||
{
|
||||
$encoding = $encoding ?: mb_internal_encoding();
|
||||
|
||||
$titleized = preg_replace_callback(
|
||||
@@ -181,7 +189,8 @@ class Stringy {
|
||||
* @param string $encoding The character encoding
|
||||
* @return string A humanized string
|
||||
*/
|
||||
public static function humanize($str, $encoding = null) {
|
||||
public static function humanize($str, $encoding = null)
|
||||
{
|
||||
$humanized = str_replace('_id', '', $str);
|
||||
$humanized = str_replace('_', ' ', $humanized);
|
||||
|
||||
@@ -196,7 +205,8 @@ class Stringy {
|
||||
* @param string $encoding The character encoding
|
||||
* @return string String with those characters removed
|
||||
*/
|
||||
public static function tidy($str) {
|
||||
public static function tidy($str)
|
||||
{
|
||||
$tidied = preg_replace('/\x{2026}/u', '...', $str);
|
||||
$tidied = preg_replace('/[\x{201C}\x{201D}]/u', '"', $tidied);
|
||||
$tidied = preg_replace('/[\x{2018}\x{2019}]/u', "'", $tidied);
|
||||
@@ -212,7 +222,8 @@ class Stringy {
|
||||
* @param string $str The string to cleanup whitespace
|
||||
* @return string The trimmed string with condensed whitespace
|
||||
*/
|
||||
public static function clean($str) {
|
||||
public static function clean($str)
|
||||
{
|
||||
return preg_replace('/\s+/u', ' ', trim($str));
|
||||
}
|
||||
|
||||
@@ -222,7 +233,8 @@ class Stringy {
|
||||
* @param string $str A string with non-ASCII characters
|
||||
* @return string The string after the replacements
|
||||
*/
|
||||
public static function standardize($str) {
|
||||
public static function standardize($str)
|
||||
{
|
||||
$charsArray = array(
|
||||
'a' => array('à', 'á', 'â', 'ã', 'ă', 'ä', 'å', 'ą'),
|
||||
'c' => array('ć', 'č', 'ç'),
|
||||
@@ -279,7 +291,8 @@ class Stringy {
|
||||
* 'left' or 'both'
|
||||
*/
|
||||
public static function pad($str, $length, $padStr = ' ', $padType = 'right',
|
||||
$encoding = null) {
|
||||
$encoding = null)
|
||||
{
|
||||
$encoding = $encoding ?: mb_internal_encoding();
|
||||
|
||||
if (!in_array($padType, array('left', 'right', 'both'))) {
|
||||
@@ -334,7 +347,8 @@ class Stringy {
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The padded string
|
||||
*/
|
||||
public static function padLeft($str, $length, $padStr = ' ', $encoding = null) {
|
||||
public static function padLeft($str, $length, $padStr = ' ', $encoding = null)
|
||||
{
|
||||
return self::pad($str, $length, $padStr, 'left', $encoding);
|
||||
}
|
||||
|
||||
@@ -348,7 +362,8 @@ class Stringy {
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The padded string
|
||||
*/
|
||||
public static function padRight($str, $length, $padStr = ' ', $encoding = null) {
|
||||
public static function padRight($str, $length, $padStr = ' ', $encoding = null)
|
||||
{
|
||||
return self::pad($str, $length, $padStr, 'right', $encoding);
|
||||
}
|
||||
|
||||
@@ -362,7 +377,8 @@ class Stringy {
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The padded string
|
||||
*/
|
||||
public static function padBoth($str, $length, $padStr = ' ', $encoding = null) {
|
||||
public static function padBoth($str, $length, $padStr = ' ', $encoding = null)
|
||||
{
|
||||
return self::pad($str, $length, $padStr, 'both', $encoding);
|
||||
}
|
||||
|
||||
@@ -378,7 +394,8 @@ class Stringy {
|
||||
* @return bool Whether or not $str starts with $substring
|
||||
*/
|
||||
public static function startsWith($str, $substring, $caseSensitive = true,
|
||||
$encoding = null) {
|
||||
$encoding = null)
|
||||
{
|
||||
$encoding = $encoding ?: mb_internal_encoding();
|
||||
|
||||
$substringLength = mb_strlen($substring, $encoding);
|
||||
@@ -404,7 +421,8 @@ class Stringy {
|
||||
* @return bool Whether or not $str ends with $substring
|
||||
*/
|
||||
public static function endsWith($str, $substring, $caseSensitive = true,
|
||||
$encoding = null) {
|
||||
$encoding = null)
|
||||
{
|
||||
$encoding = $encoding ?: mb_internal_encoding();
|
||||
|
||||
$substringLength = mb_strlen($substring, $encoding);
|
||||
@@ -429,7 +447,8 @@ class Stringy {
|
||||
* @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) {
|
||||
public static function toSpaces($str, $tabLength = 4)
|
||||
{
|
||||
$spaces = str_repeat(' ', $tabLength);
|
||||
|
||||
return str_replace("\t", $spaces, $str);
|
||||
@@ -444,7 +463,8 @@ class Stringy {
|
||||
* @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) {
|
||||
public static function toTabs($str, $tabLength = 4)
|
||||
{
|
||||
$spaces = str_repeat(' ', $tabLength);
|
||||
|
||||
return str_replace($spaces, "\t", $str);
|
||||
@@ -459,7 +479,8 @@ class Stringy {
|
||||
* @param string $str Text to transform into an URL slug
|
||||
* @return string The corresponding URL slug
|
||||
*/
|
||||
public static function slugify($str) {
|
||||
public static function slugify($str)
|
||||
{
|
||||
$str = preg_replace('/[^a-zA-Z\d -]/u', '', self::standardize($str));
|
||||
$str = self::clean($str);
|
||||
|
||||
@@ -474,7 +495,8 @@ class Stringy {
|
||||
* @param string $encoding The character encoding
|
||||
* @return bool Whether or not $haystack contains $needle
|
||||
*/
|
||||
public static function contains($haystack, $needle, $encoding = null) {
|
||||
public static function contains($haystack, $needle, $encoding = null)
|
||||
{
|
||||
$encoding = $encoding ?: mb_internal_encoding();
|
||||
|
||||
if (mb_strpos($haystack, $needle, 0, $encoding) !== false)
|
||||
@@ -490,7 +512,8 @@ class Stringy {
|
||||
* @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) {
|
||||
public static function surround($str, $substring)
|
||||
{
|
||||
return implode('', array($substring, $str, $substring));
|
||||
}
|
||||
|
||||
@@ -503,7 +526,8 @@ class Stringy {
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The resulting string after the insertion
|
||||
*/
|
||||
public static function insert($str, $substring, $index, $encoding = null) {
|
||||
public static function insert($str, $substring, $index, $encoding = null)
|
||||
{
|
||||
$encoding = $encoding ?: mb_internal_encoding();
|
||||
|
||||
if ($index > mb_strlen($str, $encoding))
|
||||
@@ -528,7 +552,8 @@ class Stringy {
|
||||
* @return string The resulting string after truncating
|
||||
*/
|
||||
public static function truncate($str, $length, $substring = '',
|
||||
$encoding = null) {
|
||||
$encoding = null)
|
||||
{
|
||||
$encoding = $encoding ?: mb_internal_encoding();
|
||||
|
||||
if ($length >= mb_strlen($str, $encoding))
|
||||
@@ -557,7 +582,8 @@ class Stringy {
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The reversed string
|
||||
*/
|
||||
public static function reverse($str, $encoding = null) {
|
||||
public static function reverse($str, $encoding = null)
|
||||
{
|
||||
$encoding = $encoding ?: mb_internal_encoding();
|
||||
|
||||
$strLength = mb_strlen($str, $encoding);
|
||||
@@ -579,7 +605,8 @@ class Stringy {
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The shuffled string
|
||||
*/
|
||||
public static function shuffle($str, $encoding = null) {
|
||||
public static function shuffle($str, $encoding = null)
|
||||
{
|
||||
$encoding = $encoding ?: mb_internal_encoding();
|
||||
|
||||
$indexes = range(0, mb_strlen($str, $encoding) - 1);
|
||||
@@ -592,7 +619,4 @@ class Stringy {
|
||||
|
||||
return $shuffledStr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -5,17 +5,19 @@ require("$base/src/Stringy/Stringy.php");
|
||||
|
||||
use Stringy\Stringy as S;
|
||||
|
||||
class StringyTestCase extends PHPUnit_Framework_TestCase {
|
||||
|
||||
class StringyTestCase extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider stringsForUpperCaseFirst
|
||||
*/
|
||||
public function testUpperCaseFirst($expected, $string, $encoding = null) {
|
||||
public function testUpperCaseFirst($expected, $string, $encoding = null)
|
||||
{
|
||||
$result = S::upperCaseFirst($string, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function stringsForUpperCaseFirst() {
|
||||
public function stringsForUpperCaseFirst()
|
||||
{
|
||||
$testData = array(
|
||||
array('Test', 'Test'),
|
||||
array('Test', 'test'),
|
||||
@@ -30,12 +32,14 @@ class StringyTestCase extends PHPUnit_Framework_TestCase {
|
||||
/**
|
||||
* @dataProvider stringsForLowerCaseFirst
|
||||
*/
|
||||
public function testLowerCaseFirst($expected, $string, $encoding = null) {
|
||||
public function testLowerCaseFirst($expected, $string, $encoding = null)
|
||||
{
|
||||
$result = S::lowerCaseFirst($string, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function stringsForLowerCaseFirst() {
|
||||
public function stringsForLowerCaseFirst()
|
||||
{
|
||||
$testData = array(
|
||||
array('test', 'Test'),
|
||||
array('test', 'test'),
|
||||
@@ -50,12 +54,14 @@ class StringyTestCase extends PHPUnit_Framework_TestCase {
|
||||
/**
|
||||
* @dataProvider stringsForCamelize
|
||||
*/
|
||||
public function testCamelize($expected, $string, $encoding = null) {
|
||||
public function testCamelize($expected, $string, $encoding = null)
|
||||
{
|
||||
$result = S::camelize($string, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function stringsForCamelize() {
|
||||
public function stringsForCamelize()
|
||||
{
|
||||
$testData = array(
|
||||
array('camelCase', 'CamelCase'),
|
||||
array('camelCase', 'Camel-Case'),
|
||||
@@ -78,12 +84,14 @@ class StringyTestCase extends PHPUnit_Framework_TestCase {
|
||||
/**
|
||||
* @dataProvider stringsForUpperCamelize
|
||||
*/
|
||||
public function testUpperCamelize($expected, $string, $encoding = null) {
|
||||
public function testUpperCamelize($expected, $string, $encoding = null)
|
||||
{
|
||||
$result = S::upperCamelize($string, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function stringsForUpperCamelize() {
|
||||
public function stringsForUpperCamelize()
|
||||
{
|
||||
$testData = array(
|
||||
array('CamelCase', 'camelCase'),
|
||||
array('CamelCase', 'Camel-Case'),
|
||||
@@ -106,12 +114,14 @@ class StringyTestCase extends PHPUnit_Framework_TestCase {
|
||||
/**
|
||||
* @dataProvider stringsForDasherize
|
||||
*/
|
||||
public function testDasherize($expected, $string, $encoding = null) {
|
||||
public function testDasherize($expected, $string, $encoding = null)
|
||||
{
|
||||
$result = S::dasherize($string, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function stringsForDasherize() {
|
||||
public function stringsForDasherize()
|
||||
{
|
||||
$testData = array(
|
||||
array('test-case', 'testCase'),
|
||||
array('test-case', 'Test-Case'),
|
||||
@@ -136,12 +146,14 @@ class StringyTestCase extends PHPUnit_Framework_TestCase {
|
||||
/**
|
||||
* @dataProvider stringsForUnderscored
|
||||
*/
|
||||
public function testUnderscored($expected, $string, $encoding = null) {
|
||||
public function testUnderscored($expected, $string, $encoding = null)
|
||||
{
|
||||
$result = S::underscored($string, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function stringsForUnderscored() {
|
||||
public function stringsForUnderscored()
|
||||
{
|
||||
$testData = array(
|
||||
array('test_case', 'testCase'),
|
||||
array('test_case', 'Test-Case'),
|
||||
@@ -166,12 +178,14 @@ class StringyTestCase extends PHPUnit_Framework_TestCase {
|
||||
/**
|
||||
* @dataProvider stringsForSwapCase
|
||||
*/
|
||||
public function testSwapCase($expected, $string, $encoding = null) {
|
||||
public function testSwapCase($expected, $string, $encoding = null)
|
||||
{
|
||||
$result = S::swapCase($string, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function stringsForSwapCase() {
|
||||
public function stringsForSwapCase()
|
||||
{
|
||||
$testData = array(
|
||||
array('TESTcASE', 'testCase'),
|
||||
array('tEST-cASE', 'Test-Case'),
|
||||
@@ -186,12 +200,14 @@ class StringyTestCase extends PHPUnit_Framework_TestCase {
|
||||
* @dataProvider stringsForTitleize
|
||||
*/
|
||||
public function testTitleize($expected, $string, $ignore = null,
|
||||
$encoding = null) {
|
||||
$encoding = null)
|
||||
{
|
||||
$result = S::titleize($string, $ignore, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function stringsForTitleize() {
|
||||
public function stringsForTitleize()
|
||||
{
|
||||
$ignore = array('at', 'by', 'for', 'in', 'of', 'on', 'out', 'to', 'the');
|
||||
|
||||
$testData = array(
|
||||
@@ -208,12 +224,14 @@ class StringyTestCase extends PHPUnit_Framework_TestCase {
|
||||
/**
|
||||
* @dataProvider stringsForHumanize
|
||||
*/
|
||||
public function testHumanize($expected, $string, $encoding = null) {
|
||||
public function testHumanize($expected, $string, $encoding = null)
|
||||
{
|
||||
$result = S::humanize($string, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function stringsForHumanize() {
|
||||
public function stringsForHumanize()
|
||||
{
|
||||
$testData = array(
|
||||
array('Author', 'author_id'),
|
||||
array('Test user', ' _test_user_'),
|
||||
@@ -226,12 +244,14 @@ class StringyTestCase extends PHPUnit_Framework_TestCase {
|
||||
/**
|
||||
* @dataProvider stringsForTidy
|
||||
*/
|
||||
public function testTidy($expected, $string) {
|
||||
public function testTidy($expected, $string)
|
||||
{
|
||||
$result = S::tidy($string);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function stringsForTidy() {
|
||||
public function stringsForTidy()
|
||||
{
|
||||
$testData = array(
|
||||
array('"I see..."', '“I see…”'),
|
||||
array("'This too'", "‘This too’"),
|
||||
@@ -245,12 +265,14 @@ class StringyTestCase extends PHPUnit_Framework_TestCase {
|
||||
/**
|
||||
* @dataProvider stringsForClean
|
||||
*/
|
||||
public function testClean($expected, $string) {
|
||||
public function testClean($expected, $string)
|
||||
{
|
||||
$result = S::clean($string);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function stringsForClean() {
|
||||
public function stringsForClean()
|
||||
{
|
||||
$testData = array(
|
||||
array('foo bar', ' foo bar '),
|
||||
array('test string', 'test string'),
|
||||
@@ -266,12 +288,14 @@ class StringyTestCase extends PHPUnit_Framework_TestCase {
|
||||
/**
|
||||
* @dataProvider stringsForStandardize
|
||||
*/
|
||||
public function testStandardize($expected, $string) {
|
||||
public function testStandardize($expected, $string)
|
||||
{
|
||||
$result = S::standardize($string);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function stringsForStandardize() {
|
||||
public function stringsForStandardize()
|
||||
{
|
||||
$testData = array(
|
||||
array('foo bar', 'fòô bàř'),
|
||||
array(' TEST ', ' ŤÉŚŢ '),
|
||||
@@ -285,12 +309,14 @@ class StringyTestCase extends PHPUnit_Framework_TestCase {
|
||||
* @dataProvider stringsForPad
|
||||
*/
|
||||
public function testPad($expected, $string, $length, $padStr = ' ',
|
||||
$padType = 'right', $encoding = null) {
|
||||
$padType = 'right', $encoding = null)
|
||||
{
|
||||
$result = S::pad($string, $length, $padStr, $padType, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function stringsForPad() {
|
||||
public function stringsForPad()
|
||||
{
|
||||
$testData = array(
|
||||
// $length <= $str
|
||||
array('foo bar', 'foo bar', -1),
|
||||
@@ -336,12 +362,14 @@ class StringyTestCase extends PHPUnit_Framework_TestCase {
|
||||
* @dataProvider stringsForPadLeft
|
||||
*/
|
||||
public function testPadLeft($expected, $string, $length, $padStr = ' ',
|
||||
$encoding = null) {
|
||||
$encoding = null)
|
||||
{
|
||||
$result = S::padLeft($string, $length, $padStr, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function stringsForPadLeft() {
|
||||
public function stringsForPadLeft()
|
||||
{
|
||||
$testData = array(
|
||||
array(' foo bar', 'foo bar', 9),
|
||||
array('_*_foo bar', 'foo bar', 10, '_*'),
|
||||
@@ -355,12 +383,14 @@ class StringyTestCase extends PHPUnit_Framework_TestCase {
|
||||
* @dataProvider stringsForPadRight
|
||||
*/
|
||||
public function testPadRight($expected, $string, $length, $padStr = ' ',
|
||||
$encoding = null) {
|
||||
$encoding = null)
|
||||
{
|
||||
$result = S::padRight($string, $length, $padStr, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function stringsForPadRight() {
|
||||
public function stringsForPadRight()
|
||||
{
|
||||
$testData = array(
|
||||
array('foo bar ', 'foo bar', 9),
|
||||
array('foo bar_*_', 'foo bar', 10, '_*'),
|
||||
@@ -374,12 +404,14 @@ class StringyTestCase extends PHPUnit_Framework_TestCase {
|
||||
* @dataProvider stringsForPadBoth
|
||||
*/
|
||||
public function testPadBoth($expected, $string, $length, $padStr = ' ',
|
||||
$encoding = null) {
|
||||
$encoding = null)
|
||||
{
|
||||
$result = S::padBoth($string, $length, $padStr, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function stringsForPadBoth() {
|
||||
public function stringsForPadBoth()
|
||||
{
|
||||
$testData = array(
|
||||
array('foo bar ', 'foo bar', 8),
|
||||
array(' foo bar ', 'foo bar', 9, ' '),
|
||||
@@ -394,12 +426,14 @@ class StringyTestCase extends PHPUnit_Framework_TestCase {
|
||||
* @dataProvider stringsForStartsWith
|
||||
*/
|
||||
public function testStartsWith($expected, $string, $substring,
|
||||
$caseSensitive = true, $encoding = null) {
|
||||
$caseSensitive = true, $encoding = null)
|
||||
{
|
||||
$result = S::startsWith($string, $substring, $caseSensitive, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function stringsForStartsWith() {
|
||||
public function stringsForStartsWith()
|
||||
{
|
||||
$testData = array(
|
||||
array(true, 'foo bars', 'foo bar'),
|
||||
array(true, 'FOO bars', 'foo bar', false),
|
||||
@@ -421,12 +455,14 @@ class StringyTestCase extends PHPUnit_Framework_TestCase {
|
||||
* @dataProvider stringsForEndsWith
|
||||
*/
|
||||
public function testEndsWith($expected, $string, $substring,
|
||||
$caseSensitive = true, $encoding = null) {
|
||||
$caseSensitive = true, $encoding = null)
|
||||
{
|
||||
$result = S::endsWith($string, $substring, $caseSensitive, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function stringsForEndsWith() {
|
||||
public function stringsForEndsWith()
|
||||
{
|
||||
$testData = array(
|
||||
array(true, 'foo bars', 'o bars'),
|
||||
array(true, 'FOO bars', 'o bars', false),
|
||||
@@ -447,12 +483,14 @@ class StringyTestCase extends PHPUnit_Framework_TestCase {
|
||||
/**
|
||||
* @dataProvider stringsForToSpaces
|
||||
*/
|
||||
public function testToSpaces($expected, $string, $tabLength = 4) {
|
||||
public function testToSpaces($expected, $string, $tabLength = 4)
|
||||
{
|
||||
$result = S::toSpaces($string, $tabLength);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function stringsForToSpaces() {
|
||||
public function stringsForToSpaces()
|
||||
{
|
||||
$testData = array(
|
||||
array(' foo bar ', ' foo bar '),
|
||||
array(' foo bar ', ' foo bar ', 5),
|
||||
@@ -468,12 +506,14 @@ class StringyTestCase extends PHPUnit_Framework_TestCase {
|
||||
/**
|
||||
* @dataProvider stringsForToTabs
|
||||
*/
|
||||
public function testToTabs($expected, $string, $tabLength = 4) {
|
||||
public function testToTabs($expected, $string, $tabLength = 4)
|
||||
{
|
||||
$result = S::toTabs($string, $tabLength);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function stringsForToTabs() {
|
||||
public function stringsForToTabs()
|
||||
{
|
||||
$testData = array(
|
||||
array(' foo bar ', ' foo bar '),
|
||||
array(' foo bar ', ' foo bar ', 5),
|
||||
@@ -488,12 +528,14 @@ class StringyTestCase extends PHPUnit_Framework_TestCase {
|
||||
/**
|
||||
* @dataProvider stringsForSlugify
|
||||
*/
|
||||
public function testSlugify($expected, $string) {
|
||||
public function testSlugify($expected, $string)
|
||||
{
|
||||
$result = S::slugify($string);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function stringsForSlugify() {
|
||||
public function stringsForSlugify()
|
||||
{
|
||||
$testData = array(
|
||||
array('foo-bar', ' foo bar '),
|
||||
array('foo-dbar', " Foo d'Bar "),
|
||||
@@ -509,12 +551,14 @@ class StringyTestCase extends PHPUnit_Framework_TestCase {
|
||||
/**
|
||||
* @dataProvider stringsForContains
|
||||
*/
|
||||
public function testContains($expected, $haystack, $needle, $encoding = null) {
|
||||
public function testContains($expected, $haystack, $needle, $encoding = null)
|
||||
{
|
||||
$result = S::contains($haystack, $needle, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function stringsForContains() {
|
||||
public function stringsForContains()
|
||||
{
|
||||
$testData = array(
|
||||
array(true, 'This string contains foo bar', 'foo bar'),
|
||||
array(true, '12398!@(*%!@# @!%#*&^%', ' @!%#*&^%'),
|
||||
@@ -535,12 +579,14 @@ class StringyTestCase extends PHPUnit_Framework_TestCase {
|
||||
/**
|
||||
* @dataProvider stringsForSurround
|
||||
*/
|
||||
public function testSurround($expected, $string, $substring) {
|
||||
public function testSurround($expected, $string, $substring)
|
||||
{
|
||||
$result = S::surround($string, $substring);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function stringsForSurround() {
|
||||
public function stringsForSurround()
|
||||
{
|
||||
$testData = array(
|
||||
array('__foobar__', 'foobar', '__'),
|
||||
array('test', 'test', ''),
|
||||
@@ -556,12 +602,14 @@ class StringyTestCase extends PHPUnit_Framework_TestCase {
|
||||
* @dataProvider stringsForInsert
|
||||
*/
|
||||
public function testInsert($expected, $string, $substring, $index,
|
||||
$encoding = null) {
|
||||
$encoding = null)
|
||||
{
|
||||
$result = S::insert($string, $substring, $index, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function stringsForInsert() {
|
||||
public function stringsForInsert()
|
||||
{
|
||||
$testData = array(
|
||||
array('foo bar', 'oo bar', 'f', 0),
|
||||
array('foo bar', 'f bar', 'oo', 1),
|
||||
@@ -579,12 +627,14 @@ class StringyTestCase extends PHPUnit_Framework_TestCase {
|
||||
* @dataProvider stringsForTruncate
|
||||
*/
|
||||
public function testTruncate($expected, $string, $length, $substring = '',
|
||||
$encoding = null) {
|
||||
$encoding = null)
|
||||
{
|
||||
$result = S::truncate($string, $length, $substring, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function stringsForTruncate() {
|
||||
public function stringsForTruncate()
|
||||
{
|
||||
$testData = array(
|
||||
array('Test foo bar', 'Test foo bar', 12),
|
||||
array('Test foo', 'Test foo bar', 11),
|
||||
@@ -615,12 +665,14 @@ class StringyTestCase extends PHPUnit_Framework_TestCase {
|
||||
/**
|
||||
* @dataProvider stringsForReverse
|
||||
*/
|
||||
public function testReverse($expected, $string, $encoding = null) {
|
||||
public function testReverse($expected, $string, $encoding = null)
|
||||
{
|
||||
$result = S::reverse($string, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function stringsForReverse() {
|
||||
public function stringsForReverse()
|
||||
{
|
||||
$testData = array(
|
||||
array('', ''),
|
||||
array('raboof', 'foobar'),
|
||||
@@ -635,13 +687,15 @@ class StringyTestCase extends PHPUnit_Framework_TestCase {
|
||||
/**
|
||||
* @dataProvider stringsForShuffle
|
||||
*/
|
||||
public function testShuffle($string, $encoding = null) {
|
||||
public function testShuffle($string, $encoding = null)
|
||||
{
|
||||
// We'll just make sure that the chars are present before/after shuffle
|
||||
$result = S::shuffle($string, $encoding);
|
||||
$this->assertEquals(count_chars($string), count_chars($result));
|
||||
}
|
||||
|
||||
public function stringsForShuffle() {
|
||||
public function stringsForShuffle()
|
||||
{
|
||||
$testData = array(
|
||||
array('foo bar'),
|
||||
array('∂∆ ˚åß', 'UTF-8'),
|
||||
@@ -652,5 +706,3 @@ class StringyTestCase extends PHPUnit_Framework_TestCase {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
Reference in New Issue
Block a user