1
0
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:
Daniel St. Jules
2014-02-02 16:07:47 -05:00
parent 9f930262af
commit f14e8c16a4
6 changed files with 132 additions and 2 deletions

View File

@@ -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(

View File

@@ -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()
*/

View File

@@ -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()
*/