1
0
mirror of https://github.com/danielstjules/Stringy.git synced 2025-08-18 11:01:16 +02:00

Update ArrayAccess interface implementation, add details to readme

This commit is contained in:
Daniel St. Jules
2014-02-06 18:27:21 -05:00
parent ebc58a51ef
commit 3f5b6a2413
3 changed files with 83 additions and 101 deletions

View File

@@ -95,16 +95,26 @@ class StringyTestCase extends CommonTest
$this->assertEquals(array('F', 'ò', 'ô', ' ', 'B', 'à', 'ř'), $keyValResult);
}
public function testOffsetExists()
/**
* @dataProvider offsetExistsProvider()
*/
public function testOffsetExists($expected, $offset)
{
$stringy = S::create('fòô', 'UTF-8');
$this->assertEquals($expected, $stringy->offsetExists($offset));
$this->assertEquals($expected, isset($stringy[$offset]));
}
$this->assertTrue($stringy->offsetExists(0));
$this->assertTrue($stringy->offsetExists(2));
$this->assertFalse($stringy->offsetExists(3));
$this->assertTrue(isset($stringy[2]));
$this->assertFalse(isset($stringy[3]));
public function offsetExistsProvider()
{
return array(
array(true, 0),
array(true, 2),
array(false, 3),
array(true, -1),
array(true, -3),
array(false, -4)
);
}
public function testOffsetGet()
@@ -113,61 +123,35 @@ class StringyTestCase extends CommonTest
$this->assertEquals('f', $stringy->offsetGet(0));
$this->assertEquals('ô', $stringy->offsetGet(2));
$this->assertEquals(null, $stringy->offsetGet(3));
$this->assertEquals('ô', $stringy[2]);
$this->assertEquals(null, $stringy[3]);
}
/**
* @dataProvider offsetSetProvider()
* @expectedException \OutOfBoundsException
*/
public function testOffsetSet($expected, $offset, $value)
public function testOffsetGetOutOfBounds()
{
$stringy = S::create('fòô', 'UTF-8');
$stringy->offsetSet($offset, $value);
$this->assertEquals($expected, (string) $stringy);
$stringy = S::create('fòô', 'UTF-8');
$stringy[$offset] = $value;
$this->assertEquals($expected, (string) $stringy);
}
public function offsetSetProvider()
{
return array(
array('ôòô', 0, 'ô'),
array('fòo', 2, 'o'),
array('fòôô', 3, 'ô'),
array('fòôô', 8, 'ô'),
array('fòôô', null, 'ô'),
array('fô', 1, ''),
array('fbô', 1, 'bar')
);
$test = $stringy[3];
}
/**
* @dataProvider offsetUnsetProvider()
* @expectedException \Exception
*/
public function testOffsetUnset($expected, $offset)
public function testOffsetSet()
{
$stringy = S::create('fòô', 'UTF-8');
$stringy->offsetUnset($offset);
$this->assertEquals($expected, (string) $stringy);
$stringy = S::create('fòô', 'UTF-8');
unset($stringy[$offset]);
$this->assertEquals($expected, (string) $stringy);
$stringy[1] = 'invalid';
}
public function offsetUnsetProvider()
/**
* @expectedException \Exception
*/
public function testOffsetUnset()
{
return array(
array('òô', 0),
array('fô', 1),
array('fò', 2),
array('fòô', 3)
);
$stringy = S::create('fòô', 'UTF-8');
unset($stringy[1]);
}
/**