mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-08-08 22:36:32 +02:00
Added $charList and $type to trim function
Adding the option to trim the string with others characters, not only with the default characters provided by php. Also added the option to define the function which will be used to trim the string, if it's normal trim, left trim or right trim
This commit is contained in:
@@ -594,9 +594,9 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider trimProvider()
|
||||
* @dataProvider trimProviderWithoutParams()
|
||||
*/
|
||||
public function testTrim($expected, $str)
|
||||
public function testTrimWithoutParams($expected, $str)
|
||||
{
|
||||
$stringy = S::create($str);
|
||||
$result = $stringy->trim();
|
||||
@@ -605,6 +605,40 @@ class StringyTestCase extends CommonTest
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider trimProviderWithParams()
|
||||
*/
|
||||
public function testTrimWithParams($expected, $str, $charList, $type)
|
||||
{
|
||||
$stringy = S::create($str);
|
||||
$result = $stringy->trim($charList, $type);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testTrimWithInvalidCharset()
|
||||
{
|
||||
$stringy = S::create('test');
|
||||
$stringy->trim(array('test1', 'test2'), 'trim');
|
||||
$this->fail('Expecting exception when the first argument passed is not a string');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testTrimWithInvalidType()
|
||||
{
|
||||
$stringy = S::create('test');
|
||||
$stringy->trim(' test ', 'aa');
|
||||
$stringy->trim('btest ', 'Trim');
|
||||
$stringy->trim(' btest', 'RTrim');
|
||||
$this->fail('Expecting exception when the first argument passed is not a string');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider longestCommonPrefixProvider()
|
||||
*/
|
||||
|
Reference in New Issue
Block a user