CacheTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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-2015 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 'Zend/XmlRpc/Server.php';
  27. require_once 'Zend/XmlRpc/Server/Cache.php';
  28. /**
  29. * Test case for Zend_XmlRpc_Server_Cache
  30. *
  31. * @category Zend
  32. * @package Zend_XmlRpc
  33. * @subpackage UnitTests
  34. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. * @group Zend_XmlRpc
  37. */
  38. class Zend_XmlRpc_Server_CacheTest extends PHPUnit_Framework_TestCase
  39. {
  40. /**
  41. * Runs the test methods of this class.
  42. *
  43. * @return void
  44. */
  45. public static function main()
  46. {
  47. $suite = new PHPUnit_Framework_TestSuite("Zend_XmlRpc_Server_CacheTest");
  48. $result = PHPUnit_TextUI_TestRunner::run($suite);
  49. }
  50. /**
  51. * Zend_XmlRpc_Server object
  52. * @var Zend_XmlRpc_Server
  53. */
  54. protected $_server;
  55. /**
  56. * Local file for caching
  57. * @var string
  58. */
  59. protected $_file;
  60. /**
  61. * Setup environment
  62. */
  63. public function setUp()
  64. {
  65. $this->_file = realpath(dirname(__FILE__)) . '/xmlrpc.cache';
  66. $this->_server = new Zend_XmlRpc_Server();
  67. $this->_server->setClass('Zend_XmlRpc_Server_Cache', 'cache');
  68. }
  69. /**
  70. * Teardown environment
  71. */
  72. public function tearDown()
  73. {
  74. if (file_exists($this->_file)) {
  75. unlink($this->_file);
  76. }
  77. unset($this->_server);
  78. }
  79. /**
  80. * Tests functionality of both get() and save()
  81. */
  82. public function testGetSave()
  83. {
  84. if (!is_writeable('./')) {
  85. $this->markTestIncomplete('Directory no writable');
  86. }
  87. $this->assertTrue(Zend_XmlRpc_Server_Cache::save($this->_file, $this->_server));
  88. $expected = $this->_server->listMethods();
  89. $server = new Zend_XmlRpc_Server();
  90. $this->assertTrue(Zend_XmlRpc_Server_Cache::get($this->_file, $server));
  91. $actual = $server->listMethods();
  92. $this->assertSame($expected, $actual);
  93. }
  94. /**
  95. * Zend_XmlRpc_Server_Cache::delete() test
  96. */
  97. public function testDelete()
  98. {
  99. if (!is_writeable('./')) {
  100. $this->markTestIncomplete('Directory no writable');
  101. }
  102. $this->assertTrue(Zend_XmlRpc_Server_Cache::save($this->_file, $this->_server));
  103. $this->assertTrue(Zend_XmlRpc_Server_Cache::delete($this->_file));
  104. }
  105. public function testShouldReturnFalseWithInvalidCache()
  106. {
  107. if (!is_writeable('./')) {
  108. $this->markTestIncomplete('Directory no writable');
  109. }
  110. file_put_contents($this->_file, 'blahblahblah');
  111. $server = new Zend_XmlRpc_Server();
  112. $this->assertFalse(Zend_XmlRpc_Server_Cache::get($this->_file, $server));
  113. }
  114. }
  115. // Call Zend_XmlRpc_Server_CacheTest::main() if this source file is executed directly.
  116. if (PHPUnit_MAIN_METHOD == "Zend_XmlRpc_Server_CacheTest::main") {
  117. Zend_XmlRpc_Server_CacheTest::main();
  118. }