CacheTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. // Call Zend_XmlRpc_Server_CacheTest::main() if this source file is executed directly.
  3. if (!defined("PHPUnit_MAIN_METHOD")) {
  4. define("PHPUnit_MAIN_METHOD", "Zend_XmlRpc_Server_CacheTest::main");
  5. }
  6. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  7. require_once 'Zend/XmlRpc/Server.php';
  8. require_once 'Zend/XmlRpc/Server/Cache.php';
  9. /**
  10. * Test case for Zend_XmlRpc_Server_Cache
  11. *
  12. * @package Zend_XmlRpc
  13. * @subpackage UnitTests
  14. * @version $Id$
  15. */
  16. class Zend_XmlRpc_Server_CacheTest extends PHPUnit_Framework_TestCase
  17. {
  18. /**
  19. * Runs the test methods of this class.
  20. *
  21. * @return void
  22. */
  23. public static function main()
  24. {
  25. $suite = new PHPUnit_Framework_TestSuite("Zend_XmlRpc_Server_CacheTest");
  26. $result = PHPUnit_TextUI_TestRunner::run($suite);
  27. }
  28. /**
  29. * Zend_XmlRpc_Server object
  30. * @var Zend_XmlRpc_Server
  31. */
  32. protected $_server;
  33. /**
  34. * Local file for caching
  35. * @var string
  36. */
  37. protected $_file;
  38. /**
  39. * Setup environment
  40. */
  41. public function setUp()
  42. {
  43. $this->_file = realpath(dirname(__FILE__)) . '/xmlrpc.cache';
  44. $this->_server = new Zend_XmlRpc_Server();
  45. $this->_server->setClass('Zend_XmlRpc_Server_Cache', 'cache');
  46. }
  47. /**
  48. * Teardown environment
  49. */
  50. public function tearDown()
  51. {
  52. if (file_exists($this->_file)) {
  53. unlink($this->_file);
  54. }
  55. unset($this->_server);
  56. }
  57. /**
  58. * Tests functionality of both get() and save()
  59. */
  60. public function testGetSave()
  61. {
  62. if (!is_writeable('./')) {
  63. $this->markTestIncomplete('Directory no writable');
  64. }
  65. $this->assertTrue(Zend_XmlRpc_Server_Cache::save($this->_file, $this->_server));
  66. $expected = $this->_server->listMethods();
  67. $server = new Zend_XmlRpc_Server();
  68. $this->assertTrue(Zend_XmlRpc_Server_Cache::get($this->_file, $server));
  69. $actual = $server->listMethods();
  70. $this->assertSame($expected, $actual);
  71. }
  72. /**
  73. * Zend_XmlRpc_Server_Cache::delete() test
  74. */
  75. public function testDelete()
  76. {
  77. if (!is_writeable('./')) {
  78. $this->markTestIncomplete('Directory no writable');
  79. }
  80. $this->assertTrue(Zend_XmlRpc_Server_Cache::save($this->_file, $this->_server));
  81. $this->assertTrue(Zend_XmlRpc_Server_Cache::delete($this->_file));
  82. }
  83. public function testShouldReturnFalseWithInvalidCache()
  84. {
  85. if (!is_writeable('./')) {
  86. $this->markTestIncomplete('Directory no writable');
  87. }
  88. file_put_contents($this->_file, 'blahblahblah');
  89. $server = new Zend_XmlRpc_Server();
  90. $this->assertFalse(Zend_XmlRpc_Server_Cache::get($this->_file, $server));
  91. }
  92. }
  93. // Call Zend_XmlRpc_Server_CacheTest::main() if this source file is executed directly.
  94. if (PHPUnit_MAIN_METHOD == "Zend_XmlRpc_Server_CacheTest::main") {
  95. Zend_XmlRpc_Server_CacheTest::main();
  96. }