1
0
mirror of https://github.com/danielstjules/Stringy.git synced 2025-08-31 16:51:57 +02:00

120 Commits
1.x ... 2.x

Author SHA1 Message Date
Daniel St. Jules
edbda419cb 2.4.0 2017-03-02 15:43:29 -05:00
Daniel St. Jules
e8afcffc7c Add ў and Ў to charsArray 2017-03-02 15:33:26 -05:00
Daniel St. Jules
986260239d Fix safeTruncate tests 2017-03-02 15:18:53 -05:00
forevermatt
841600867d Fix safeTruncate to handle strings without spaces and those where the first word is longer than the desired truncation length
Before this, calling safeTruncate with a string without spaces and a truncate length less than the string length would return an empty string.
2017-03-02 15:18:53 -05:00
Daniel St. Jules
845e8d693d Merge pull request #153 from vpassapera/feature/fix-phpdoc
Fixes phpdoc for objects extending stringy.
2017-03-01 00:33:19 -05:00
Daniel St. Jules
b35270671c Merge pull request #143 from fgambino/patch-1
Add full width character forms to ascii map
2017-02-28 23:54:27 -05:00
Daniel St. Jules
0aab4361bf Merge pull request #157 from OlivierBarbier/master
Reuse substr method
2017-02-28 23:46:09 -05:00
Daniel St. Jules
df777da6ac Add endsWithAny 2017-02-28 23:41:49 -05:00
Daniel St. Jules
ded4d41d44 Use table for linking to methods 2017-02-28 23:31:03 -05:00
Daniel St. Jules
569736327a Fix readme link 2017-02-28 23:24:33 -05:00
Daniel St. Jules
6f2e2851ac Add startsWithAny to readme 2017-02-28 23:23:43 -05:00
Daniel St. Jules
553bf37acb Merge pull request #151 from vikpe/master
Add documentation for stripWhitespace()
2017-02-28 23:16:59 -05:00
Olivier Barbier
916f79221e Reuse substr method 2017-02-16 12:13:56 +01:00
Victor Passapera
d71d4f0ad6 Fixes phpdoc for objects extending stringy. 2017-01-19 22:42:06 -08:00
Daniel St. Jules
de93eab01f Merge pull request #147 from mimmi20/master
New method request: startsWithAny()
2016-12-23 12:46:28 -08:00
Thomas Müller
9b6404d5c3 update array syntax 2016-12-23 21:28:39 +01:00
Viktor Persson
27a4f11f2e Added documentation for stripWhitespace(). 2016-12-22 10:37:27 +01:00
Daniel St. Jules
46de78bda9 Merge pull request #150 from vikpe/master
Add stripWhitespace
2016-12-22 01:03:59 -08:00
Daniel St. Jules
cb14fc2e6b Change private to protected to facilitate extending class 2016-12-21 23:28:07 -08:00
Daniel St. Jules
090a15f2fd Fix #142 - Fix and improve exception in supportsEncoding 2016-12-21 23:25:46 -08:00
Viktor Persson
d80347e72a Add stripWhitespace 2016-12-20 19:40:02 +01:00
Thomas Müller
0491ed8db8 add startsWithAny function 2016-10-31 19:54:19 +01:00
Frank Gambino
eb445b55ef Use utf-8 representation of the wide space char 2016-09-29 09:35:01 -04:00
Frank Gambino
91b153d30e Add wide non-breaking space 2016-09-29 09:26:35 -04:00
Frank Gambino
9ebdf88b71 Add full width character forms to ascii map
Reference: http://www.fileformat.info/info/unicode/block/halfwidth_and_fullwidth_forms/list.htm
2016-09-29 09:19:33 -04:00
Daniel St. Jules
0607751e17 Merge pull request #139 from tomeh/documentation-fixes
Updated documentation.
2016-06-14 13:50:55 -07:00
Tom Harris
6507f0ac44 Updated documentation.
Fixed presumed typos.
2016-06-14 21:13:57 +01:00
Daniel St. Jules
4e214a5195 2.3.2 2016-05-02 08:18:10 -07:00
Daniel St. Jules
fcc2969210 Merge pull request #137 from danielstjules/mbstring
Fix #134: Improve support without mbstring
2016-05-02 08:14:50 -07:00
Daniel St. Jules
30d1742082 Work on full support with mbstring module 2016-05-01 19:16:24 -07:00
Daniel St. Jules
bd90918858 2.3.1 2016-03-21 13:26:21 -07:00
Daniel St. Jules
a2d1ec535a Fix #129: Always use root namespace for mbstring functions 2016-03-21 13:22:27 -07:00
Daniel St. Jules
b953a85d2c Add capture group test to regexReplaceProvider 2016-03-19 17:57:04 -07:00
Daniel St. Jules
e07a07a076 Add capture group example to readme 2016-03-19 17:53:09 -07:00
Daniel St. Jules
c4d785d29f Fix changelog date 2016-03-19 17:34:20 -07:00
Daniel St. Jules
5554477962 2.3.0 2016-03-19 17:33:13 -07:00
Daniel St. Jules
87c1a47355 Support older verisons of composer 2016-03-19 17:21:08 -07:00
Daniel St. Jules
6d558974ba Merge pull request #120 from lucasmichot/feature/master/useless-else
Remove some useless else.
2016-02-10 13:20:49 -08:00
Daniel St. Jules
5a9b987f9a Merge pull request #124 from lucasmichot/feature/master/integrates-polyfill
Add polyfill
2016-02-09 16:59:23 -08:00
Lucas Michot
e3d397fa74 Add polyfill 2016-02-10 01:56:06 +01:00
Daniel St. Jules
ffc3fa5ff9 Merge pull request #112 from lucasmichot/feature/master/polyfill
WIP - Allows Stringy to work without ext-mbstring
2016-02-09 16:43:13 -08:00
Lucas Michot
c3f25577ed Avoid duplicate jobs 2016-02-10 01:38:59 +01:00
Lucas Michot
5a4629662c Add tests matrix 2016-02-10 01:28:12 +01:00
Lucas Michot
823e50a340 Allows Stringy to work without ext-mbstring 2016-01-08 18:35:53 +01:00
Daniel St. Jules
9d77c49fca Merge pull request #117 from lucasmichot/feature/master/phpunit-autoload
Let phpunit load autoload.php
2016-01-08 09:32:17 -08:00
Daniel St. Jules
a074d2a2ac Merge pull request #118 from lucasmichot/feature/master/import
Avoid FQN in code
2016-01-08 09:30:30 -08:00
Daniel St. Jules
b7cfa84219 Merge pull request #119 from lucasmichot/feature/master/export-ignore-editorconfig
Do not export .editorconfig
2016-01-08 09:25:15 -08:00
Lucas Michot
e3be6a56ea Composer install for travisCI tests. 2016-01-08 18:22:09 +01:00
Lucas Michot
bdbd4d7541 Let phpunit load autoload.php 2016-01-08 18:01:20 +01:00
Lucas Michot
8419369f3b Add some imports 2016-01-08 18:01:13 +01:00
Lucas Michot
a3dde38a2f Do not export .editorconfig 2016-01-08 18:00:43 +01:00
Lucas Michot
59ce593086 Remove some useless else. 2016-01-08 18:00:23 +01:00
Daniel St. Jules
54cf92c89c Merge pull request #115 from behzadsh/master
Add Persian characters in Stringy::charsArray()
2015-12-27 11:17:23 -05:00
Behzad Shabani
d320bf8704 Add Persian characters in Stringy::charsArray() 2015-12-27 16:03:33 +03:30
Daniel St. Jules
2de4c4aee3 Add badges 2015-12-26 08:13:47 -08:00
Daniel St. Jules
fc39b70953 2.2 2015-12-20 16:49:59 -08:00
Daniel St. Jules
9b61dcc771 Remove y char 2015-12-20 16:45:53 -08:00
Daniel St. Jules
b85a84d0b9 Fix #108 Improve char coverage 2015-12-20 16:44:46 -08:00
Daniel St. Jules
e5c3043d75 Style fixes 2015-12-20 13:22:02 -08:00
Daniel St. Jules
49a7405a2a Remove package annotation from #105 2015-12-20 13:19:29 -08:00
Daniel St. Jules
63109ce85c Add @method lines to StaticStringy 2015-12-20 13:08:08 -08:00
Daniel St. Jules
b223a2c320 Small fixes from #105 2015-12-20 12:08:36 -08:00
Daniel St. Jules
264eed18dd Merge pull request #111 from lucasmichot/feature/master/gitattributes
Add a basic .gitattributes file and avoid some exports
2015-12-20 14:51:11 -05:00
Daniel St. Jules
d990a41a1a Update isBase64 to return true if an empty string 2015-12-20 11:46:33 -08:00
Marcel Pociot
318db789b1 Added isBase64 method 2015-12-20 11:44:18 -08:00
Daniel St. Jules
f086c67ac7 Merge pull request #114 from danielstjules/reflection
Reflection
2015-12-20 14:37:45 -05:00
Daniel St. Jules
ee59d586f2 PHP 5.3 support with reflection 2015-12-20 11:35:48 -08:00
samuelwilliams
3c7bc662a6 :: is dynamically generated. 2015-12-20 17:01:52 +11:00
Daniel St. Jules
2072e667e9 Merge pull request #109 from lucasmichot/feature/master/editorconfig
Add a .editorconfig file
2015-12-08 13:29:02 -05:00
Lucas Michot
b65da66ae8 Add a .gitattributes file and avoid some exports 2015-12-06 14:20:38 +01:00
Lucas Michot
604ddc0528 Add a .editorconfig file 2015-12-06 14:11:58 +01:00
Daniel St. Jules
abd5505e98 Merge pull request #103 from danielkesselberg/master
Update for German umlaut transformation
2015-10-19 22:54:55 -07:00
Daniel Kesselberg
ee4b89c2f8 Update for German umlaut transformation (Ä => AE, Ö => UE, Ü => UE, ä => ae, ö => oe, ü => ue) 2015-09-24 10:47:35 +02:00
Daniel St. Jules
ac04be8416 Add note on PHP 7 compatibility 2015-09-09 22:17:45 -07:00
Daniel St. Jules
41336996a1 Fix ensureRight doc comment 2015-09-09 22:06:27 -07:00
Daniel St. Jules
a8793ff711 Merge pull request #100 from joshdifabio/patch-1
Fix copy/paste mistake in README
2015-09-09 22:05:46 -07:00
Daniel St. Jules
183e529e15 Merge pull request #102 from Big-Shark/newTravisInfrastructure
Changed travis infrastructure
2015-09-09 21:59:17 -07:00
Daniel St. Jules
4673754054 Fix: isJSON now returns false for empty strings 2015-09-09 21:24:11 -07:00
Big_Shark
83671e721a Changed travis infrastructure 2015-09-10 11:19:33 +07:00
Daniel St. Jules
c5f370c46d Merge pull request #101 from Big-Shark/php7
Added php7 for travis
2015-09-09 21:18:47 -07:00
Big_Shark
436d269622 Added php7 for travis 2015-09-10 11:16:21 +07:00
Josh Di Fabio
c09de057a1 Fix copy/paste mistake in README 2015-09-08 13:37:21 +01:00
Daniel St. Jules
efb10020f6 2.1 2015-09-02 23:50:48 -07:00
Daniel St. Jules
ae74e66369 Update readme notes on StaticStringy 2015-09-02 23:47:07 -07:00
Daniel St. Jules
f6475e1288 Stringy::create str defaults to empty string 2015-09-02 23:46:48 -07:00
Daniel St. Jules
ff36c79892 Add test for StaticStringy invocation 2015-09-02 23:37:17 -07:00
Daniel St. Jules
8f40b3495d String is now optional in Stringy constructor 2015-09-02 23:35:32 -07:00
Daniel St. Jules
e237f30d94 Bring back StaticStringy as a __callStatic wrapper 2015-09-02 00:12:25 -07:00
Daniel St. Jules
ad6d32080f Update titleize description in readme 2015-07-29 02:09:00 -07:00
Daniel St. Jules
7377aabf61 Fix titleize example 2015-07-29 02:05:16 -07:00
Daniel St. Jules
01fb889a1a 2.0.0 2015-07-29 01:36:15 -07:00
Daniel St. Jules
775d004629 Check offset in camelize 2015-07-29 01:31:53 -07:00
Daniel St. Jules
fe266445f7 Revise why section in readme 2015-07-28 23:59:56 -07:00
Daniel St. Jules
dd95144bf8 Add mbstring to readme example 2015-07-28 23:41:28 -07:00
Daniel St. Jules
812f227f11 Add why section 2015-07-28 23:28:23 -07:00
Daniel St. Jules
6667ca1aed Updating examples, adding tests 2015-07-28 23:06:44 -07:00
Daniel St. Jules
cde0740118 Add note on 1.x documentation 2015-07-28 22:24:47 -07:00
Daniel St. Jules
fa22b94abf Issue #82: titleize now lowercases, no longer preserves acronyms 2015-07-28 22:21:33 -07:00
Daniel St. Jules
f12b40cc29 Strip leading dashes and underscores with camelize 2015-07-28 22:07:04 -07:00
Daniel St. Jules
e1c562b7e8 Update php version compatibility notes 2015-07-27 12:31:40 -07:00
Daniel St. Jules
a39ed63627 Fix split for PHP 5.3 2015-07-26 23:49:50 -07:00
Daniel St. Jules
f34af92850 Re-order functions in Stringy.php 2015-07-26 23:41:35 -07:00
Daniel St. Jules
9165957971 Update htmlEncode and htmlDecode docs 2015-07-25 22:25:44 -07:00
Daniel St. Jules
b3f1bf5174 Update example in readme 2015-07-25 22:20:56 -07:00
Daniel St. Jules
b9cf4b6ae3 Added lines 2015-07-25 22:19:36 -07:00
Daniel St. Jules
cce314f4a5 Add note on syntax in examples 2015-07-25 20:33:34 -07:00
Daniel St. Jules
4a971302f7 Comment fix 2015-07-25 20:07:23 -07:00
Daniel St. Jules
3dcc801483 Use php 5.6 creation in examples 2015-07-25 20:05:34 -07:00
Daniel St. Jules
fe7b54a4e7 Added split 2015-07-25 19:58:50 -07:00
Daniel St. Jules
5e3ac6231c Added slice 2015-07-25 12:59:23 -07:00
Daniel St. Jules
342ef7c3dd Add between 2015-07-24 13:34:50 -07:00
Daniel St. Jules
9d5a06cf37 Update intro code 2015-07-24 00:09:10 -07:00
Daniel St. Jules
2d34e72cde Added repeat 2015-07-23 23:53:33 -07:00
Daniel St. Jules
bded15d683 Added toBoolean 2015-07-23 23:40:21 -07:00
Daniel St. Jules
6b74918cc9 Pending tests 2015-07-23 22:47:46 -07:00
Daniel St. Jules
804aa3e700 Add notes on mbstring to readme 2015-07-22 23:52:36 -07:00
Daniel St. Jules
aef6f0c200 Add append and prepend 2015-07-22 23:30:02 -07:00
Daniel St. Jules
f77d9903fa Reformatting readme 2015-07-22 23:08:19 -07:00
Daniel St. Jules
c673cd3edf Remove StaticStringy from readme 2015-07-22 18:37:33 -07:00
Daniel St. Jules
0d92d7e810 Remove StaticStringy 2015-07-22 18:15:54 -07:00
13 changed files with 3791 additions and 4518 deletions

