factory.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * @author Robin McCorkell <rmccorkell@karoshi.org.uk>
  4. *
  5. * @copyright Copyright (c) 2015, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace Test\Memcache;
  22. class Test_Factory_Available_Cache1 {
  23. public function __construct($prefix = '') {
  24. }
  25. public static function isAvailable() {
  26. return true;
  27. }
  28. }
  29. class Test_Factory_Available_Cache2 {
  30. public function __construct($prefix = '') {
  31. }
  32. public static function isAvailable() {
  33. return true;
  34. }
  35. }
  36. class Test_Factory_Unavailable_Cache1 {
  37. public function __construct($prefix = '') {
  38. }
  39. public static function isAvailable() {
  40. return false;
  41. }
  42. }
  43. class Test_Factory_Unavailable_Cache2 {
  44. public function __construct($prefix = '') {
  45. }
  46. public static function isAvailable() {
  47. return false;
  48. }
  49. }
  50. class Test_Factory extends \Test\TestCase {
  51. const AVAILABLE1 = '\\Test\\Memcache\\Test_Factory_Available_Cache1';
  52. const AVAILABLE2 = '\\Test\\Memcache\\Test_Factory_Available_Cache2';
  53. const UNAVAILABLE1 = '\\Test\\Memcache\\Test_Factory_Unavailable_Cache1';
  54. const UNAVAILABLE2 = '\\Test\\Memcache\\Test_Factory_Unavailable_Cache2';
  55. public function cacheAvailabilityProvider() {
  56. return [
  57. [
  58. // local and distributed available
  59. self::AVAILABLE1, self::AVAILABLE2,
  60. self::AVAILABLE1, self::AVAILABLE2
  61. ],
  62. [
  63. // local available, distributed unavailable
  64. self::AVAILABLE1, self::UNAVAILABLE1,
  65. self::AVAILABLE1, self::AVAILABLE1
  66. ],
  67. [
  68. // local unavailable, distributed available
  69. self::UNAVAILABLE1, self::AVAILABLE1,
  70. \OC\Memcache\Factory::NULL_CACHE, self::AVAILABLE1
  71. ],
  72. [
  73. // local and distributed unavailable
  74. self::UNAVAILABLE1, self::UNAVAILABLE2,
  75. \OC\Memcache\Factory::NULL_CACHE, \OC\Memcache\Factory::NULL_CACHE
  76. ],
  77. [
  78. // local and distributed null
  79. null, null,
  80. \OC\Memcache\Factory::NULL_CACHE, \OC\Memcache\Factory::NULL_CACHE
  81. ],
  82. [
  83. // local available, distributed null (most common scenario)
  84. self::AVAILABLE1, null,
  85. self::AVAILABLE1, self::AVAILABLE1
  86. ]
  87. ];
  88. }
  89. /**
  90. * @dataProvider cacheAvailabilityProvider
  91. */
  92. public function testCacheAvailability($localCache, $distributedCache,
  93. $expectedLocalCache, $expectedDistributedCache)
  94. {
  95. $factory = new \OC\Memcache\Factory('abc', $localCache, $distributedCache);
  96. $this->assertTrue(is_a($factory->createLocal(), $expectedLocalCache));
  97. $this->assertTrue(is_a($factory->createDistributed(), $expectedDistributedCache));
  98. }
  99. }