mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-08-31 16:51:57 +02:00
Compare commits
41 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
d661047fb3 | ||
|
26fe399396 | ||
|
31c4ba145f | ||
|
5a1be9bf20 | ||
|
28c3db01c5 | ||
|
27ef5a8914 | ||
|
350d1e6f8e | ||
|
ce58c93fc2 | ||
|
d60422d197 | ||
|
3cc12c2ee7 | ||
|
8e16ad472d | ||
|
3f926c654a | ||
|
f8fc711ae1 | ||
|
628c467a67 | ||
|
24aa843639 | ||
|
bb6ea99c52 | ||
|
d1df244678 | ||
|
9a929d1860 | ||
|
583789b9e3 | ||
|
f00e3d5d80 | ||
|
c31e41f57a | ||
|
722f30d132 | ||
|
26a0fed52e | ||
|
1c0026ca00 | ||
|
da5ee7057d | ||
|
410ceac663 | ||
|
857650f278 | ||
|
bc11fce93e | ||
|
fc885d777d | ||
|
9d2863b983 | ||
|
037184e3d9 | ||
|
8ac1918386 | ||
|
7cb6709fd4 | ||
|
a663802c2c | ||
|
7e91d1ead2 | ||
|
abf3e38c1c | ||
|
5a5c39d02b | ||
|
c577684e0a | ||
|
681463de87 | ||
|
90de5cca00 | ||
|
a0b7615210 |
@@ -5,6 +5,3 @@ php:
|
||||
- 5.4
|
||||
- 5.3
|
||||
- hhvm
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
|
14
CHANGELOG.md
14
CHANGELOG.md
@@ -1,3 +1,17 @@
|
||||
### 1.8.0 (2015-01-03)
|
||||
|
||||
* Listed ext-mbstring in composer.json
|
||||
* Added Stringy\create function for PHP 5.6
|
||||
|
||||
### 1.7.0 (2014-10-14)
|
||||
|
||||
* Added containsAll and containsAny
|
||||
* Light cleanup
|
||||
|
||||
### 1.6.0 (2014-09-14)
|
||||
|
||||
* Added toTitleCase
|
||||
|
||||
### 1.5.2 (2014-07-09)
|
||||
|
||||
* Announced support for HHVM
|
||||
|
78
README.md
78
README.md
@@ -1,20 +1,23 @@
|
||||

|
||||

