createOne([ Image::ATTRIBUTE_FACET => ImageFacet::COVER_LARGE, ]); $studio = Studio::factory() ->hasAttached($image) ->createOne(); $action = new BackfillLargeCoverImageAction($studio); $result = $action->handle(); static::assertTrue(ActionStatus::SKIPPED()->is($result->getStatus())); static::assertDatabaseCount(Image::class, 1); static::assertEmpty(Storage::disk(Config::get('image.disk'))->allFiles()); Http::assertNothingSent(); } /** * The Backfill Large Cover Image Action shall fail if the Studio has no Resources. * * @return void * * @throws Exception */ public function testFailedWhenNoResource(): void { Storage::fake(Config::get('image.disk')); $studio = Studio::factory()->createOne(); $action = new BackfillLargeCoverImageAction($studio); $result = $action->handle(); static::assertTrue($result->hasFailed()); static::assertDatabaseCount(Image::class, 0); static::assertEmpty(Storage::disk(Config::get('image.disk'))->allFiles()); Http::assertNothingSent(); } /** * The Backfill Large Cover Image Action shall fail if the Studio has no MAL Resource. * * @return void * * @throws Exception */ public function testFailedWhenNoMalResource(): void { Storage::fake(Config::get('image.disk')); $site = null; while ($site === null) { $siteCandidate = ResourceSite::getRandomInstance(); if (ResourceSite::MAL()->isNot($siteCandidate)) { $site = $siteCandidate; } } $resource = ExternalResource::factory()->createOne([ ExternalResource::ATTRIBUTE_SITE => $site->value, ]); $studio = Studio::factory() ->hasAttached($resource, [], Studio::RELATION_RESOURCES) ->createOne(); $action = new BackfillLargeCoverImageAction($studio); $result = $action->handle(); static::assertTrue($result->hasFailed()); static::assertDatabaseCount(Image::class, 0); static::assertEmpty(Storage::disk(Config::get('image.disk'))->allFiles()); Http::assertNothingSent(); } /** * The Backfill Large Cover Image Action shall pass if the image can be retrieved. * * @return void * * @throws Exception */ public function testPassed(): void { Storage::fake(Config::get('image.disk')); $file = File::fake()->image($this->faker->word().'.jpg'); Http::fake([ 'https://cdn.myanimelist.net/images/company/*' => Http::response($file->getContent()), ]); $resource = ExternalResource::factory()->createOne([ ExternalResource::ATTRIBUTE_SITE => ResourceSite::MAL, ]); $studio = Studio::factory() ->hasAttached($resource, [], Studio::RELATION_RESOURCES) ->createOne(); $action = new BackfillLargeCoverImageAction($studio); $result = $action->handle(); static::assertTrue(ActionStatus::PASSED()->is($result->getStatus())); static::assertDatabaseCount(Image::class, 1); static::assertTrue($studio->images()->where(Image::ATTRIBUTE_FACET, ImageFacet::COVER_LARGE)->exists()); static::assertCount(1, Storage::disk(Config::get('image.disk'))->allFiles()); Http::assertSentCount(1); } }