123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915 |
- <?php
- require __DIR__ . '/../src/Stringy.php';
- use Stringy\Stringy as S;
- class StringyTestCase extends CommonTest
- {
- public function testConstruct()
- {
- $stringy = new S('foo bar', 'UTF-8');
- $this->assertStringy($stringy);
- $this->assertEquals('foo bar', (string) $stringy);
- $this->assertEquals('UTF-8', $stringy->getEncoding());
- }
- /**
- * @expectedException InvalidArgumentException
- */
- public function testConstructWithArray()
- {
- (string) new S(array());
- $this->fail('Expecting exception when the constructor is passed an array');
- }
- /**
- * @expectedException InvalidArgumentException
- */
- public function testMissingToString()
- {
- (string) new S(new stdClass());
- $this->fail('Expecting exception when the constructor is passed an ' .
- 'object without a __toString method');
- }
- /**
- * @dataProvider toStringProvider()
- */
- public function testToString($expected, $str)
- {
- $this->assertEquals($expected, (string) new S($str));
- }
- public function toStringProvider()
- {
- return array(
- array('', null),
- array('', false),
- array('1', true),
- array('-9', -9),
- array('1.18', 1.18),
- array(' string ', ' string ')
- );
- }
- public function testCreate()
- {
- $stringy = S::create('foo bar', 'UTF-8');
- $this->assertStringy($stringy);
- $this->assertEquals('foo bar', (string) $stringy);
- $this->assertEquals('UTF-8', $stringy->getEncoding());
- }
- public function testChaining()
- {
- $stringy = S::create("Fòô Bàř", 'UTF-8');
- $this->assertStringy($stringy);
- $result = $stringy->collapseWhitespace()->swapCase()->upperCaseFirst();
- $this->assertEquals('FÒÔ bÀŘ', $result);
- }
- public function testCount()
- {
- $stringy = S::create('Fòô', 'UTF-8');
- $this->assertEquals(3, $stringy->count());
- $this->assertEquals(3, count($stringy));
- }
- public function testGetIterator()
- {
- $stringy = S::create('Fòô Bàř', 'UTF-8');
- $valResult = array();
- foreach ($stringy as $char) {
- $valResult[] = $char;
- }
- $keyValResult = array();
- foreach ($stringy as $pos => $char) {
- $keyValResult[$pos] = $char;
- }
- $this->assertEquals(array('F', 'ò', 'ô', ' ', 'B', 'à', 'ř'), $valResult);
- $this->assertEquals(array('F', 'ò', 'ô', ' ', 'B', 'à', 'ř'), $keyValResult);
- }
- /**
- * @dataProvider offsetExistsProvider()
- */
- public function testOffsetExists($expected, $offset)
- {
- $stringy = S::create('fòô', 'UTF-8');
- $this->assertEquals($expected, $stringy->offsetExists($offset));
- $this->assertEquals($expected, isset($stringy[$offset]));
- }
- public function offsetExistsProvider()
- {
- return array(
- array(true, 0),
- array(true, 2),
- array(false, 3),
- array(true, -1),
- array(true, -3),
- array(false, -4)
- );
- }
- public function testOffsetGet()
- {
- $stringy = S::create('fòô', 'UTF-8');
- $this->assertEquals('f', $stringy->offsetGet(0));
- $this->assertEquals('ô', $stringy->offsetGet(2));
- $this->assertEquals('ô', $stringy[2]);
- }
- /**
- * @expectedException \OutOfBoundsException
- */
- public function testOffsetGetOutOfBounds()
- {
- $stringy = S::create('fòô', 'UTF-8');
- $test = $stringy[3];
- }
- /**
- * @expectedException \Exception
- */
- public function testOffsetSet()
- {
- $stringy = S::create('fòô', 'UTF-8');
- $stringy[1] = 'invalid';
- }
- /**
- * @expectedException \Exception
- */
- public function testOffsetUnset()
- {
- $stringy = S::create('fòô', 'UTF-8');
- unset($stringy[1]);
- }
- /**
- * @dataProvider charsProvider()
- */
- public function testChars($expected, $str, $encoding = null)
- {
- $result = S::create($str, $encoding)->chars();
- $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::create($str, $encoding)->upperCaseFirst();
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- }
- /**
- * @dataProvider lowerCaseFirstProvider()
- */
- public function testLowerCaseFirst($expected, $str, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->lowerCaseFirst();
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider camelizeProvider()
- */
- public function testCamelize($expected, $str, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->camelize();
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider upperCamelizeProvider()
- */
- public function testUpperCamelize($expected, $str, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->upperCamelize();
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider dasherizeProvider()
- */
- public function testDasherize($expected, $str, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->dasherize();
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider underscoredProvider()
- */
- public function testUnderscored($expected, $str, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->underscored();
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider swapCaseProvider()
- */
- public function testSwapCase($expected, $str, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->swapCase();
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider titleizeProvider()
- */
- public function testTitleize($expected, $str, $ignore = null,
- $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->titleize($ignore);
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider humanizeProvider()
- */
- public function testHumanize($expected, $str, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->humanize();
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider tidyProvider()
- */
- public function testTidy($expected, $str)
- {
- $stringy = S::create($str);
- $result = $stringy->tidy();
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider collapseWhitespaceProvider()
- */
- public function testCollapseWhitespace($expected, $str, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->collapseWhitespace();
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider toAsciiProvider()
- */
- public function testToAscii($expected, $str, $removeUnsupported = true)
- {
- $stringy = S::create($str);
- $result = $stringy->toAscii($removeUnsupported);
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider padProvider()
- */
- public function testPad($expected, $str, $length, $padStr = ' ',
- $padType = 'right', $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->pad($length, $padStr, $padType);
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @expectedException \InvalidArgumentException
- */
- public function testPadException()
- {
- $stringy = S::create('foo');
- $result = $stringy->pad(5, 'foo', 'bar');
- }
- /**
- * @dataProvider padLeftProvider()
- */
- public function testPadLeft($expected, $str, $length, $padStr = ' ',
- $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->padLeft($length, $padStr);
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider padRightProvider()
- */
- public function testPadRight($expected, $str, $length, $padStr = ' ',
- $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->padRight($length, $padStr);
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider padBothProvider()
- */
- public function testPadBoth($expected, $str, $length, $padStr = ' ',
- $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->padBoth($length, $padStr);
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider startsWithProvider()
- */
- public function testStartsWith($expected, $str, $substring,
- $caseSensitive = true, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->startsWith($substring, $caseSensitive);
- $this->assertInternalType('boolean', $result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider endsWithProvider()
- */
- public function testEndsWith($expected, $str, $substring,
- $caseSensitive = true, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->endsWith($substring, $caseSensitive);
- $this->assertInternalType('boolean', $result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider toSpacesProvider()
- */
- public function testToSpaces($expected, $str, $tabLength = 4)
- {
- $stringy = S::create($str);
- $result = $stringy->toSpaces($tabLength);
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider toTabsProvider()
- */
- public function testToTabs($expected, $str, $tabLength = 4)
- {
- $stringy = S::create($str);
- $result = $stringy->toTabs($tabLength);
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider toLowerCaseProvider()
- */
- public function testToLowerCase($expected, $str, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->toLowerCase();
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider toTitleCaseProvider()
- */
- public function testToTitleCase($expected, $str, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->toTitleCase();
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider toUpperCaseProvider()
- */
- public function testToUpperCase($expected, $str, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->toUpperCase();
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider slugifyProvider()
- */
- public function testSlugify($expected, $str, $replacement = '-')
- {
- $stringy = S::create($str);
- $result = $stringy->slugify($replacement);
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider containsProvider()
- */
- public function testContains($expected, $haystack, $needle,
- $caseSensitive = true, $encoding = null)
- {
- $stringy = S::create($haystack, $encoding);
- $result = $stringy->contains($needle, $caseSensitive);
- $this->assertInternalType('boolean', $result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($haystack, $stringy);
- }
- /**
- * @dataProvider containsAnyProvider()
- */
- public function testcontainsAny($expected, $haystack, $needles,
- $caseSensitive = true, $encoding = null)
- {
- $stringy = S::create($haystack, $encoding);
- $result = $stringy->containsAny($needles, $caseSensitive);
- $this->assertInternalType('boolean', $result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($haystack, $stringy);
- }
- /**
- * @dataProvider containsAllProvider()
- */
- public function testContainsAll($expected, $haystack, $needles,
- $caseSensitive = true, $encoding = null)
- {
- $stringy = S::create($haystack, $encoding);
- $result = $stringy->containsAll($needles, $caseSensitive);
- $this->assertInternalType('boolean', $result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($haystack, $stringy);
- }
- /**
- * @dataProvider surroundProvider()
- */
- public function testSurround($expected, $str, $substring)
- {
- $stringy = S::create($str);
- $result = $stringy->surround($substring);
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider insertProvider()
- */
- public function testInsert($expected, $str, $substring, $index,
- $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->insert($substring, $index);
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider truncateProvider()
- */
- public function testTruncate($expected, $str, $length, $substring = '',
- $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->truncate($length, $substring);
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider safeTruncateProvider()
- */
- public function testSafeTruncate($expected, $str, $length, $substring = '',
- $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->safeTruncate($length, $substring);
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider reverseProvider()
- */
- public function testReverse($expected, $str, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->reverse();
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider shuffleProvider()
- */
- public function testShuffle($str, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $encoding = $encoding ?: mb_internal_encoding();
- $result = $stringy->shuffle();
- $this->assertStringy($result);
- $this->assertEquals($str, $stringy);
- $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)
- {
- $stringy = S::create($str);
- $result = $stringy->trim();
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider longestCommonPrefixProvider()
- */
- public function testLongestCommonPrefix($expected, $str, $otherStr,
- $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->longestCommonPrefix($otherStr);
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider longestCommonSuffixProvider()
- */
- public function testLongestCommonSuffix($expected, $str, $otherStr,
- $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->longestCommonSuffix($otherStr);
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider longestCommonSubstringProvider()
- */
- public function testLongestCommonSubstring($expected, $str, $otherStr,
- $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->longestCommonSubstring($otherStr);
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider lengthProvider()
- */
- public function testLength($expected, $str, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->length();
- $this->assertInternalType('int', $result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider substrProvider()
- */
- public function testSubstr($expected, $str, $start, $length = null,
- $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->substr($start, $length);
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider atProvider()
- */
- public function testAt($expected, $str, $index, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->at($index);
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider firstProvider()
- */
- public function testFirst($expected, $str, $n, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->first($n);
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider lastProvider()
- */
- public function testLast($expected, $str, $n, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->last($n);
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider ensureLeftProvider()
- */
- public function testEnsureLeft($expected, $str, $substring, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->ensureLeft($substring);
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider ensureRightProvider()
- */
- public function testEnsureRight($expected, $str, $substring, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->ensureRight($substring);
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider removeLeftProvider()
- */
- public function testRemoveLeft($expected, $str, $substring, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->removeLeft($substring);
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider removeRightProvider()
- */
- public function testRemoveRight($expected, $str, $substring, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->removeRight($substring);
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider isAlphaProvider()
- */
- public function testIsAlpha($expected, $str, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->isAlpha();
- $this->assertInternalType('boolean', $result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider isAlphanumericProvider()
- */
- public function testIsAlphanumeric($expected, $str, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->isAlphanumeric();
- $this->assertInternalType('boolean', $result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider isBlankProvider()
- */
- public function testIsBlank($expected, $str, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->isBlank();
- $this->assertInternalType('boolean', $result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider isJsonProvider()
- */
- public function testIsJson($expected, $str, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->isJson();
- $this->assertInternalType('boolean', $result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider isLowerCaseProvider()
- */
- public function testIsLowerCase($expected, $str, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->isLowerCase();
- $this->assertInternalType('boolean', $result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider hasLowerCaseProvider()
- */
- public function testHasLowerCase($expected, $str, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->hasLowerCase();
- $this->assertInternalType('boolean', $result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider isSerializedProvider()
- */
- public function testIsSerialized($expected, $str, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->isSerialized();
- $this->assertInternalType('boolean', $result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider isUpperCaseProvider()
- */
- public function testIsUpperCase($expected, $str, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->isUpperCase();
- $this->assertInternalType('boolean', $result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider hasUpperCaseProvider()
- */
- public function testHasUpperCase($expected, $str, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->hasUpperCase();
- $this->assertInternalType('boolean', $result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider isHexadecimalProvider()
- */
- public function testIsHexadecimal($expected, $str, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->isHexadecimal();
- $this->assertInternalType('boolean', $result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider countSubstrProvider()
- */
- public function testCountSubstr($expected, $str, $substring,
- $caseSensitive = true, $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->countSubstr($substring, $caseSensitive);
- $this->assertInternalType('int', $result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider replaceProvider()
- */
- public function testReplace($expected, $str, $search, $replacement,
- $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->replace($search, $replacement);
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- /**
- * @dataProvider regexReplaceProvider()
- */
- public function testregexReplace($expected, $str, $pattern, $replacement,
- $options = 'msr', $encoding = null)
- {
- $stringy = S::create($str, $encoding);
- $result = $stringy->regexReplace($pattern, $replacement, $options);
- $this->assertStringy($result);
- $this->assertEquals($expected, $result);
- $this->assertEquals($str, $stringy);
- }
- }
|