clock = new \App\Framework\DateTime\SystemClock(); $this->connection = Mockery::mock(ConnectionInterface::class); $this->repository = new DatabaseContentTranslationRepository($this->connection); }); it('saves translation to database', function () { $contentId = ContentId::generate($this->clock); $translation = CmsTestHelpers::createContentTranslation($contentId); $this->connection->shouldReceive('execute') ->once() ->with(Mockery::type(\App\Framework\Database\ValueObjects\SqlQuery::class)) ->andReturn(1); $this->repository->save($translation); }); it('finds translation by content id and locale', function () { $contentId = ContentId::generate($this->clock); $locale = Locale::german(); $row = [ 'content_id' => $contentId->toString(), 'locale' => 'de', 'title' => 'Deutscher Titel', 'blocks' => json_encode([['id' => 'hero-1', 'type' => 'hero', 'data' => ['title' => 'Hero']]]), 'created_at' => '2025-01-15 10:00:00', 'updated_at' => '2025-01-15 10:00:00', ]; $result = Mockery::mock(ResultInterface::class); $result->shouldReceive('fetch') ->once() ->andReturn($row); $this->connection->shouldReceive('query') ->once() ->andReturn($result); $found = $this->repository->findByContentAndLocale($contentId, $locale); expect($found)->toBeInstanceOf(ContentTranslation::class); expect($found->locale->equals($locale))->toBeTrue(); }); it('finds all translations for content', function () { $contentId = ContentId::generate($this->clock); $row = [ 'content_id' => $contentId->toString(), 'locale' => 'de', 'title' => 'Deutscher Titel', 'blocks' => json_encode([['id' => 'hero-1', 'type' => 'hero', 'data' => ['title' => 'Hero']]]), 'created_at' => '2025-01-15 10:00:00', 'updated_at' => '2025-01-15 10:00:00', ]; $result = Mockery::mock(ResultInterface::class); $result->shouldReceive('fetchAll') ->once() ->andReturn([$row]); $this->connection->shouldReceive('query') ->once() ->andReturn($result); $found = $this->repository->findByContent($contentId); expect($found)->toBeArray(); expect($found)->toHaveCount(1); }); it('deletes translation', function () { $contentId = ContentId::generate($this->clock); $locale = Locale::german(); $this->connection->shouldReceive('execute') ->once() ->with(Mockery::type(\App\Framework\Database\ValueObjects\SqlQuery::class)) ->andReturn(1); $this->repository->delete($contentId, $locale); }); });