mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-08-13 00:34:11 +02:00
Implemented IteratorAggregate, added chars()
This commit is contained in:
@@ -2,6 +2,15 @@
|
||||
|
||||
abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function charsProvider()
|
||||
{
|
||||
return array(
|
||||
array(array(), ''),
|
||||
array(array('T', 'e', 's', 't'), 'Test'),
|
||||
array(array('F', 'ò', 'ô', ' ', 'B', 'à', 'ř'), 'Fòô Bàř', 'UTF-8')
|
||||
);
|
||||
}
|
||||
|
||||
public function upperCaseFirstProvider()
|
||||
{
|
||||
return array(
|
||||
|
@@ -7,6 +7,19 @@ use Stringy\StaticStringy as S;
|
||||
|
||||
class StaticStringyTestCase extends CommonTest
|
||||
{
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider upperCaseFirstProvider()
|
||||
*/
|
||||
|
@@ -70,6 +70,37 @@ class StringyTestCase extends CommonTest
|
||||
$this->assertEquals('FÒÔ bÀŘ', $result);
|
||||
}
|
||||
|
||||
public function testGetIterator()
|
||||
{
|
||||
$stringy = S::create('Fòô Bàř', 'UTF-8');
|
||||
|
||||
$valResult = [];
|
||||
foreach ($stringy as $char) {
|
||||
$valResult[] = $char;
|
||||
}
|
||||
|
||||
$keyValResult = [];
|
||||
foreach ($stringy as $pos => $char) {
|
||||
$keyValResult[$pos] = $char;
|
||||
}
|
||||
|
||||
$this->assertEquals(array('F', 'ò', 'ô', ' ', 'B', 'à', 'ř'), $valResult);
|
||||
$this->assertEquals(array('F', 'ò', 'ô', ' ', 'B', 'à', 'ř'), $keyValResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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()
|
||||
*/
|
||||
|
Reference in New Issue
Block a user