1
0
mirror of https://github.com/danielstjules/Stringy.git synced 2025-08-22 12:53:20 +02:00

Update replace() to correctly apply preg_quote to pattern and replacement

This commit is contained in:
Daniel St. Jules
2013-09-14 23:59:46 -04:00
parent 9bd5a9c0c8
commit 88145e83e8
6 changed files with 27 additions and 27 deletions

View File

@@ -925,12 +925,14 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
$testData = array(
array('', '', '', ''),
array('foo', '', '', 'foo'),
array('foo', '\s', '\s', 'foo'),
array('foo bar', 'foo bar', '', ''),
array('bar', 'foo bar', 'foo ', ''),
array('far bar', 'foo bar', 'foo', 'far'),
array('bar bar', 'foo bar foo bar', 'foo ', ''),
array('', '', '', '', 'UTF-8'),
array('fòô', '', '', 'fòô', 'UTF-8'),
array('fòô', '\s', '\s', 'fòô', 'UTF-8'),
array('fòô bàř', 'fòô bàř', '', '', 'UTF-8'),
array('bàř', 'fòô bàř', 'fòô ', '', 'UTF-8'),
array('far bàř', 'fòô bàř', 'fòô', 'far', 'UTF-8'),

View File

@@ -565,10 +565,10 @@ class StaticStringyTestCase extends CommonTest
/**
* @dataProvider stringsForReplace
*/
public function testReplace($expected, $str, $search, $replace,
public function testReplace($expected, $str, $search, $replacement,
$encoding = null)
{
$result = S::replace($str, $search, $replace, $encoding);
$result = S::replace($str, $search, $replacement, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}

View File

@@ -666,11 +666,11 @@ class StringyTestCase extends CommonTest
/**
* @dataProvider stringsForReplace
*/
public function testReplace($expected, $str, $search, $replace,
public function testReplace($expected, $str, $search, $replacement,
$encoding = null)
{
$stringy = S::create($str, $encoding);
$result = $stringy->replace($search, $replace);
$result = $stringy->replace($search, $replacement);
$this->assertInstanceOf('Stringy\Stringy', $result);
$this->assertEquals($expected, $result);
$this->assertEquals($str, $stringy);