ConfigTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Elasticsearch\Test\Unit\Model;
  7. use Magento\Elasticsearch\Model\Config;
  8. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
  9. use Magento\Framework\App\Config\ScopeConfigInterface;
  10. /**
  11. * Class ConfigTest
  12. */
  13. class ConfigTest extends \PHPUnit\Framework\TestCase
  14. {
  15. /**
  16. * @var Config
  17. */
  18. protected $model;
  19. /**
  20. * @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
  21. */
  22. protected $scopeConfig;
  23. /**
  24. * Setup
  25. *
  26. * @return void
  27. */
  28. protected function setUp()
  29. {
  30. $this->scopeConfig = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class)
  31. ->disableOriginalConstructor()
  32. ->getMock();
  33. $objectManager = new ObjectManagerHelper($this);
  34. $this->model = $objectManager->getObject(
  35. \Magento\Elasticsearch\Model\Config::class,
  36. [
  37. 'scopeConfig' => $this->scopeConfig
  38. ]
  39. );
  40. }
  41. /**
  42. * Test prepareClientOptions() method
  43. */
  44. public function testPrepareClientOptions()
  45. {
  46. $this->scopeConfig->expects($this->any())
  47. ->method('getValue')
  48. ->willReturn('');
  49. $options = [
  50. 'hostname' => 'localhost',
  51. 'port' => '9200',
  52. 'index' => 'magento2',
  53. 'enableAuth' => '1',
  54. 'username' => 'user',
  55. 'password' => 'pass',
  56. 'timeout' => 1,
  57. ];
  58. $this->assertEquals($options, $this->model->prepareClientOptions($options));
  59. }
  60. /**
  61. * Test getIndexPrefix() method
  62. */
  63. public function testGetIndexPrefix()
  64. {
  65. $this->scopeConfig->expects($this->any())
  66. ->method('getValue')
  67. ->willReturn('indexPrefix');
  68. $this->assertEquals('indexPrefix', $this->model->getIndexPrefix());
  69. }
  70. /**
  71. * Test getEntityType() method
  72. */
  73. public function testGetEntityType()
  74. {
  75. $this->assertInternalType('string', $this->model->getEntityType());
  76. }
  77. /**
  78. * Test getEntityType() method
  79. */
  80. public function testIsElasticsearchEnabled()
  81. {
  82. $this->assertFalse($this->model->isElasticsearchEnabled());
  83. }
  84. }