16
.editorconfig Normal file
View File

@@ -0,0 +1,16 @@
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
[*.yml]
indent_style = space
indent_size = 2

8
.gitattributes vendored Normal file
View File

@@ -0,0 +1,8 @@
* text=auto
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.travis.yml export-ignore
phpunit.xml.dist export-ignore
tests export-ignore

View File

@@ -1,7 +1,43 @@
language: php
php:
- 5.6
- 5.5
- 5.4
- 5.3
- hhvm
# This triggers builds to run on the new TravisCI infrastructure.
# See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/
sudo: false
matrix:
fast_finish: true
include:
- php: 5.3
env: polyfill='true'
- php: 5.3
env: polyfill='false'
- php: 5.4
env: polyfill='true'
- php: 5.4
env: polyfill='false'
- php: 5.5
env: polyfill='true'
- php: 5.5
env: polyfill='false'
- php: 5.6
env: polyfill='true'
- php: 5.6
env: polyfill='false'
- php: 7.0
env: polyfill='true'
- php: 7.0
env: polyfill='false'
install: travis_retry composer install --no-interaction --prefer-source
before_script:
- travis_retry composer self-update
- travis_retry composer install --no-interaction --prefer-source
- if [[ $polyfill = 'false' ]]; then travis_retry composer remove symfony/polyfill-mbstring; fi
script:
- vendor/bin/phpunit

