createOne(); $facet = $image->facet; static::assertInstanceOf(ImageFacet::class, $facet); } /** * Images shall be nameable. * * @return void */ public function testNameable(): void { $image = Image::factory()->createOne(); static::assertIsString($image->getName()); } /** * Images shall have subtitle. * * @return void */ public function testHasSubtitle(): void { $image = Image::factory()->createOne(); static::assertIsString($image->getSubtitle()); } /** * Image shall have a many-to-many relationship with the type Anime. * * @return void */ public function testAnime(): void { $animeCount = $this->faker->randomDigitNotNull(); $image = Image::factory() ->has(Anime::factory()->count($animeCount)) ->createOne(); static::assertInstanceOf(BelongsToMany::class, $image->anime()); static::assertEquals($animeCount, $image->anime()->count()); static::assertInstanceOf(Anime::class, $image->anime()->first()); static::assertEquals(AnimeImage::class, $image->anime()->getPivotClass()); } /** * Image shall have a many-to-many relationship with the type Artist. * * @return void */ public function testArtists(): void { $artistCount = $this->faker->randomDigitNotNull(); $image = Image::factory() ->has(Artist::factory()->count($artistCount)) ->createOne(); static::assertInstanceOf(BelongsToMany::class, $image->artists()); static::assertEquals($artistCount, $image->artists()->count()); static::assertInstanceOf(Artist::class, $image->artists()->first()); static::assertEquals(ArtistImage::class, $image->artists()->getPivotClass()); } /** * Image shall have a many-to-many relationship with the type Studio. * * @return void */ public function testStudios(): void { $studioCount = $this->faker->randomDigitNotNull(); $image = Image::factory() ->has(Studio::factory()->count($studioCount)) ->createOne(); static::assertInstanceOf(BelongsToMany::class, $image->studios()); static::assertEquals($studioCount, $image->studios()->count()); static::assertInstanceOf(Studio::class, $image->studios()->first()); static::assertEquals(StudioImage::class, $image->studios()->getPivotClass()); } /** * Image shall have a many-to-many relationship with the type Playlist. * * @return void */ public function testPlaylists(): void { $playlistCount = $this->faker->randomDigitNotNull(); $image = Image::factory() ->has(Playlist::factory()->count($playlistCount)) ->createOne(); static::assertInstanceOf(BelongsToMany::class, $image->playlists()); static::assertEquals($playlistCount, $image->playlists()->count()); static::assertInstanceOf(Playlist::class, $image->playlists()->first()); } /** * The image shall not be deleted from storage when the Image is deleted. * * @return void */ public function testImageStorageDeletion(): void { $fs = Storage::fake(Config::get('image.disk')); $file = File::fake()->image($this->faker->word().'.jpg'); $fsFile = $fs->putFile('', $file); $facet = Arr::random(ImageFacet::cases()); $image = Image::factory()->createOne([ Image::ATTRIBUTE_FACET => $facet->value, Image::ATTRIBUTE_PATH => $fsFile, ]); $image->delete(); static::assertTrue($fs->exists($image->path)); } /** * The image shall be deleted from storage when the Image is force deleted. * * @return void */ public function testImageStorageForceDeletion(): void { Event::fakeExcept(ImageDeleting::class); $fs = Storage::fake(Config::get('image.disk')); $file = File::fake()->image($this->faker->word().'.jpg'); $fsFile = $fs->putFile('', $file); $facet = Arr::random(ImageFacet::cases()); $image = Image::factory()->createOne([ Image::ATTRIBUTE_FACET => $facet->value, Image::ATTRIBUTE_PATH => $fsFile, ]); $image->forceDelete(); static::assertFalse($fs->exists($image->path)); } }