BuilderTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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\Adapter\Index;
  7. use Magento\Elasticsearch\Model\Adapter\Index\Builder;
  8. use Magento\Framework\Locale\Resolver as LocaleResolver;
  9. use Magento\Elasticsearch\Model\Adapter\Index\Config\EsConfigInterface;
  10. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
  11. class BuilderTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var Builder
  15. */
  16. protected $model;
  17. /**
  18. * @var LocaleResolver|\PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $localeResolver;
  21. /**
  22. * @var EsConfigInterface|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. protected $esConfig;
  25. /**
  26. * Setup method
  27. * @return void
  28. */
  29. protected function setUp()
  30. {
  31. $this->localeResolver = $this->getMockBuilder(\Magento\Framework\Locale\Resolver::class)
  32. ->disableOriginalConstructor()
  33. ->setMethods([
  34. 'emulate',
  35. 'getLocale'
  36. ])
  37. ->getMock();
  38. $this->esConfig = $this->getMockBuilder(
  39. \Magento\Elasticsearch\Model\Adapter\Index\Config\EsConfigInterface::class
  40. )
  41. ->disableOriginalConstructor()
  42. ->getMock();
  43. $objectManager = new ObjectManagerHelper($this);
  44. $this->model = $objectManager->getObject(
  45. \Magento\Elasticsearch\Model\Adapter\Index\Builder::class,
  46. [
  47. 'localeResolver' => $this->localeResolver,
  48. 'esConfig' => $this->esConfig
  49. ]
  50. );
  51. }
  52. /**
  53. * Test build() method
  54. *
  55. * @param string $locale
  56. * @dataProvider buildDataProvider
  57. */
  58. public function testBuild($locale)
  59. {
  60. $this->localeResolver->expects($this->once())
  61. ->method('getLocale')
  62. ->willReturn($locale);
  63. $this->esConfig->expects($this->once())
  64. ->method('getStemmerInfo')
  65. ->willReturn([
  66. 'type' => 'stemmer',
  67. 'default' => 'english',
  68. 'en_US' => 'english',
  69. ]);
  70. $result = $this->model->build();
  71. $this->assertNotNull($result);
  72. }
  73. /**
  74. * Test setStoreId() method
  75. */
  76. public function testSetStoreId()
  77. {
  78. $result = $this->model->setStoreId(1);
  79. $this->assertNull($result);
  80. }
  81. /**
  82. * @return array
  83. */
  84. public function buildDataProvider()
  85. {
  86. return [
  87. ['en_US'],
  88. ['de_DE'],
  89. ];
  90. }
  91. }