Permalink
Browse files

Merge branch 'hotfix/2987'

Close #2987
  • Loading branch information...
2 parents 8b75516 + f153662 commit 0a74c75a05c1b0a36d9ae79d0a014c6f25d4e5a6 @weierophinney weierophinney committed Nov 19, 2012
Showing with 28 additions and 0 deletions.
  1. +17 −0 library/Zend/Session/Container.php
  2. +11 −0 tests/ZendTest/Session/ContainerTest.php
View
17 library/Zend/Session/Container.php
@@ -439,6 +439,23 @@ public function offsetUnset($key)
}
/**
+ * Exchange the current array with another array or object.
+ *
+ * @param array|object $input
+ * @return array Returns the old array
+ * @see ArrayObject::exchangeArray()
+ */
+ public function exchangeArray($input)
+ {
+ $storage = $this->verifyNamespace();
+ $name = $this->getName();
+
+ $old = $storage[$name];
+ $storage[$name] = $input;
+ return (array) $old;
+ }
+
+ /**
* Iterate over session container
*
* @return Iterator
View
11 tests/ZendTest/Session/ContainerTest.php
@@ -515,4 +515,15 @@ public function testValidationShouldNotRaiseErrorForMissingResponseObject()
$session->test = 42;
$this->assertEquals(42, $session->test);
}
+
+ public function testExchangeArray()
+ {
+ $this->container->offsetSet('old', 'old');
+ $this->assertTrue($this->container->offsetExists('old'));
+
+ $old = $this->container->exchangeArray(array('new' => 'new'));
+ $this->assertArrayHasKey('old', $old, "'exchangeArray' doesn't return an array of old items");
+ $this->assertFalse($this->container->offsetExists('old'), "'exchangeArray' doesn't remove old items");
+ $this->assertTrue($this->container->offsetExists('new'), "'exchangeArray' doesn't add the new array items");
+ }
}

0 comments on commit 0a74c75

Please sign in to comment.