|
||||
|
||||
A PHP library with a variety of string manipulation functions with multibyte
|
||||
support. Offers both OO method chaining and a procedural-style static wrapper.
|
||||
Tested and compatible with PHP 5.3+ and HHVM. Inspired by underscore.string.js.
|
||||
A PHP string manipulation library with multibyte support. Offers both OO method
|
||||
chaining and a procedural-style static wrapper. Tested and compatible with
|
||||
PHP 5.3+ and HHVM. Inspired by underscore.string.js.
|
||||
|
||||
[](https://travis-ci.org/danielstjules/Stringy)
|
||||
[](https://travis-ci.org/danielstjules/Stringy)
|
||||
|
||||
* [Requiring/Loading](#requiringloading)
|
||||
* [OO and Procedural](#oo-and-procedural)
|
||||
* [Implemented Interfaces](#implemented-interfaces)
|
||||
* [PHP 5.6 Creation](#php-56-creation)
|
||||
* [Methods](#methods)
|
||||
* [at](#at)
|
||||
* [camelize](#camelize)
|
||||
* [chars](#chars)
|
||||
* [collapseWhitespace](#collapsewhitespace)
|
||||
* [contains](#contains)
|
||||
* [containsAll](#containsall)
|
||||
* [containsAny](#containsany)
|
||||
* [countSubstr](#countsubstr)
|
||||
* [create](#create)
|
||||
* [dasherize](#dasherize)
|
||||
@@ -61,6 +64,7 @@ Tested and compatible with PHP 5.3+ and HHVM. Inspired by underscore.string.js.
|
||||
* [toLowerCase](#tolowercase)
|
||||
* [toSpaces](#tospaces)
|
||||
* [toTabs](#totabs)
|
||||
* [toTitleCase](#totitlecase)
|
||||
* [toUpperCase](#touppercase)
|
||||
* [trim](#trim)
|
||||
* [truncate](#truncate)
|
||||
@@ -76,9 +80,13 @@ Tested and compatible with PHP 5.3+ and HHVM. Inspired by underscore.string.js.
|
||||
If you're using Composer to manage dependencies, you can include the following
|
||||
in your composer.json file:
|
||||
|
||||
```json
|
||||
{
|
||||
"require": {
|
||||
"danielstjules/stringy": ">=1.5.2"
|
||||
"danielstjules/stringy": "~1.8"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Then, after running `composer update` or `php composer.phar update`, you can
|
||||
load the class using Composer's autoloading:
|
||||
@@ -164,6 +172,21 @@ $stringy[3]; // OutOfBoundsException
|
||||
$stringy[2] = 'a'; // Exception
|
||||
```
|
||||
|
||||
## PHP 5.6 Creation
|
||||
|
||||
As of PHP 5.6, [`use function`](https://wiki.php.net/rfc/use_function) is
|
||||
available for importing functions. Stringy exposes a namespaced function,
|
||||
`Stringy\create`, which emits the same behaviour as `Stringy\Stringy::create()`.
|
||||
If running PHP 5.6, or another runtime that supports the `use function` syntax,
|
||||
you can take advantage of an even simpler API as seen below:
|
||||
|
||||
``` php
|
||||
use function Stringy\create as s;
|
||||
|
||||
// Instead of: S::create('Fòô Bàř', 'UTF-8')
|
||||
s('Fòô Bàř', 'UTF-8')->collapseWhitespace()->swapCase();
|
||||
```
|
||||
|
||||
## Methods
|
||||
|
||||
In the list below, any static method other than S::create refers to a method in
|
||||
@@ -244,6 +267,36 @@ S::create('Ο συγγραφέας είπε', 'UTF-8')->contains('συγγραφ
|
||||
S::contains('Ο συγγραφέας είπε', 'συγγραφέας', 'UTF-8'); // true
|
||||
```
|
||||
|
||||
#### containsAll
|
||||
|
||||
$stringy->containsAll(array $needles [, boolean $caseSensitive = true ])
|
||||
|
||||
S::containsAll(string $haystack, array $needles [, boolean $caseSensitive = true [, string $encoding ]])
|
||||
|
||||
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.
|
||||
|
||||
```php
|
||||
S::create('Str contains foo and bar')->containsAll(array('foo', 'bar'));
|
||||
S::containsAll('Str contains foo and bar', array('foo', 'bar')); // true
|
||||
```
|
||||
|
||||
#### containsAny
|
||||
|
||||
$stringy->containsAny(array $needles [, boolean $caseSensitive = true ])
|
||||
|
||||
S::containsAny(string $haystack, array $needles [, boolean $caseSensitive = true [, string $encoding ]])
|
||||
|
||||
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.
|
||||
|
||||
```php
|
||||
S::create('Str contains foo')->containsAny(array('foo', 'bar'));
|
||||
S::containsAny('Str contains foo', array('foo', 'bar')); // true
|
||||
```
|
||||
|
||||
#### countSubstr
|
||||
|
||||
$stringy->countSubstr(string $substring [, boolean $caseSensitive = true ])
|
||||
@@ -881,6 +934,19 @@ S::create(' fòô bàř')->toTabs();
|
||||
S::toTabs(' fòô bàř'); // ' fòô bàř'
|
||||
```
|
||||
|
||||
#### toTitleCase
|
||||
|
||||
$stringy->toTitleCase()
|
||||
|
||||
S::toTitleCase(string $str [, string $encoding ])
|
||||
|
||||
Converts the first character of each word in the string to uppercase.
|
||||
|
||||
```php
|
||||
S::create('fòô bàř', 'UTF-8')->toTitleCase();
|
||||
S::toTitleCase('fòô bàř', 'UTF-8'); // 'Fòô Bàř'
|
||||
```
|
||||
|
||||
#### toUpperCase
|
||||
|
||||
$stringy->toUpperCase()
|
||||
|
@@ -15,10 +15,11 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
"php": ">=5.3.0",
|
||||
"ext-mbstring": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "4.0.*"
|
||||
"phpunit/phpunit": "~4.0"
|
||||
},
|
||||
"support": {
|
||||
"issues": "https://github.com/danielstjules/Stringy/issues",
|
||||
@@ -26,6 +27,9 @@
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Stringy\\": "src/" },
|
||||
"files": ["src/Create.php"]
|
||||
},
|
||||
"autoload-dev": {
|
||||
"classmap": [ "tests" ]
|
||||
}
|
||||
}
|
||||
|
@@ -5,7 +5,10 @@
|
||||
syntaxCheck="false">
|
||||
<testsuites>
|
||||
<testsuite name="Stringy">
|
||||
<directory>tests</directory>
|
||||
<file>tests/CommonTest.php</file>
|
||||
<file>tests/StringyTest.php</file>
|
||||
<file>tests/StaticStringyTest.php</file>
|
||||
<file phpVersion="5.6.0">tests/CreateTest.php</file>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
||||
|
17
src/Create.php
Normal file
17
src/Create.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Stringy;
|
||||
|
||||
/**
|
||||
* Invokes Stringy::create and returns the generated Stringy object on success.
|
||||
*
|
||||
* @param mixed $str Value to modify, after being cast to string
|
||||
* @param string $encoding The character encoding
|
||||
* @return Stringy A Stringy object
|
||||
* @throws \InvalidArgumentException if an array or object without a
|
||||
* __toString method is passed as the first argument
|
||||
*/
|
||||
function create($str, $encoding = null)
|
||||
{
|
||||
return new Stringy($str, $encoding);
|
||||
}
|
@@ -323,6 +323,18 @@ class StaticStringy
|
||||
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().
|
||||
@@ -370,6 +382,42 @@ class StaticStringy
|
||||
->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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Surrounds a string with the given substring.
|
||||
*
|
||||
@@ -428,7 +476,7 @@ class StaticStringy
|
||||
* @return string The resulting string after truncating
|
||||
*/
|
||||
public static function safeTruncate($str, $length, $substring = '',
|
||||
$encoding = null)
|
||||
$encoding = null)
|
||||
{
|
||||
return (string) Stringy::create($str, $encoding)
|
||||
->safeTruncate($length, $substring);
|
||||
|
126
src/Stringy.php
126
src/Stringy.php
@@ -4,8 +4,19 @@ namespace Stringy;
|
||||
|
||||
class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
{
|
||||
/**
|
||||
* An instance's string.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $str;
|
||||
|
||||
/**
|
||||
* The string's encoding, which should be one of the mbstring module's
|
||||
* supported encodings.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $encoding;
|
||||
|
||||
/**
|
||||
@@ -26,7 +37,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
throw new \InvalidArgumentException(
|
||||
'Passed value cannot be an array'
|
||||
);
|
||||
} else if (is_object($str) && !method_exists($str, '__toString')) {
|
||||
} elseif (is_object($str) && !method_exists($str, '__toString')) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Passed object must have a __toString method'
|
||||
);
|
||||
@@ -105,7 +116,8 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
* @param mixed $offset The index to check
|
||||
* @return boolean Whether or not the index exists
|
||||
*/
|
||||
public function offsetExists($offset) {
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
$length = $this->length();
|
||||
$offset = (int) $offset;
|
||||
|
||||
@@ -127,7 +139,8 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
* @throws \OutOfBoundsException If the positive or negative offset does
|
||||
* not exist
|
||||
*/
|
||||
public function offsetGet($offset) {
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
$offset = (int) $offset;
|
||||
$length = $this->length();
|
||||
|
||||
@@ -146,7 +159,8 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
* @param mixed $value Value to set
|
||||
* @throws \Exception When called
|
||||
*/
|
||||
public function offsetSet($offset, $value) {
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
// Stringy is immutable, cannot directly set char
|
||||
throw new \Exception('Stringy object is immutable, cannot modify char');
|
||||
}
|
||||
@@ -158,7 +172,8 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
* @param mixed $offset The index of the character
|
||||
* @throws \Exception When called
|
||||
*/
|
||||
public function offsetUnset($offset) {
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
// Don't allow directly modifying the string
|
||||
throw new \Exception('Stringy object is immutable, cannot unset char');
|
||||
}
|
||||
@@ -224,7 +239,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
|
||||
$camelCase = preg_replace_callback(
|
||||
'/[-_\s]+(.)?/u',
|
||||
function($match) use ($encoding) {
|
||||
function ($match) use ($encoding) {
|
||||
return $match[1] ? mb_strtoupper($match[1], $encoding) : '';
|
||||
},
|
||||
$stringy->trim()->lowerCaseFirst()->str
|
||||
@@ -232,7 +247,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
|
||||
$stringy->str = preg_replace_callback(
|
||||
'/[\d]+(.)?/u',
|
||||
function($match) use ($encoding) {
|
||||
function ($match) use ($encoding) {
|
||||
return mb_strtoupper($match[0], $encoding);
|
||||
},
|
||||
$camelCase
|
||||
@@ -361,8 +376,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*/
|
||||
public function humanize()
|
||||
{
|
||||
$str = str_replace('_id', '', $this->str);
|
||||
$str = str_replace('_', ' ', $str);
|
||||
$str = str_replace(array('_id', '_'), array('', ' '), $this->str);
|
||||
|
||||
return self::create($str, $this->encoding)->trim()->upperCaseFirst();
|
||||
}
|
||||
@@ -376,11 +390,17 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*/
|
||||
public function tidy()
|
||||
{
|
||||
$str = $this->str;
|
||||
$str = preg_replace('/\x{2026}/u', '...', $str);
|
||||
$str = preg_replace('/[\x{201C}\x{201D}]/u', '"', $str);
|
||||
$str = preg_replace('/[\x{2018}\x{2019}]/u', "'", $str);
|
||||
$str = preg_replace('/[\x{2013}\x{2014}]/u', '-', $str);
|
||||
$str = preg_replace(array(
|
||||
'/\x{2026}/u',
|
||||
'/[\x{201C}\x{201D}]/u',
|
||||
'/[\x{2018}\x{2019}]/u',
|
||||
'/[\x{2013}\x{2014}]/u',
|
||||
), array(
|
||||
'...',
|
||||
'"',
|
||||
"'",
|
||||
'-',
|
||||
), $this->str);
|
||||
|
||||
return self::create($str, $this->encoding);
|
||||
}
|
||||
@@ -676,6 +696,18 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
return self::create($str, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the first character of each word in the string to uppercase.
|
||||
*
|
||||
* @return Stringy Object with all characters of $str being title-cased
|
||||
*/
|
||||
public function toTitleCase()
|
||||
{
|
||||
$str = mb_convert_case($this->str, MB_CASE_TITLE, $this->encoding);
|
||||
|
||||
return self::create($str, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts all characters in the string to lowercase. An alias for PHP's
|
||||
* mb_strtolower().
|
||||
@@ -744,6 +776,54 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 array $needles Substrings to look for
|
||||
* @param bool $caseSensitive Whether or not to enforce case-sensitivity
|
||||
* @return bool Whether or not $str contains $needle
|
||||
*/
|
||||
public function containsAny($needles, $caseSensitive = true)
|
||||
{
|
||||
if (empty($needles)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($needles as $needle) {
|
||||
if ($this->contains($needle, $caseSensitive)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 array $needles Substrings to look for
|
||||
* @param bool $caseSensitive Whether or not to enforce case-sensitivity
|
||||
* @return bool Whether or not $str contains $needle
|
||||
*/
|
||||
public function containsAll($needles, $caseSensitive = true)
|
||||
{
|
||||
if (empty($needles)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($needles as $needle) {
|
||||
if (!$this->contains($needle, $caseSensitive)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Surrounds $str with the given substring.
|
||||
*
|
||||
@@ -965,8 +1045,8 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
$end = 0;
|
||||
$table = array_fill(0, $strLength + 1, array_fill(0, $otherLength + 1, 0));
|
||||
|
||||
for ($i = 1; $i <= $strLength; $i++){
|
||||
for ($j = 1; $j <= $otherLength; $j++){
|
||||
for ($i = 1; $i <= $strLength; $i++) {
|
||||
for ($j = 1; $j <= $otherLength; $j++) {
|
||||
$strChar = mb_substr($stringy->str, $i - 1, 1, $encoding);
|
||||
$otherChar = mb_substr($otherStr, $j - 1, 1, $encoding);
|
||||
|
||||
@@ -1008,17 +1088,10 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*/
|
||||
public function substr($start, $length = null)
|
||||
{
|
||||
$stringy = self::create($this->str, $this->encoding);
|
||||
$length = $length === null ? $this->length() : $length;
|
||||
$str = mb_substr($this->str, $start, $length, $this->encoding);
|
||||
|
||||
if ($length === null) {
|
||||
$stringy->str = mb_substr($stringy->str, $start,
|
||||
$stringy->length() - $start, $this->encoding);
|
||||
} else {
|
||||
$stringy->str = mb_substr($stringy->str, $start, $length,
|
||||
$stringy->encoding);
|
||||
}
|
||||
|
||||
return $stringy;
|
||||
return self::create($str, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1215,7 +1288,6 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
return (json_last_error() === JSON_ERROR_NONE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the string contains only lower case chars, false
|
||||
* otherwise.
|
||||
|
@@ -2,6 +2,16 @@
|
||||
|
||||
abstract class CommonTest 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 charsProvider()
|
||||
{
|
||||
return array(
|
||||
@@ -318,6 +328,17 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
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(
|
||||
@@ -354,30 +375,106 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
public function containsProvider()
|
||||
{
|
||||
return array(
|
||||
array(true, 'This string contains foo bar', 'foo bar'),
|
||||
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, 'This string contains foo bar', 'Foo bar'),
|
||||
array(false, 'This string contains foo bar', 'foobar'),
|
||||
array(false, 'This string contains foo bar', 'foo bar '),
|
||||
array(false, '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, 'This string contains foo bar', 'Foo bar', false),
|
||||
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, 'This string contains foo bar', 'foobar', false),
|
||||
array(false, 'This string contains foo bar', 'foo bar ', false),
|
||||
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(
|
||||
|
16
tests/CreateTest.php
Normal file
16
tests/CreateTest.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../src/Create.php';
|
||||
|
||||
use function Stringy\create as s;
|
||||
|
||||
class CreateTestCase extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testCreate()
|
||||
{
|
||||
$stringy = s('foo bar', 'UTF-8');
|
||||
$this->assertInstanceOf('Stringy\Stringy', $stringy);
|
||||
$this->assertEquals('foo bar', (string) $stringy);
|
||||
$this->assertEquals('UTF-8', $stringy->getEncoding());
|
||||
}
|
||||
}
|
@@ -244,6 +244,16 @@ class StaticStringyTestCase extends CommonTest
|
||||
$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()
|
||||
*/
|
||||
@@ -275,6 +285,28 @@ class StaticStringyTestCase extends CommonTest
|
||||
$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()
|
||||
*/
|
||||
|
@@ -9,7 +9,7 @@ class StringyTestCase extends CommonTest
|
||||
public function testConstruct()
|
||||
{
|
||||
$stringy = new S('foo bar', 'UTF-8');
|
||||
$this->assertInstanceOf('Stringy\Stringy', $stringy);
|
||||
$this->assertStringy($stringy);
|
||||
$this->assertEquals('foo bar', (string) $stringy);
|
||||
$this->assertEquals('UTF-8', $stringy->getEncoding());
|
||||
}
|
||||
@@ -56,7 +56,7 @@ class StringyTestCase extends CommonTest
|
||||
public function testCreate()
|
||||
{
|
||||
$stringy = S::create('foo bar', 'UTF-8');
|
||||
$this->assertInstanceOf('Stringy\Stringy', $stringy);
|
||||
$this->assertStringy($stringy);
|
||||
$this->assertEquals('foo bar', (string) $stringy);
|
||||
$this->assertEquals('UTF-8', $stringy->getEncoding());
|
||||
}
|
||||
@@ -64,7 +64,7 @@ class StringyTestCase extends CommonTest
|
||||
public function testChaining()
|
||||
{
|
||||
$stringy = S::create("Fòô Bàř", 'UTF-8');
|
||||
$this->assertInstanceOf('Stringy\Stringy', $stringy);
|
||||
$this->assertStringy($stringy);
|
||||
$result = $stringy->collapseWhitespace()->swapCase()->upperCaseFirst();
|
||||
$this->assertEquals('FÒÔ bÀŘ', $result);
|
||||
}
|
||||
@@ -172,7 +172,7 @@ class StringyTestCase extends CommonTest
|
||||
public function testUpperCaseFirst($expected, $str, $encoding = null)
|
||||
{
|
||||
$result = S::create($str, $encoding)->upperCaseFirst();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->lowerCaseFirst();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -195,7 +195,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->camelize();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -207,7 +207,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->upperCamelize();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -219,7 +219,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->dasherize();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -231,7 +231,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->underscored();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -243,7 +243,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->swapCase();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -256,7 +256,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->titleize($ignore);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -268,7 +268,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->humanize();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -280,7 +280,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str);
|
||||
$result = $stringy->tidy();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -292,7 +292,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->collapseWhitespace();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -304,7 +304,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str);
|
||||
$result = $stringy->toAscii();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -317,7 +317,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->pad($length, $padStr, $padType);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -339,7 +339,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->padLeft($length, $padStr);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -352,7 +352,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->padRight($length, $padStr);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -365,7 +365,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->padBoth($length, $padStr);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -403,7 +403,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str);
|
||||
$result = $stringy->toSpaces($tabLength);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -415,7 +415,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str);
|
||||
$result = $stringy->toTabs($tabLength);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -427,7 +427,19 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->toLowerCase();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$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);
|
||||
}
|
||||
@@ -439,7 +451,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->toUpperCase();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -451,7 +463,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str);
|
||||
$result = $stringy->slugify($replacement);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -469,6 +481,32 @@ class StringyTestCase extends CommonTest
|
||||
$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()
|
||||
*/
|
||||
@@ -476,7 +514,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str);
|
||||
$result = $stringy->surround($substring);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -489,7 +527,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->insert($substring, $index);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -502,7 +540,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->truncate($length, $substring);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -514,7 +552,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->reverse();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -528,7 +566,7 @@ class StringyTestCase extends CommonTest
|
||||
$encoding = $encoding ?: mb_internal_encoding();
|
||||
$result = $stringy->shuffle();
|
||||
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
$this->assertEquals(mb_strlen($str, $encoding),
|
||||
mb_strlen($result, $encoding));
|
||||
@@ -549,7 +587,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str);
|
||||
$result = $stringy->trim();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -562,7 +600,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->longestCommonPrefix($otherStr);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -575,7 +613,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->longestCommonSubstring($otherStr);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -600,7 +638,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->substr($start, $length);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -612,7 +650,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->at($index);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -624,7 +662,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->first($n);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -636,7 +674,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->last($n);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -648,7 +686,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->ensureLeft($substring);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -660,7 +698,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->ensureRight($substring);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -672,7 +710,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->removeLeft($substring);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -684,7 +722,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->removeRight($substring);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -806,7 +844,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->replace($search, $replacement);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -819,7 +857,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->regexReplace($pattern, $replacement, $options);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
Reference in New Issue
Block a user