mediaMetadataService = self::mock(MediaMetadataService::class); } public function testUpdate(): void { $this->expectsEvents(LibraryChanged::class); /** @var User $user */ $user = User::factory()->admin()->create(); /** @var Album $album */ $album = Album::factory()->create(['id' => 9999]); $this->mediaMetadataService ->shouldReceive('writeAlbumCover') ->once() ->with(Mockery::on(static fn (Album $album) => $album->id === 9999), 'Foo', 'jpeg'); $this->putAs('api/album/' . $album->id . '/cover', ['cover' => 'data:image/jpeg;base64,Rm9v'], $user) ->assertOk(); } public function testUpdateNotAllowedForNormalUsers(): void { /** @var Album $album */ $album = Album::factory()->create(); $this->mediaMetadataService ->shouldReceive('writeAlbumCover') ->never(); /** @var User $user */ $user = User::factory()->create(); $this->putAs('api/album/' . $album->id . '/cover', ['cover' => 'data:image/jpeg;base64,Rm9v'], $user) ->assertForbidden(); } }