createMock(CmsTranslationRepository::class); $repository->expects(self::once())->method('getTranslations')->with( 1101, 3, CmsTranslationRepository::ENTITY_BLOG_POST, self::isType('array') )->willReturn(['name' => 'Deutscher Titel']); $post = $this->createMock(Post::class); $post->method('getId')->willReturn(1101); $post->expects(self::once())->method('setData')->with('name', 'Deutscher Titel')->willReturnSelf(); $this->createApplier($repository)->apply($post); } public function testAppliesCollectionTranslationsWithOneRepositoryQuery(): void { $repository = $this->createMock(CmsTranslationRepository::class); $repository->expects(self::once())->method('getTranslationsForEntities')->with( [1101, 1102], 3, CmsTranslationRepository::ENTITY_BLOG_POST, self::isType('array') )->willReturn([ 1101 => ['name' => 'Erster Titel'], 1102 => ['name' => 'Zweiter Titel'], ]); $first = $this->createMock(Post::class); $first->method('getId')->willReturn(1101); $first->expects(self::once())->method('setData')->with('name', 'Erster Titel')->willReturnSelf(); $second = $this->createMock(Post::class); $second->method('getId')->willReturn(1102); $second->expects(self::once())->method('setData')->with('name', 'Zweiter Titel')->willReturnSelf(); $this->createApplier($repository)->applyMany([$first, $second]); } private function createApplier(CmsTranslationRepository $repository): BlogPostTranslationApplier { $store = $this->createMock(StoreInterface::class); $store->method('getId')->willReturn(3); $storeManager = $this->createMock(StoreManagerInterface::class); $storeManager->method('getStore')->willReturn($store); $state = $this->createMock(State::class); $state->method('getAreaCode')->willReturn('frontend'); return new BlogPostTranslationApplier($repository, $storeManager, $state); } }