ElasticsearchRegistry example

private Client&MockObject $client;

    private IndicesNamespace&MockObject $indices;

    protected function setUp(): void
    {
        Feature::skipTestIfInActive('ES_MULTILINGUAL_INDEX', $this);

        $this->connection = $this->createMock(Connection::class);
        $this->helper = $this->createMock(ElasticsearchHelper::class);
        $this->registry = new ElasticsearchRegistry([$this->createDefinition('product')]);
        $this->indexCreator = $this->createMock(IndexCreator::class);
        $this->iteratorFactory = $this->createMock(IteratorFactory::class);
        $this->client = $this->createMock(Client::class);

        $this->helper->method('allowIndexing')->willReturn(true);

        $this->indices = $this->createMock(IndicesNamespace::class);
        $this->client->method('indices')->willReturn($this->indices);

        parent::setUp();
    }

    

class ElasticsearchRegistryTest extends TestCase
{
    public function testRegistry(): void
    {
        $definition = $this->createMock(ElasticsearchProductDefinition::class);
        $definition
            ->method('getEntityDefinition')
            ->willReturn(new ProductDefinition());

        $registry = new ElasticsearchRegistry([
            $definition,
        ]);

        static::assertTrue($registry->has('product'));
        static::assertInstanceOf(ElasticsearchProductDefinition::class$registry->get('product'));

        static::assertFalse($registry->has('category'));
        static::assertNull($registry->get('category'));

        static::assertEquals(['product']$registry->getDefinitionNames());
    }
}
$language = new LanguageEntity();
        $language->setId(Uuid::randomHex());

        $languageProvider = $this->createMock(ElasticsearchLanguageProvider::class);
        $languageProvider
            ->method('getLanguages')
            ->willReturn(new LanguageCollection([$language]));

        $elasticsearchHelper = $this->createMock(ElasticsearchHelper::class);
        $elasticsearchHelper->method('getIndexName')->willReturn('index');

        $registry = new ElasticsearchRegistry([
            $this->createMock(ElasticsearchProductDefinition::class),
        ]);

        $client = $this->createMock(Client::class);
        $indicesNamespace = $this->createMock(IndicesNamespace::class);
        $indicesNamespace
            ->expects(static::once())
            ->method('putMapping')
            ->with([
                'index' => 'index',
                'body' => [
                    
private IndicesNamespace&MockObject $indices;

    private MultilingualEsIndexer&MockObject $newEsIndexer;

    protected function setUp(): void
    {
        Feature::skipTestIfActive('ES_MULTILINGUAL_INDEX', $this);

        $this->connection = $this->createMock(Connection::class);
        $this->helper = $this->createMock(ElasticsearchHelper::class);
        $this->registry = new ElasticsearchRegistry([$this->createDefinition('product')]);
        $this->indexCreator = $this->createMock(IndexCreator::class);
        $this->iteratorFactory = $this->createMock(IteratorFactory::class);
        $this->client = $this->createMock(Client::class);
        $this->currencyRepository = $this->createMock(EntityRepository::class);
        $this->languageRepository = $this->createMock(EntityRepository::class);
        $this->newEsIndexer = $this->createMock(MultilingualEsIndexer::class);
        $this->bus = new CollectingMessageBus();

        $this->helper->method('allowIndexing')->willReturn(true);

        $this->language1 = new LanguageEntity();
        
Home | Imprint | This part of the site doesn't use cookies.