createMock(\medoo::class); $repository = new ScontainersRepository($mockDb); $container = $repository->find(0); $this->assertIsArray($container); $this->assertSame(0, (int)$container['id']); $this->assertSame(1, (int)$container['status']); } public function testDeleteReturnsFalseForInvalidId(): void { $mockDb = $this->createMock(\medoo::class); $repository = new ScontainersRepository($mockDb); $this->assertFalse($repository->delete(0)); } public function testFindReturnsContainerWithTranslations(): void { $mockDb = $this->createMock(\medoo::class); $mockDb->expects($this->once()) ->method('get') ->with('pp_scontainers', '*', ['id' => 7]) ->willReturn(['id' => 7, 'status' => 1, 'show_title' => 1]); $mockDb->expects($this->once()) ->method('select') ->with('pp_scontainers_langs', '*', ['container_id' => 7]) ->willReturn([ ['lang_id' => 'pl', 'title' => 'Tytul PL', 'text' => 'Tekst PL'], ['lang_id' => 'en', 'title' => 'Title EN', 'text' => 'Text EN'], ]); $repository = new ScontainersRepository($mockDb); $container = $repository->find(7); $this->assertSame(7, (int)$container['id']); $this->assertArrayHasKey('languages', $container); $this->assertArrayHasKey('pl', $container['languages']); $this->assertArrayHasKey('en', $container['languages']); } public function testDetailsForLanguageReturnsNullForInvalidData(): void { $mockDb = $this->createMock(\medoo::class); $repository = new ScontainersRepository($mockDb); $this->assertNull($repository->detailsForLanguage(0, 'pl')); $this->assertNull($repository->detailsForLanguage(1, '')); } // ── Frontend methods tests ────────────────────────────────── public function testFrontScontainerDetailsReturnsContainerWithLanguage(): void { $mockDb = $this->createMock(\medoo::class); $mockDb->expects($this->exactly(2)) ->method('get') ->willReturnOnConsecutiveCalls( ['id' => 3, 'status' => 1, 'show_title' => 1], ['container_id' => 3, 'lang_id' => 'pl', 'title' => 'Tytul', 'text' => 'Tekst'] ); $repository = new ScontainersRepository($mockDb); $result = $repository->frontScontainerDetails(3, 'pl'); $this->assertIsArray($result); $this->assertSame(3, (int)$result['id']); $this->assertSame(1, (int)$result['status']); $this->assertSame('Tytul', $result['languages']['title']); } public function testFrontScontainerDetailsReturnsFallbackForNotFound(): void { $mockDb = $this->createMock(\medoo::class); $mockDb->method('get')->willReturn(null); $repository = new ScontainersRepository($mockDb); $result = $repository->frontScontainerDetails(999, 'pl'); $this->assertIsArray($result); $this->assertSame(999, (int)$result['id']); $this->assertSame(0, (int)$result['status']); $this->assertSame('pl', $result['languages']['lang_id']); } }