data as $id => $class ) { $location = $this->createTempDir($class); ezcCacheManager::createCache( $id, $location, $class ); $realCache = ezcCacheManager::getCache( $id ); $fakeCache = new $class( realpath( $location ) ); $this->assertEquals( $realCache, $fakeCache, 'Invalid object created from ezcCacheManager. Expected "' . get_class( $realCache ) . '", found "'. get_class( $fakeCache ) .'".' ); unset( $realCache ); unset( $fakeCache ); $this->removeTempDir($location); } $this->assertTrue( true ); } public function testManagerCreateCache_Failure() { $id = 0; // First try to create cache in invalid location. try { $cache = ezcCacheManager::createCache( $id, '/fckgw', $this->data[$id] ); } catch ( ezcCacheManagerException $e ) { $this->assertEquals( $e->getCode(), ezcCacheManagerException::INVALID_LOCATION, 'Wrong exception thrown on non-existant location .' ); } // Second try, allocate a cache succesfully $location = $this->createTempDir($this->data[$id]); $cache = ezcCacheManager::createCache( $id, $location, $this->data[$id] ); // Use next cache class/location. $id++; $caughtException = false; try { // Use current ID with last IDs location ezcCacheManager::createCache( $id, $location, $this->data[$id] ); } catch ( ezcCacheManagerException $e ) { $this->assertEquals( $e->getCode(), ezcCacheManagerException::USED_LOCATION, 'Wrong exception thrown on used location <'.$location.'>.' ); $caughtException = true; } if ( $caughtException === false ) { $this->fail('Exception not thrown on used location <'.$location.'>.'); } $this->removeTempDir($location); // Use next cache class/location. $id++; $caughtException = false; $location = $this->createTempDir($this->data[$id]); try { // Use current ID with non-existant cache class ezcCacheManager::createCache( $id, $location, 'Test' ); } catch ( ezcCacheManagerException $e ) { $this->assertEquals( $e->getCode(), ezcCacheManagerException::INVALID_STORAGE_CLASS, 'Wrong exception thrown on invalid storage class .' ); $caughtException = true; } if ( $caughtException === false ) { $this->fail('Wrong exception thrown on invalid storage class .'); } $this->removeTempDir($location); } /** * Success tests already included in testCreateCache_Success() */ public function testGetCache_Failure() { try { $cache = ezcCacheManager::getCache( 'unknnown' ); } catch ( ezcCacheManagerException $e ) { $this->assertEquals( $e->getCode(), ezcCacheManagerException::INVALID_ID, 'Cache manager threw incorrect exception' ); } } } ?>