Files
animethemes-server/tests/Feature/Events/Pivot/Wiki/AnimeResourceTest.php
T
paranarimasu 2e930b17ff feat: initial migration to Laravel 10 (#572)
* feat: initial migration to Laravel 10

* style: fix StyleCI findings
2023-04-18 16:22:36 -05:00

109 lines
3.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\Events\Pivot\Wiki;
use App\Events\Pivot\Wiki\AnimeResource\AnimeResourceCreated;
use App\Events\Pivot\Wiki\AnimeResource\AnimeResourceDeleted;
use App\Events\Pivot\Wiki\AnimeResource\AnimeResourceUpdated;
use App\Models\Wiki\Anime;
use App\Models\Wiki\ExternalResource;
use App\Pivots\Wiki\AnimeResource;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Event;
use Tests\TestCase;
/**
* Class AnimeResourceTest.
*/
class AnimeResourceTest extends TestCase
{
/**
* When an Anime is attached to a Resource or vice versa, an AnimeResourceCreated event shall be dispatched.
*
* @return void
*/
public function testAnimeResourceCreatedEventDispatched(): void
{
$anime = Anime::factory()->createOne();
$resource = ExternalResource::factory()->createOne();
$anime->resources()->attach($resource);
Event::assertDispatched(AnimeResourceCreated::class);
}
/**
* When an Anime is detached from a Resource or vice versa, an AnimeResourceDeleted event shall be dispatched.
*
* @return void
*/
public function testAnimeResourceDeletedEventDispatched(): void
{
$anime = Anime::factory()->createOne();
$resource = ExternalResource::factory()->createOne();
$anime->resources()->attach($resource);
$anime->resources()->detach($resource);
Event::assertDispatched(AnimeResourceDeleted::class);
}
/**
* When an Anime Resource pivot is updated, an AnimeResourceUpdated event shall be dispatched.
*
* @return void
*/
public function testAnimeResourceUpdatedEventDispatched(): void
{
$anime = Anime::factory()->createOne();
$resource = ExternalResource::factory()->createOne();
$animeResource = AnimeResource::factory()
->for($anime, 'anime')
->for($resource, 'resource')
->createOne();
$changes = AnimeResource::factory()
->for($anime, 'anime')
->for($resource, 'resource')
->makeOne();
$animeResource->fill($changes->getAttributes());
$animeResource->save();
Event::assertDispatched(AnimeResourceUpdated::class);
}
/**
* The AnimeResourceUpdated event shall contain embed fields.
*
* @return void
*/
public function testAnimeResourceUpdatedEventEmbedFields(): void
{
$anime = Anime::factory()->createOne();
$resource = ExternalResource::factory()->createOne();
$animeResource = AnimeResource::factory()
->for($anime, 'anime')
->for($resource, 'resource')
->createOne();
$changes = AnimeResource::factory()
->for($anime, 'anime')
->for($resource, 'resource')
->makeOne();
$animeResource->fill($changes->getAttributes());
$animeResource->save();
Event::assertDispatched(AnimeResourceUpdated::class, function (AnimeResourceUpdated $event) {
$message = $event->getDiscordMessage();
return ! empty(Arr::get($message->embed, 'fields'));
});
}
}