diff --git a/src/Mooc/Videos/Application/Update/UpdateVideoTitleCommand.php b/src/Mooc/Videos/Application/Update/UpdateVideoTitleCommand.php new file mode 100644 index 00000000..e8b48e04 --- /dev/null +++ b/src/Mooc/Videos/Application/Update/UpdateVideoTitleCommand.php @@ -0,0 +1,28 @@ +id; + } + + public function title(): string + { + return $this->title; + } + + +} diff --git a/src/Mooc/Videos/Application/Update/UpdateVideoTitleCommandHandler.php b/src/Mooc/Videos/Application/Update/UpdateVideoTitleCommandHandler.php new file mode 100644 index 00000000..69b54def --- /dev/null +++ b/src/Mooc/Videos/Application/Update/UpdateVideoTitleCommandHandler.php @@ -0,0 +1,26 @@ +titleUpdater = $titleUpdater; + } + + public function __invoke(UpdateVideoTitleCommand $command) + { + $id = new VideoId($command->id()); + $title = new VideoTitle($command->title()); + + $this->titleUpdater->__invoke($id, $title); + } +} diff --git a/tests/Mooc/Videos/Application/Update/UpdateVideoTitleCommandMother.php b/tests/Mooc/Videos/Application/Update/UpdateVideoTitleCommandMother.php new file mode 100644 index 00000000..e7248da6 --- /dev/null +++ b/tests/Mooc/Videos/Application/Update/UpdateVideoTitleCommandMother.php @@ -0,0 +1,34 @@ +value() ?? VideoIdMother::create()->value(), + $title->value() ?? VideoTitleMother::create()->value() + ); + } + + public static function withId(VideoId $id): UpdateVideoTitleCommand + { + return self::create($id, VideoTitleMother::create()); + } + + public static function withIdAndTitle(VideoId $id, VideoTitle $title): UpdateVideoTitleCommand + { + return self::create($id, $title); + } +} diff --git a/tests/Mooc/Videos/Application/Update/VideoFinderTest.php b/tests/Mooc/Videos/Application/Update/VideoFinderTest.php new file mode 100644 index 00000000..e41401c0 --- /dev/null +++ b/tests/Mooc/Videos/Application/Update/VideoFinderTest.php @@ -0,0 +1,36 @@ +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); + } +} diff --git a/tests/Mooc/Videos/Application/Update/VideoRenamerCommandTest.php b/tests/Mooc/Videos/Application/Update/VideoRenamerCommandTest.php new file mode 100644 index 00000000..ae6b91dd --- /dev/null +++ b/tests/Mooc/Videos/Application/Update/VideoRenamerCommandTest.php @@ -0,0 +1,44 @@ +finder = new VideoFinder($this->repository()); + } + + /** @test */ + public function it_should_throw_an_exception_when_the_video_not_exist() + { + $this->expectException(VideoNotFound::class); + + $id = VideoIdMother::create(); + + $this->shouldSearch($id, null); + + $this->finder->__invoke($id); + } + + /** @test */ + public function it_should_find_an_existing_video(): void + { + $video = VideoMother::create(); + + $this->shouldSearch($video->id(), $video); + + $videoFromRepository = $this->finder->__invoke($video->id()); + + $this->assertEquals($videoFromRepository, $video); + } +} diff --git a/tests/Mooc/Videos/Domain/VideoIdMother.php b/tests/Mooc/Videos/Domain/VideoIdMother.php new file mode 100644 index 00000000..1f272cce --- /dev/null +++ b/tests/Mooc/Videos/Domain/VideoIdMother.php @@ -0,0 +1,17 @@ +id()), + VideoTypeMother::create($request->type()), + VideoTitleMother::create($request->title()), + VideoUrlMother::create($request->url()), + CourseIdMother::create($request->courseId()), + ); + } +} diff --git a/tests/Mooc/Videos/Domain/VideoTitleMother.php b/tests/Mooc/Videos/Domain/VideoTitleMother.php new file mode 100644 index 00000000..b7320b89 --- /dev/null +++ b/tests/Mooc/Videos/Domain/VideoTitleMother.php @@ -0,0 +1,14 @@ +value()); + } +} diff --git a/tests/Mooc/Videos/Domain/VideoUrlMother.php b/tests/Mooc/Videos/Domain/VideoUrlMother.php new file mode 100644 index 00000000..409f0303 --- /dev/null +++ b/tests/Mooc/Videos/Domain/VideoUrlMother.php @@ -0,0 +1,14 @@ +repository() + ->shouldReceive('save') + ->with($this->similarTo($video)) + ->once() + ->andReturnNull(); + } + + protected function shouldSearch(VideoId $id, ?Video $video): void + { + $this->repository() + ->shouldReceive('search') + ->with($this->similarTo($id)) + ->once() + ->andReturn($video); + } + + protected function repository(): VideoRepository|MockInterface + { + return $this->repository = $this->repository ?? $this->mock(VideoRepository::class); + } +} diff --git a/tests/Shared/Domain/UrlMother.php b/tests/Shared/Domain/UrlMother.php new file mode 100644 index 00000000..38b59e7d --- /dev/null +++ b/tests/Shared/Domain/UrlMother.php @@ -0,0 +1,11 @@ +url; + } +}