"Test 1 2 3 4 5 6 7 8\\\\", 2 => 'La la la 02064 lololo', 3 => 12345, 4 => 12.3746, ); protected function setUp() { if ( !ezcBaseFeatures::hasExtensionSupport( 'apc' ) ) { $this->markTestSkipped( "PHP must have APC support." ); } // Class name == - "Test" $storageClass = ( $this->storageClass = substr( get_class( $this ), 0, strlen( get_class( $this ) ) - 4 ) ); $this->storage = new $storageClass( $this->createTempDir( 'ezcCacheTest' ), array( 'ttl' => 10 ) ); } // Override test from parent class public function testConstructorErrorLocationNotWriteable() { return true; } // Override test from parent class public function testStoreRestoreOutdatedWithoutAttributes() { $options = array( 'ttl' => 10 ); $storage = new ezcCacheStorageApcWrapper( $this->getTempDir(), $options ); foreach ( $this->data as $id => $dataArr ) { $storage->store( $id, $dataArr ); // Hack the cache to be outdated by 100 seconds $data = $storage->restore( $id ); $registry = $storage->getRegistry(); $location = $this->getTempDir() . DIRECTORY_SEPARATOR; list( $identifier, $dataObj ) = each( $registry[$location][$id] ); $registry[$location][$id][$identifier]->time = time() - 100; $storage->setRegistry( $registry ); $data = $storage->restore( $id ); $this->assertTrue( $data === false, "Restore data broken for ID <{$id}>." ); } } // Override test from parent class public function testStoreRestoreOutdatedWithAttributes() { $options = array( 'ttl' => 10 ); $storage = new ezcCacheStorageApcWrapper( $this->getTempDir(), $options ); foreach ( $this->data as $id => $dataArr ) { $attributes = array( 'name' => 'test', 'title' => 'Test item', 'date' => time() . $id, ); $storage->store( $id, $dataArr, $attributes ); // Hack the cache to be outdated by 100 seconds $data = $storage->restore( $id, $attributes ); $registry = $storage->getRegistry(); $location = $this->getTempDir() . DIRECTORY_SEPARATOR; list( $identifier, $dataObj ) = each( $registry[$location][$id] ); $registry[$location][$id][$identifier]->time = time() - 100; $storage->setRegistry( $registry ); // Wait for cache to be outdated. $data = $storage->restore( $id, $attributes ); $this->assertTrue( $data === false, "Restore data broken for ID <{$id}>." ); } } public function testMockApcBackend() { $apcBackend = $this->getMock( 'ezcCacheApcBackend', array( 'store' ), array() ); $apcBackend->expects( $this->any() ) ->method( 'store' ) ->will( $this->returnValue( false ) ); $options = array( 'ttl' => 10 ); $storage = new ezcCacheStorageApcWrapper( '.', $options ); $storage->setBackend( $apcBackend ); $id = 'id'; try { $storage->store( $id, 'data' ); $this->fail( "Expected exception was not thrown." ); } catch ( ezcCacheApcException $e ) { $this->assertEquals( "Apc store failed.", $e->getMessage() ); } } public function testStoreResource() { $resource = fopen( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'wrappers' . DIRECTORY_SEPARATOR . 'apc_wrapper.php', 'r' ); try { $this->storage->store( "key", $resource ); fclose( $resource ); $this->fail( "Expected exception was not thrown." ); } catch ( ezcCacheInvalidDataException $e ) { fclose( $resource ); $this->assertEquals( "The given data was of type 'resource', which can not be stored. Expecting: 'simple, array, object'.", $e->getMessage() ); } } public function testGetRemainingLifetimeId() { $this->storage->setOptions( array( 'ttl' => 10 ) ); $this->storage->store( '1', 'data1' ); // "8 <= " - for those cases where the current second changes after the storage $this->assertEquals( true, 8 <= $this->storage->getRemainingLifetime( '1' ) ); } public function testGetRemainingLifetimeAttributes() { $this->storage->setOptions( array( 'ttl' => 10 ) ); $this->storage->store( '1', 'data1', array( 'type' => 'simple' ) ); $this->storage->store( '2', 'data2', array( 'type' => 'simple' ) ); // "8 <= " - for those cases where the current second changes after the storage $this->assertEquals( true, 8 <= $this->storage->getRemainingLifetime( null, array( 'type' => 'simple' ) ) ); } public function testGetRemainingLifetimeNoMatch() { $this->storage->setOptions( array( 'ttl' => 10 ) ); $this->assertEquals( 0, $this->storage->getRemainingLifetime( 'no_such_id' ) ); } public function testCacheManagerLocationEmpty() { $options = array( 'ttl' => 10 ); ezcCacheManager::createCache( 'cache', null, 'ezcCacheStorageApcPlain', $options ); $storage = ezcCacheManager::getCache( 'cache' ); $storage->store( 'key', 'data' ); $this->assertEquals( 'data', $storage->restore( 'key' ) ); } public function testStorageApcOptions() { $options = new ezcCacheStorageApcOptions(); $this->invalidPropertyTest( $options, 'ttl', 'wrong value', 'int > 0 or false' ); $this->missingPropertyTest( $options, 'no_such_option' ); $this->issetPropertyTest( $options, 'ttl', true ); $this->issetPropertyTest( $options, 'no_such_option', false ); } public static function suite() { return new PHPUnit_Framework_TestSuite( __CLASS__ ); } } ?>