mediaMetadataService = self::mock(MediaMetadataService::class); } /** @return array */ public function provideAlbumThumbnailData(): array { return [['http://localhost/img/covers/foo_thumbnail.jpg'], [null]]; } /** @dataProvider provideAlbumThumbnailData */ public function testGetAlbumThumbnail(?string $thumbnailUrl): void { /** @var Album $createdAlbum */ $createdAlbum = Album::factory()->create(); $this->mediaMetadataService ->shouldReceive('getAlbumThumbnailUrl') ->once() ->with(Mockery::on(static function (Album $album) use ($createdAlbum): bool { return $album->id === $createdAlbum->id; })) ->andReturn($thumbnailUrl); $response = $this->getAs("api/albums/{$createdAlbum->id}/thumbnail"); $response->assertJson(['thumbnailUrl' => $thumbnailUrl]); } }