From 678da22fb9ef0d7696b7ef0e00835d43dcbf09b1 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Sat, 3 Sep 2011 12:17:21 +0200 Subject: [PATCH] Add IdentityMap tests. --- tests/unit/framework/IdentityMapTest.php | 82 ++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 tests/unit/framework/IdentityMapTest.php diff --git a/tests/unit/framework/IdentityMapTest.php b/tests/unit/framework/IdentityMapTest.php new file mode 100644 index 0000000..a81701d --- /dev/null +++ b/tests/unit/framework/IdentityMapTest.php @@ -0,0 +1,82 @@ +assertAttributeEmpty('idToObject', $map); + $this->assertAttributeCount(0, 'objectToId', $map); + + return $map; + } + + /** + * @covers IdentityMap::set + * @depends testIsInitiallyEmpty + */ + public function testObjectCanBeAdded(IdentityMap $map) + { + $map->set(1, self::$object); + + $idToObject = $this->readAttribute($map, 'idToObject'); + $objectToId = $this->readAttribute($map, 'objectToId'); + + $this->assertContains(self::$object, $idToObject); + $this->assertContains(self::$object, $objectToId); + + return $map; + } + + /** + * @covers IdentityMap::getObject + * @covers IdentityMap::hasId + * @depends testObjectCanBeAdded + */ + public function testObjectCanBeRetrievedById(IdentityMap $map) + { + $this->assertSame(self::$object, $map->getObject(1)); + } + + /** + * @covers IdentityMap::getObject + * @depends testObjectCanBeAdded + * @expectedException OutOfBoundsException + */ + public function testExceptionIsRaisedForNonExistantId(IdentityMap $map) + { + $map->getObject(0); + } + + /** + * @covers IdentityMap::getId + * @covers IdentityMap::hasObject + * @depends testObjectCanBeAdded + */ + public function testIdCanBeRetrievedForObject(IdentityMap $map) + { + $this->assertEquals(1, $map->getId(self::$object)); + } + + /** + * @covers IdentityMap::getId + * @depends testObjectCanBeAdded + * @expectedException OutOfBoundsException + */ + public function testExceptionIsRaisedForNonExistantObject(IdentityMap $map) + { + $map->getId(new StdClass); + } +}