public function testMultipleObjectTypes() { // we should be able to add multiple objects of multiple classes $objA1 = InstancePoolTestObject::constructFromHardCodedData(1); $objA2 = InstancePoolTestObject::constructFromHardCodedData(2); $objB1 = InstancePoolTestObject2::constructFromHardCodedData(1); $objB2 = InstancePoolTestObject2::constructFromHardCodedData(2); // verify the objects we have are in fact different $uniqueEntities = array(); $uniqueEntities[get_class($objA1) . '-' . $objA1->getKeyId()] = true; $uniqueEntities[get_class($objA2) . '-' . $objA2->getKeyId()] = true; $uniqueEntities[get_class($objB1) . '-' . $objB1->getKeyId()] = true; $uniqueEntities[get_class($objB2) . '-' . $objB2->getKeyId()] = true; $this->assertTrue(count($uniqueEntities) == 4, 'The instance pool test objects are messed up'); // add them all CoughInstancePool::add($objA1, $objA1->getKeyId()); CoughInstancePool::add($objA2, $objA2->getKeyId()); CoughInstancePool::add($objB1, $objB1->getKeyId()); CoughInstancePool::add($objB2, $objB2->getKeyId()); // check they all come back good $this->assertIdentical($objA1, CoughInstancePool::get(get_class($objA1), $objA1->getKeyId())); $this->assertIdentical($objA2, CoughInstancePool::get(get_class($objA2), $objA2->getKeyId())); $this->assertIdentical($objB1, CoughInstancePool::get(get_class($objB1), $objB1->getKeyId())); $this->assertIdentical($objB2, CoughInstancePool::get(get_class($objB2), $objB2->getKeyId())); // remove two at random and check that they are gone and the others are still good CoughInstancePool::remove(get_class($objB1), $objB1->getKeyId()); CoughInstancePool::remove(get_class($objA2), $objA2->getKeyId()); $this->assertNull(CoughInstancePool::get(get_class($objB1), $objB1->getKeyId())); $this->assertNull(CoughInstancePool::get(get_class($objA2), $objA2->getKeyId())); $this->assertIdentical($objA1, CoughInstancePool::get(get_class($objA1), $objA1->getKeyId())); $this->assertIdentical($objB2, CoughInstancePool::get(get_class($objB2), $objB2->getKeyId())); }
public static function removeAll() { self::$instances = array(); return true; }