*/
private function getClassInfo($className) {
$classNameHash = sha1($className);
+ $classInfo = $this->getClassInfoCache()->get($classNameHash);
- // we also need to make sure that the cache is returning a vaild object
- // in case something went wrong with unserialization etc..
- if (!$this->getClassInfoCache()->has($classNameHash) || !is_object($this->getClassInfoCache()->get($classNameHash))) {
- $this->getClassInfoCache()->set($classNameHash, $this->getClassInfoFactory()->buildClassInfoFromClassName($className));
+ if (!$classInfo instanceof Tx_Extbase_Object_Container_ClassInfo) {
+ $classInfo = $this->getClassInfoFactory()->buildClassInfoFromClassName($className);
+ $this->getClassInfoCache()->set($classNameHash, $classInfo);
}
- return $this->getClassInfoCache()->get($classNameHash);
+ return $classInfo;
}
}
-?>
\ No newline at end of file
+?>
public function setUp() {
//our mocked cache will allways indicate that he has nothing in the cache to force that we get the real classinfo
- $mockedCache = $this->getMock('Tx_Extbase_Object_Container_ClassInfoCache',array('has'));
- $mockedCache->expects($this->any())->method('has')->will($this->returnValue(false));
+ $mockedCache = $this->getMock('Tx_Extbase_Object_Container_ClassInfoCache', array('get'));
+ $mockedCache->expects($this->any())->method('get')->will($this->returnValue(FALSE));
+ $mockedCache->expects($this->never())->method('has');
- $this->container = $this->getMock('Tx_Extbase_Object_Container_Container', array('log','getClassInfoCache'));
+ $this->container = $this->getMock('Tx_Extbase_Object_Container_Container', array('log', 'getClassInfoCache'));
$this->container->expects($this->any())->method('getClassInfoCache')->will($this->returnValue($mockedCache));
}
$container = $this->getMock('Tx_Extbase_Object_Container_Container', array('log', 'getClassInfoCache'));
$container->expects($this->any())->method('getClassInfoCache')->will($this->returnValue($mockedCache));
- $mockedCache->expects($this->any())->method('has')->will($this->returnValue(FALSE));
+ $mockedCache->expects($this->never())->method('has');
+ $mockedCache->expects($this->once())->method('get')->with($classNameHash)->will($this->returnValue(FALSE));
$mockedCache->expects($this->once())->method('set')->with($classNameHash, $this->anything())->will($this->returnCallback(array($this, 'setClassInfoCacheCallback')));
- $mockedCache->expects($this->once())->method('get')->with($classNameHash)->will($this->returnCallback(array($this, 'getClassInfoCacheCallback')));
$container->getInstance($className);
+
+ $this->assertInstanceOf('Tx_Extbase_Object_Container_ClassInfo', $this->cachedClassInfo);
+ $this->assertEquals($className, $this->cachedClassInfo->getClassName());
}
/**
$this->cachedClassInfo = $value;
}
- /**
- * Callback for getInstanceUsesClassNameSha1AsCacheKey
- *
- * @param string $id
- * @return Tx_Extbase_Object_Container_ClassInfo
- */
- public function getClassInfoCacheCallback($id) {
- return $this->cachedClassInfo;
- }
-
/**
* @test
*/