CacheTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_XmlRpc
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. // Call Zend_XmlRpc_Server_CacheTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_XmlRpc_Server_CacheTest::main");
  25. }
  26. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  27. require_once 'Zend/XmlRpc/Server.php';
  28. require_once 'Zend/XmlRpc/Server/Cache.php';
  29. /**
  30. * Test case for Zend_XmlRpc_Server_Cache
  31. *
  32. * @category Zend
  33. * @package Zend_XmlRpc
  34. * @subpackage UnitTests
  35. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. * @group Zend_XmlRpc
  38. */
  39. class Zend_XmlRpc_Server_CacheTest extends PHPUnit_Framework_TestCase
  40. {
  41. /**
  42. * Runs the test methods of this class.
  43. *
  44. * @return void
  45. */
  46. public static function main()
  47. {
  48. $suite = new PHPUnit_Framework_TestSuite("Zend_XmlRpc_Server_CacheTest");
  49. $result = PHPUnit_TextUI_TestRunner::run($suite);
  50. }
  51. /**
  52. * Zend_XmlRpc_Server object
  53. * @var Zend_XmlRpc_Server
  54. */
  55. protected $_server;
  56. /**
  57. * Local file for caching
  58. * @var string
  59. */
  60. protected $_file;
  61. /**
  62. * Setup environment
  63. */
  64. public function setUp()
  65. {
  66. $this->_file = realpath(dirname(__FILE__)) . '/xmlrpc.cache';
  67. $this->_server = new Zend_XmlRpc_Server();
  68. $this->_server->setClass('Zend_XmlRpc_Server_Cache', 'cache');
  69. }
  70. /**
  71. * Teardown environment
  72. */
  73. public function tearDown()
  74. {
  75. if (file_exists($this->_file)) {
  76. unlink($this->_file);
  77. }
  78. unset($this->_server);
  79. }
  80. /**
  81. * Tests functionality of both get() and save()
  82. */
  83. public function testGetSave()
  84. {
  85. if (!is_writeable('./')) {
  86. $this->markTestIncomplete('Directory no writable');
  87. }
  88. $this->assertTrue(Zend_XmlRpc_Server_Cache::save($this->_file, $this->_server));
  89. $expected = $this->_server->listMethods();
  90. $server = new Zend_XmlRpc_Server();
  91. $this->assertTrue(Zend_XmlRpc_Server_Cache::get($this->_file, $server));
  92. $actual = $server->listMethods();
  93. $this->assertSame($expected, $actual);
  94. }
  95. /**
  96. * Zend_XmlRpc_Server_Cache::delete() test
  97. */
  98. public function testDelete()
  99. {
  100. if (!is_writeable('./')) {
  101. $this->markTestIncomplete('Directory no writable');
  102. }
  103. $this->assertTrue(Zend_XmlRpc_Server_Cache::save($this->_file, $this->_server));
  104. $this->assertTrue(Zend_XmlRpc_Server_Cache::delete($this->_file));
  105. }
  106. public function testShouldReturnFalseWithInvalidCache()
  107. {
  108. if (!is_writeable('./')) {
  109. $this->markTestIncomplete('Directory no writable');
  110. }
  111. file_put_contents($this->_file, 'blahblahblah');
  112. $server = new Zend_XmlRpc_Server();
  113. $this->assertFalse(Zend_XmlRpc_Server_Cache::get($this->_file, $server));
  114. }
  115. }
  116. // Call Zend_XmlRpc_Server_CacheTest::main() if this source file is executed directly.
  117. if (PHPUnit_MAIN_METHOD == "Zend_XmlRpc_Server_CacheTest::main") {
  118. Zend_XmlRpc_Server_CacheTest::main();
  119. }