file = UploadedFile::fromFile(test_path('songs/full.mp3'), 'song.mp3'); //@phpstan-ignore-line } public function testUnauthorizedPost(): void { Setting::set('media_path'); $this->postAs('/api/upload', ['file' => $this->file])->assertForbidden(); } /** @return array */ public function provideUploadExceptions(): array { return [ [MediaPathNotSetException::class, Response::HTTP_FORBIDDEN], [SongUploadFailedException::class, Response::HTTP_BAD_REQUEST], ]; } public function testUploadFailsIfMediaPathIsNotSet(): void { Setting::set('media_path'); $this->postAs('/api/upload', ['file' => $this->file], create_admin())->assertForbidden(); } public function testUploadSuccessful(): void { Event::fake(LibraryChanged::class); Setting::set('media_path', public_path('sandbox/media')); $this->postAs('/api/upload', ['file' => $this->file], create_admin())->assertJsonStructure(['song', 'album']); Event::assertDispatched(LibraryChanged::class); } }