Skip to content

Commit

Permalink
Add tests for hasChanged, set/getByRef and fix setByRef
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Meyer committed Sep 24, 2014
1 parent 6f988cb commit 635b802
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion library/Icinga/Web/Session/SessionNamespace.php
Expand Up @@ -111,7 +111,7 @@ public function set($key, $value)

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)]);
Expand Down
36 changes: 36 additions & 0 deletions test/php/library/Icinga/Web/Session/SessionNamespaceTest.php
Expand Up @@ -84,4 +84,40 @@ public function testIteration()
$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');
}
}

0 comments on commit 635b802

Please sign in to comment.