mediaMetadataService = self::mock(MediaMetadataService::class); } public function testUploadCover(): void { /** @var Playlist $playlist */ $playlist = Playlist::factory()->create(); self::assertNull($playlist->cover); $this->mediaMetadataService ->shouldReceive('writePlaylistCover') ->once() ->with(Mockery::on(static fn (Playlist $target) => $target->is($playlist)), 'Foo', 'jpeg'); $this->putAs( "api/playlists/$playlist->id/cover", ['cover' => 'data:image/jpeg;base64,Rm9v'], $playlist->user ) ->assertOk(); } public function testUploadCoverNotAllowedForNonOwner(): void { /** @var Playlist $playlist */ $playlist = Playlist::factory()->create(); $this->mediaMetadataService->shouldNotReceive('writePlaylistCover'); $this->putAs( "api/playlists/$playlist->id/cover", ['cover' => 'data:image/jpeg;base64,Rm9v'], create_user() ) ->assertForbidden(); } }