View File

@@ -1,3 +1,47 @@
### 2.4.0 (2017-03-02)
* Add startsWithAny
* Add endsWithAny
* Add stripWhitespace
* Fix error handling for unsupported encodings
* Change private methods to protected for extending class
* Fix safeTruncate for strings without spaces
* Additional char support in toAscii, e.g. full width chars and wide
non-breaking space
### 2.3.2 (2016-05-02)
* Improve support without mbstring
### 2.3.1 (2016-03-21)
* Always use root namespace for mbstring functions
### 2.3.0 (2016-03-19)
* Add Persian characters in Stringy::charsArray()
* Use symfony/polyfill-mbstring to avoid dependency on ext-mbstring
### 2.2.0 (2015-12-20)
* isJSON now returns false for empty strings
* Update for German umlaut transformation
* Use reflection to generate method list for StaticStringy
* Added isBase64 method
* Improved toAscii char coverage
### 2.1.0 (2015-09-02)
* Added simplified StaticStringy class
* str in Stringy::create and constructor is now optional
### 2.0.0 (2015-07-29)
* Removed StaticStringy class
* Added append, prepend, toBoolean, repeat, between, slice, split, and lines
* camelize/upperCamelize now strip leading dashes and underscores
* titleize converts to lowercase, thus no longer preserving acronyms
### 1.10.0 (2015-07-22)
* Added trimLeft, trimRight

