-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathUpdateVideoTitleCommandHandlerTest.php
53 lines (39 loc) · 1.7 KB
/
UpdateVideoTitleCommandHandlerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace CodelyTv\Tests\Mooc\Videos\Application\Update;
use CodelyTv\Mooc\Videos\Application\Update\UpdateVideoTitleCommandHandler;
use CodelyTv\Mooc\Videos\Application\Update\VideoTitleUpdater;
use CodelyTv\Mooc\Videos\Domain\VideoNotFound;
use CodelyTv\Tests\Mooc\Videos\Domain\VideoIdMother;
use CodelyTv\Tests\Mooc\Videos\Domain\VideoMother;
use CodelyTv\Tests\Mooc\Videos\Domain\VideoTitleMother;
use CodelyTv\Tests\Mooc\Videos\Infrastructure\VideosModuleUnitTestCase;
use CodelyTv\Tests\Shared\Domain\DuplicatorMother;
final class UpdateVideoTitleCommandHandlerTest extends VideosModuleUnitTestCase
{
private UpdateVideoTitleCommandHandler|null $handler;
protected function setUp(): void
{
parent::setUp();
$this->handler = new UpdateVideoTitleCommandHandler(new VideoTitleUpdater($this->repository()));
}
/** @test */
public function it_should_update_video_title_when_video_exists(): void
{
$video = VideoMother::create();
$newTitle = VideoTitleMother::create();
$command = UpdateVideoTitleCommandMother::withIdAndTitle($video->id(), $newTitle);
$renamedVideo = DuplicatorMother::with($video, ['title' => $newTitle]);
$this->shouldSearch($video->id(), $video);
$this->shouldSave($renamedVideo);
$this->handler->__invoke($command);
}
/** @test */
public function it_should_throw_an_exception_when_the_video_does_not_exist(): void
{
$this->expectException(VideoNotFound::class);
$id = VideoIdMother::create();
$command = UpdateVideoTitleCommandMother::withId($id);
$this->shouldSearch($id, null);
$this->handler->__invoke($command);
}
}