Add tests for hasChanged, set/getByRef and fix setByRef

This commit is contained in:
Johannes Meyer 2014-09-17 11:05:35 +02:00
parent 6f988cb94c
commit 635b802a2b
2 changed files with 37 additions and 1 deletions

View File

@ -111,7 +111,7 @@ class SessionNamespace implements IteratorAggregate
public function setByRef($key, &$value)
{
$this->values[$key] = $value;
$this->values[$key] = & $value;
if (in_array($key, $this->removed)) {
unset($this->removed[array_search($key, $this->removed)]);

View File

@ -84,4 +84,40 @@ class SessionNamespaceTest extends BaseTestCase
$this->assertEquals($value, $values[$key]);
}
}
public function testRetrievingValuesByReferenceWorks()
{
$ns = new SessionNamespace();
$ns->array = array(1, 2);
$array = & $ns->getByRef('array');
$array[0] = 11;
$this->assertEquals(
array(11, 2),
$ns->array,
'Values retrieved with getByRef() seem not be affected by external changes'
);
}
public function testSettingValuesByReferenceWorks()
{
$ns = new SessionNamespace();
$array = array(1, 2);
$ns->setByRef('array', $array);
$array[0] = 11;
$this->assertEquals(
array(11, 2),
$ns->array,
'Values set with setByRef() seem not to receive external changes'
);
}
public function testTrackingChangesWorks()
{
$ns = new SessionNamespace();
$this->assertFalse($ns->hasChanged(), 'A new empty session namespace seems to have changes');
$ns->test = 1;
$this->assertTrue($ns->hasChanged(), 'A new session namespace with values seems not to have changes');
}
}