NegativeDnsCacheTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace Test\Http\Client;
  8. use OC\Http\Client\NegativeDnsCache;
  9. use OCP\ICache;
  10. use OCP\ICacheFactory;
  11. class NegativeDnsCacheTest extends \Test\TestCase {
  12. /** @var ICache */
  13. private $cache;
  14. /** @var ICacheFactory */
  15. private $cacheFactory;
  16. /** @var NegativeDnsCache */
  17. private $negativeDnsCache;
  18. protected function setUp(): void {
  19. parent::setUp();
  20. $this->cache = $this->createMock(ICache::class);
  21. $this->cacheFactory = $this->createMock(ICacheFactory::class);
  22. $this->cacheFactory
  23. ->method('createLocal')
  24. ->with('NegativeDnsCache')
  25. ->willReturn($this->cache);
  26. $this->negativeDnsCache = new NegativeDnsCache($this->cacheFactory);
  27. }
  28. public function testSetNegativeCacheForDnsType() : void {
  29. $this->cache
  30. ->expects($this->once())
  31. ->method('set')
  32. ->with('www.example.com-1', 'true', 3600);
  33. $this->negativeDnsCache->setNegativeCacheForDnsType('www.example.com', DNS_A, 3600);
  34. }
  35. public function testIsNegativeCached(): void {
  36. $this->cache
  37. ->expects($this->once())
  38. ->method('hasKey')
  39. ->with('www.example.com-1')
  40. ->willReturn(true);
  41. $this->assertTrue($this->negativeDnsCache->isNegativeCached('www.example.com', DNS_A));
  42. }
  43. }