repository = $this->createMock(PostMediaUsageRepositoryInterface::class); $this->reader = new PostMediaUsageReader($this->repository); } public function testCountUsagesDelegatesToRepository(): void { $this->repository ->expects($this->once()) ->method('countUsages') ->with(12) ->willReturn(4); self::assertSame(4, $this->reader->countUsages(12)); } public function testCountUsagesByMediaIdsDelegatesToRepository(): void { $this->repository ->expects($this->once()) ->method('countUsagesByMediaIds') ->with([12, 18]) ->willReturn([12 => 4, 18 => 1]); self::assertSame([12 => 4, 18 => 1], $this->reader->countUsagesByMediaIds([12, 18])); } public function testFindUsagesDelegatesToRepository(): void { $repositoryReferences = [ new PostMediaUsageReference(8, 'Titre', '/admin/posts/edit/8'), ]; $expectedReferences = [ new MediaUsageReference(8, 'Titre', '/admin/posts/edit/8'), ]; $this->repository ->expects($this->once()) ->method('findUsages') ->with(12, 3) ->willReturn($repositoryReferences); self::assertEquals($expectedReferences, $this->reader->findUsages(12, 3)); } public function testFindUsagesByMediaIdsDelegatesToRepository(): void { $repositoryReferences = [ 12 => [new PostMediaUsageReference(8, 'Titre', '/admin/posts/edit/8')], 18 => [new PostMediaUsageReference(14, 'Autre', '/admin/posts/edit/14')], ]; $expectedReferences = [ 12 => [new MediaUsageReference(8, 'Titre', '/admin/posts/edit/8')], 18 => [new MediaUsageReference(14, 'Autre', '/admin/posts/edit/14')], ]; $this->repository ->expects($this->once()) ->method('findUsagesByMediaIds') ->with([12, 18], 3) ->willReturn($repositoryReferences); self::assertEquals($expectedReferences, $this->reader->findUsagesByMediaIds([12, 18], 3)); } }