createOne(); static::assertIsString($audio->getName()); } /** * Audios shall have subtitle. * * @return void */ public function testHasSubtitle(): void { $audio = Audio::factory()->createOne(); static::assertIsString($audio->getSubtitle()); } /** * Audio shall have a one-to-many relationship with the type Video. * * @return void */ public function testVideos(): void { $videoCount = $this->faker->randomDigitNotNull(); $audio = Audio::factory() ->has(Video::factory()->count($videoCount)) ->createOne(); static::assertInstanceOf(HasMany::class, $audio->videos()); static::assertEquals($videoCount, $audio->videos()->count()); static::assertInstanceOf(Video::class, $audio->videos()->first()); } /** * Audios shall have a one-to-many polymorphic relationship to View. * * @return void */ public function testViews(): void { $audio = Audio::factory()->createOne(); views($audio)->record(); static::assertInstanceOf(MorphMany::class, $audio->views()); static::assertEquals(1, $audio->views()->count()); static::assertInstanceOf(View::class, $audio->views()->first()); } /** * The audio shall not be deleted from storage when the Audio is deleted. * * @return void */ public function testAudioStorageDeletion(): void { $fs = Storage::fake(Config::get(AudioConstants::DEFAULT_DISK_QUALIFIED)); $file = File::fake()->create($this->faker->word().'.ogg', $this->faker->randomDigitNotNull()); $fsFile = $fs->putFile('', $file); $audio = Audio::factory()->createOne([ Audio::ATTRIBUTE_PATH => $fsFile, ]); $audio->delete(); static::assertTrue($fs->exists($audio->path)); } /** * The audio shall be deleted from storage when the Audio is force deleted. * * @return void */ public function testAudioStorageForceDeletion(): void { Event::fakeExcept(AudioForceDeleting::class); $fs = Storage::fake(Config::get(AudioConstants::DEFAULT_DISK_QUALIFIED)); $file = File::fake()->create($this->faker->word().'.ogg', $this->faker->randomDigitNotNull()); $fsFile = $fs->putFile('', $file); $audio = Audio::factory()->createOne([ Audio::ATTRIBUTE_PATH => $fsFile, ]); $audio->forceDelete(); static::assertFalse($fs->exists($audio->path)); } }