1
0

ClientServiceTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Copyright (c) 2015 Lukas Reschke <lukas@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace Test\Http\Client;
  9. use GuzzleHttp\Client as GuzzleClient;
  10. use GuzzleHttp\HandlerStack;
  11. use GuzzleHttp\Handler\CurlHandler;
  12. use OC\Http\Client\Client;
  13. use OC\Http\Client\ClientService;
  14. use OC\Http\Client\DnsPinMiddleware;
  15. use OC\Http\Client\LocalAddressChecker;
  16. use OCP\ICertificateManager;
  17. use OCP\IConfig;
  18. use OCP\ILogger;
  19. /**
  20. * Class ClientServiceTest
  21. */
  22. class ClientServiceTest extends \Test\TestCase {
  23. public function testNewClient(): void {
  24. /** @var IConfig $config */
  25. $config = $this->createMock(IConfig::class);
  26. /** @var ICertificateManager $certificateManager */
  27. $certificateManager = $this->createMock(ICertificateManager::class);
  28. $logger = $this->createMock(ILogger::class);
  29. $dnsPinMiddleware = $this->createMock(DnsPinMiddleware::class);
  30. $dnsPinMiddleware
  31. ->expects($this->atLeastOnce())
  32. ->method('addDnsPinning')
  33. ->willReturn(function () {
  34. });
  35. $localAddressChecker = $this->createMock(LocalAddressChecker::class);
  36. $clientService = new ClientService(
  37. $config,
  38. $logger,
  39. $certificateManager,
  40. $dnsPinMiddleware,
  41. $localAddressChecker
  42. );
  43. $handler = new CurlHandler();
  44. $stack = HandlerStack::create($handler);
  45. $stack->push($dnsPinMiddleware->addDnsPinning());
  46. $guzzleClient = new GuzzleClient(['handler' => $stack]);
  47. $this->assertEquals(
  48. new Client(
  49. $config,
  50. $logger,
  51. $certificateManager,
  52. $guzzleClient,
  53. $localAddressChecker
  54. ),
  55. $clientService->newClient()
  56. );
  57. }
  58. }