1164
README.md

File diff suppressed because it is too large Load Diff

View File

@@ -16,7 +16,7 @@
],
"require": {
"php": ">=5.3.0",
"ext-mbstring": "*"
"symfony/polyfill-mbstring": "~1.1"
},
"require-dev": {
"phpunit/phpunit": "~4.0"

View File

@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit processIsolation="false"
<phpunit bootstrap="vendor/autoload.php"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
<testsuites>
<testsuite name="Stringy">
<file>tests/CommonTest.php</file>
<file>tests/StringyTest.php</file>
<file>tests/StaticStringyTest.php</file>
<file phpVersion="5.6.0">tests/CreateTest.php</file>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,5 @@
<?php
require __DIR__ . '/../src/Create.php';
use function Stringy\create as s;
class CreateTestCase extends PHPUnit_Framework_TestCase

View File

@@ -1,710 +1,60 @@
<?php
require __DIR__ . '/../src/StaticStringy.php';
use Stringy\StaticStringy as S;
class StaticStringyTestCase extends CommonTest
class StaticStringyTestCase extends PHPUnit_Framework_TestCase
{
/**
* @dataProvider indexOfProvider()
/**
* @expectedException BadMethodCallException
*/
public function testIndexOf($expected, $str, $subStr, $offset = 0, $encoding = null)
public function testBadMethodCall()
{
$result = S::indexOf($str, $subStr, $offset, $encoding);
$this->assertEquals($expected, $result);
$result = S::invalidMethod('foo');
}
public function testEmptyArgsInvocation()
{
$result = S::toLowerCase();
$this->assertEquals('', (string) $result);
}
public function testInvocation()
{
$result = S::toLowerCase('FOOBAR');
$this->assertEquals('foobar', (string) $result);
}
public function testPartialArgsInvocation()
{
$result = S::slice('foobar', 0, 3);
$this->assertEquals('foo', (string) $result);
}
public function testFullArgsInvocation()
{
$result = S::slice('fòôbàř', 0, 3, 'UTF-8');
$this->assertEquals('fòô', (string) $result);
}
/**
* @dataProvider indexOfLastProvider()
* Use reflection to ensure that all argument numbers are correct. Each
* static method should accept 2 more arguments than their Stringy
* equivalent.
*/
public function testIndexOfLast($expected, $str, $subStr, $offset = 0, $encoding = null)
public function testArgumentNumbers()
{
$result = S::indexOfLast($str, $subStr, $offset, $encoding);
$this->assertEquals($expected, $result);
}
$staticStringyClass = new ReflectionClass('Stringy\StaticStringy');
$stringyClass = new ReflectionClass('Stringy\Stringy');
/**
* @dataProvider charsProvider()
*/
public function testChars($expected, $str, $encoding = null)
{
$result = S::chars($str, $encoding);
$this->assertInternalType('array', $result);
foreach ($result as $char) {
$this->assertInternalType('string', $char);
// getStaticPropertyValue can't access protected properties
$properties = $staticStringyClass->getStaticProperties();
foreach ($properties['methodArgs'] as $method => $expected) {
$num = $stringyClass->getMethod($method)
->getNumberOfParameters() + 2;
$this->assertEquals($expected, $num,
'Invalid num args for ' . $method);
}
$this->assertEquals($expected, $result);
}
/**
* @dataProvider upperCaseFirstProvider()
*/
public function testUpperCaseFirst($expected, $str, $encoding = null)
{
$result = S::upperCaseFirst($str, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider lowerCaseFirstProvider()
*/
public function testLowerCaseFirst($expected, $str, $encoding = null)
{
$result = S::lowerCaseFirst($str, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider camelizeProvider()
*/
public function testCamelize($expected, $str, $encoding = null)
{
$result = S::camelize($str, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider upperCamelizeProvider()
*/
public function testUpperCamelize($expected, $str, $encoding = null)
{
$result = S::upperCamelize($str, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider dasherizeProvider()
*/
public function testDasherize($expected, $str, $encoding = null)
{
$result = S::dasherize($str, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider underscoredProvider()
*/
public function testUnderscored($expected, $str, $encoding = null)
{
$result = S::underscored($str, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider swapCaseProvider()
*/
public function testSwapCase($expected, $str, $encoding = null)
{
$result = S::swapCase($str, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider titleizeProvider()
*/
public function testTitleize($expected, $str, $ignore = null,
$encoding = null)
{
$result = S::titleize($str, $ignore, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider humanizeProvider()
*/
public function testHumanize($expected, $str, $encoding = null)
{
$result = S::humanize($str, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider tidyProvider()
*/
public function testTidy($expected, $str)
{
$result = S::tidy($str);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider collapseWhitespaceProvider()
*/
public function testCollapseWhitespace($expected, $str, $encoding = null)
{
$result = S::collapseWhitespace($str, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider toAsciiProvider()
*/
public function testToAscii($expected, $str, $removeUnsupported = true)
{
$result = S::toAscii($str, $removeUnsupported);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider padProvider()
*/
public function testPad($expected, $str, $length, $padStr = ' ',
$padType = 'right', $encoding = null)
{
$result = S::pad($str, $length, $padStr, $padType, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @expectedException \InvalidArgumentException
*/
public function testPadException()
{
$result = S::pad('string', 5, 'foo', 'bar');
}
/**
* @dataProvider padLeftProvider()
*/
public function testPadLeft($expected, $str, $length, $padStr = ' ',
$encoding = null)
{
$result = S::padLeft($str, $length, $padStr, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider padRightProvider()
*/
public function testPadRight($expected, $str, $length, $padStr = ' ',
$encoding = null)
{
$result = S::padRight($str, $length, $padStr, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider padBothProvider()
*/
public function testPadBoth($expected, $str, $length, $padStr = ' ',
$encoding = null)
{
$result = S::padBoth($str, $length, $padStr, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider startsWithProvider()
*/
public function testStartsWith($expected, $str, $substring,
$caseSensitive = true, $encoding = null)
{
$result = S::startsWith($str, $substring, $caseSensitive, $encoding);
$this->assertInternalType('boolean', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider endsWithProvider()
*/
public function testEndsWith($expected, $str, $substring,
$caseSensitive = true, $encoding = null)
{
$result = S::endsWith($str, $substring, $caseSensitive, $encoding);
$this->assertInternalType('boolean', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider toSpacesProvider()
*/
public function testToSpaces($expected, $str, $tabLength = 4)
{
$result = S::toSpaces($str, $tabLength);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider toTabsProvider()
*/
public function testToTabs($expected, $str, $tabLength = 4)
{
$result = S::toTabs($str, $tabLength);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider toLowerCaseProvider()
*/
public function testToLowerCase($expected, $str, $encoding = null)
{
$result = S::toLowerCase($str, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider toTitleCaseProvider()
*/
public function testToTitleCase($expected, $str, $encoding = null)
{
$result = S::toTitleCase($str, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider toUpperCaseProvider()
*/
public function testToUpperCase($expected, $str, $encoding = null)
{
$result = S::toUpperCase($str, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider slugifyProvider()
*/
public function testSlugify($expected, $str, $replacement = '-')
{
$result = S::slugify($str, $replacement);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider containsProvider()
*/
public function testContains($expected, $haystack, $needle,
$caseSensitive = true, $encoding = null)
{
$result = S::contains($haystack, $needle, $caseSensitive, $encoding);
$this->assertInternalType('boolean', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider containsAnyProvider()
*/
public function testcontainsAny($expected, $haystack, $needles,
$caseSensitive = true, $encoding = null)
{
$result = S::containsAny($haystack, $needles, $caseSensitive, $encoding);
$this->assertInternalType('boolean', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider containsAllProvider()
*/
public function testContainsAll($expected, $haystack, $needles,
$caseSensitive = true, $encoding = null)
{
$result = S::containsAll($haystack, $needles, $caseSensitive, $encoding);
$this->assertInternalType('boolean', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider surroundProvider()
*/
public function testSurround($expected, $str, $substring)
{
$result = S::surround($str, $substring);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider insertProvider()
*/
public function testInsert($expected, $str, $substring, $index,
$encoding = null)
{
$result = S::insert($str, $substring, $index, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider truncateProvider()
*/
public function testTruncate($expected, $str, $length, $substring = '',
$encoding = null)
{
$result = S::truncate($str, $length, $substring, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider safeTruncateProvider()
*/
public function testSafeTruncate($expected, $str, $length, $substring = '',
$encoding = null)
{
$result = S::safeTruncate($str, $length, $substring, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider reverseProvider()
*/
public function testReverse($expected, $str, $encoding = null)
{
$result = S::reverse($str, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider shuffleProvider()
*/
public function testShuffle($str, $encoding = null)
{
$result = S::shuffle($str, $encoding);
$encoding = $encoding ?: mb_internal_encoding();
$this->assertInternalType('string', $result);
$this->assertEquals(mb_strlen($str, $encoding),
mb_strlen($result, $encoding));
// We'll make sure that the chars are present after shuffle
for ($i = 0; $i < mb_strlen($str, $encoding); $i++) {
$char = mb_substr($str, $i, 1, $encoding);
$countBefore = mb_substr_count($str, $char, $encoding);
$countAfter = mb_substr_count($result, $char, $encoding);
$this->assertEquals($countBefore, $countAfter);
}
}
/**
* @dataProvider trimProvider()
*/
public function testTrim($expected, $str, $chars = null, $encoding = null)
{
$result = S::trim($str, $chars, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider trimLeftProvider()
*/
public function testTrimLeft($expected, $str, $chars = null,
$encoding = null)
{
$result = S::trimLeft($str, $chars, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider trimRightProvider()
*/
public function testTrimRight($expected, $str, $chars = null,
$encoding = null)
{
$result = S::trimRight($str, $chars, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider longestCommonPrefixProvider()
*/
public function testLongestCommonPrefix($expected, $str, $otherStr,
$encoding = null)
{
$result = S::longestCommonPrefix($str, $otherStr, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider longestCommonSuffixProvider()
*/
public function testLongestCommonSuffix($expected, $str, $otherStr,
$encoding = null)
{
$result = S::longestCommonSuffix($str, $otherStr, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider longestCommonSubstringProvider()
*/
public function testLongestCommonSubstring($expected, $str, $otherStr,
$encoding = null)
{
$result = S::longestCommonSubstring($str, $otherStr, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider lengthProvider()
*/
public function testLength($expected, $str, $encoding = null)
{
$result = S::length($str, $encoding);
$this->assertEquals($expected, $result);
$this->assertInternalType('int', $result);
}
/**
* @dataProvider substrProvider()
*/
public function testSubstr($expected, $str, $start, $length = null,
$encoding = null)
{
$result = S::substr($str, $start, $length, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider atProvider()
*/
public function testAt($expected, $str, $index, $encoding = null)
{
$result = S::at($str, $index, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider firstProvider()
*/
public function testFirst($expected, $str, $n, $encoding = null)
{
$result = S::first($str, $n, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider lastProvider()
*/
public function testLast($expected, $str, $n, $encoding = null)
{
$result = S::last($str, $n, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider ensureLeftProvider()
*/
public function testEnsureLeft($expected, $str, $substring, $encoding = null)
{
$result = S::ensureLeft($str, $substring, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider ensureRightProvider()
*/
public function testEnsureRight($expected, $str, $substring, $encoding = null)
{
$result = S::ensureRight($str, $substring, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider removeLeftProvider()
*/
public function testRemoveLeft($expected, $str, $substring, $encoding = null)
{
$result = S::removeLeft($str, $substring, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider removeRightProvider()
*/
public function testRemoveRight($expected, $str, $substring, $encoding = null)
{
$result = S::removeRight($str, $substring, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider isAlphaProvider()
*/
public function testIsAlpha($expected, $str, $encoding = null)
{
$result = S::isAlpha($str, $encoding);
$this->assertInternalType('boolean', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider isAlphanumericProvider()
*/
public function testIsAlphanumeric($expected, $str, $encoding = null)
{
$result = S::isAlphanumeric($str, $encoding);
$this->assertInternalType('boolean', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider isBlankProvider()
*/
public function testIsBlank($expected, $str, $encoding = null)
{
$result = S::isBlank($str, $encoding);
$this->assertInternalType('boolean', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider isJsonProvider()
*/
public function testIsJson($expected, $str, $encoding = null)
{
$result = S::isJson($str, $encoding);
$this->assertInternalType('boolean', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider isLowerCaseProvider()
*/
public function testIsLowerCase($expected, $str, $encoding = null)
{
$result = S::isLowerCase($str, $encoding);
$this->assertInternalType('boolean', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider hasLowerCaseProvider()
*/
public function testHasLowerCase($expected, $str, $encoding = null)
{
$result = S::hasLowerCase($str, $encoding);
$this->assertInternalType('boolean', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider isSerializedProvider()
*/
public function testIsSerialized($expected, $str, $encoding = null)
{
$result = S::isSerialized($str, $encoding);
$this->assertInternalType('boolean', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider isUpperCaseProvider()
*/
public function testIsUpperCase($expected, $str, $encoding = null)
{
$result = S::isUpperCase($str, $encoding);
$this->assertInternalType('boolean', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider hasUpperCaseProvider()
*/
public function testHasUpperCase($expected, $str, $encoding = null)
{
$result = S::hasUpperCase($str, $encoding);
$this->assertInternalType('boolean', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider isHexadecimalProvider()
*/
public function testIsHexadecimal($expected, $str, $encoding = null)
{
$result = S::isHexadecimal($str, $encoding);
$this->assertInternalType('boolean', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider countSubstrProvider()
*/
public function testCountSubstr($expected, $str, $substring,
$caseSensitive = true, $encoding = null)
{
$result = S::countSubstr($str, $substring, $caseSensitive, $encoding);
$this->assertInternalType('int', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider replaceProvider()
*/
public function testReplace($expected, $str, $search, $replacement,
$encoding = null)
{
$result = S::replace($str, $search, $replacement, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider regexReplaceProvider()
*/
public function testRegexReplace($expected, $str, $pattern, $replacement,
$options = 'msr', $encoding = null)
{
$result = S::regexReplace($str, $pattern, $replacement, $options, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider htmlEncodeProvider()
*/
public function testHtmlEncode($expected, $str, $flags = ENT_COMPAT, $encoding = null)
{
$result = S::htmlEncode($str, $flags, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider htmlDecodeProvider()
*/
public function testHtmlDecode($expected, $str, $flags = ENT_COMPAT, $encoding = null)
{
$result = S::htmlDecode($str, $flags, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
}

File diff suppressed because it is too large Load Diff