server = new Zend_Json_Server(); $this->server->setClass('Zend_Json_Server_CacheTest_Foo', 'foo'); $this->cacheFile = tempnam(sys_get_temp_dir(), 'zjs'); // if (!is_writeable(dirname(__FILE__))) { if (!is_writeable($this->cacheFile)) { $this->markTestSkipped('Cannot write test caches due to permissions'); } if (file_exists($this->cacheFile)) { unlink($this->cacheFile); } } /** * Tears down the fixture, for example, close a network connection. * This method is called after a test is executed. * * @return void */ public function tearDown() { if (file_exists($this->cacheFile)) { unlink($this->cacheFile); } } public function testRetrievingSmdCacheShouldReturnFalseIfCacheDoesNotExist() { $this->assertFalse(Zend_Json_Server_Cache::getSmd($this->cacheFile)); } public function testSavingSmdCacheShouldReturnTrueOnSuccess() { $this->assertTrue(Zend_Json_Server_Cache::saveSmd($this->cacheFile, $this->server)); } public function testSavedCacheShouldMatchGeneratedCache() { $this->testSavingSmdCacheShouldReturnTrueOnSuccess(); $json = $this->server->getServiceMap()->toJson(); $test = Zend_Json_Server_Cache::getSmd($this->cacheFile); $this->assertSame($json, $test); } public function testDeletingSmdShouldReturnFalseOnFailure() { $this->assertFalse(Zend_Json_Server_Cache::deleteSmd($this->cacheFile)); } public function testDeletingSmdShouldReturnTrueOnSuccess() { $this->testSavingSmdCacheShouldReturnTrueOnSuccess(); $this->assertTrue(Zend_Json_Server_Cache::deleteSmd($this->cacheFile)); } } /** * Class for testing JSON-RPC server caching */ class Zend_Json_Server_CacheTest_Foo { /** * Bar * * @param bool $one * @param string $two * @param mixed $three * @return array */ public function bar($one, $two = 'two', $three = null) { return array($one, $two, $three); } /** * Baz * * @return void */ public function baz() { throw new Exception('application error'); } } // Call Zend_Json_Server_CacheTest::main() if this source file is executed directly. if (PHPUnit_MAIN_METHOD == "Zend_Json_Server_CacheTest::main") { Zend_Json_Server_CacheTest::main(); }