![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-search/Test/Unit/Adapter/Query/Preprocessor/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace Magento\Search\Test\Unit\Adapter\Query\Preprocessor; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Search\Adapter\Query\Preprocessor\Synonyms; use Magento\Search\Api\SynonymAnalyzerInterface; use Magento\Search\Model\SynonymAnalyzer; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class SynonymsTest extends TestCase { /** * @var SynonymAnalyzerInterface|MockObject */ private $synonymAnalyzer; /** * @var Synonyms */ private $synonymPreprocessor; protected function setUp(): void { $objectManager = new ObjectManager($this); $this->synonymAnalyzer = $this->getMockBuilder(SynonymAnalyzer::class) ->setMethods(['getSynonymsForPhrase']) ->disableOriginalConstructor() ->getMock(); $this->synonymPreprocessor = $objectManager->getObject( Synonyms::class, [ 'synonymsAnalyzer' => $this->synonymAnalyzer ] ); } /** * Data provider for the test * * @return array */ public static function loadProcessDataProvider() { return [ 'oneWord' => [ 'query' => 'big', 'result' => [['big', 'huge']], 'newQuery' => 'big huge' ], 'twoWords' => [ 'query' => 'big universe', 'result' => [['big', 'huge'], ['universe', 'cosmos']], 'newQuery' => 'big huge universe cosmos' ], 'noSynonyms' => [ 'query' => 'no synonyms', 'result' => [['no'], ['synonyms']], 'newQuery' => 'no synonyms' ] ]; } /** * @param string $phrase * @param array $expectedResult * @dataProvider loadProcessDataProvider */ public function testProcess($query, $result, $newQuery) { $this->synonymAnalyzer->expects($this->once()) ->method('getSynonymsForPhrase') ->with($query) ->willReturn($result); $result = $this->synonymPreprocessor->process($query); $this->assertEquals($result, $newQuery); } }