From 7601a194ab0880d8537ae76ce105e15c5b970aa9 Mon Sep 17 00:00:00 2001 From: IvanC Date: Wed, 24 Mar 2021 18:29:25 +0100 Subject: [PATCH 1/5] Version de mysql para chip M1 --- docker-compose.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 2af2539f2..9ccd324f3 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,18 +27,21 @@ services: mooc_mysql: container_name: codelytv-php_ddd_skeleton-mooc-mysql - image: mysql:8.0 + image: mysql/mysql-server:8.0.23 ports: - 3360:3306 environment: - MYSQL_ROOT_PASSWORD= - MYSQL_ALLOW_EMPTY_PASSWORD=yes + - MYSQL_ROOT_HOST=% healthcheck: test: ["CMD", "mysqladmin", "--user=root", "--password=", "--host=127.0.0.1", "ping", "--silent"] interval: 2s timeout: 10s retries: 10 - command: ["--default-authentication-plugin=mysql_native_password"] + command: ["--lower_case_table_names=1"] + + backoffice_elasticsearch: container_name: codelytv-php_ddd_skeleton-backoffice-elastic @@ -101,4 +104,4 @@ services: - shared_rabbitmq - shared_prometheus - mooc_mysql - command: symfony serve --dir=apps/mooc/backend/public --port=8030 --force-php-discovery + command: symfony serve --dir=apps/mooc/backend/public --port=8030 --force-php-discovery \ No newline at end of file From 7a2df447fe93d173d7d62d411680760281713a07 Mon Sep 17 00:00:00 2001 From: IvanC Date: Wed, 24 Mar 2021 18:59:31 +0100 Subject: [PATCH 2/5] Version de elasticsearch para chip M1 --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 9ccd324f3..91ba43819 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -45,7 +45,7 @@ services: backoffice_elasticsearch: container_name: codelytv-php_ddd_skeleton-backoffice-elastic - image: docker.elastic.co/elasticsearch/elasticsearch:6.8.10 + image: docker.elastic.co/elasticsearch/elasticsearch:7.12.0 ports: - 9200:9200 - 9300:9300 From 38832c46bcdfa6319bfeef00022ae30d4fbd50d6 Mon Sep 17 00:00:00 2001 From: IvanC Date: Thu, 25 Mar 2021 17:21:46 +0100 Subject: [PATCH 3/5] Added CourseFinderTest. 2 cases: find and not find a course --- .../Create/CreateCourseCommandHandlerTest.php | 2 +- .../Application/Find/CourseFinderTest.php | 47 +++++++++++++++++++ .../Application/Update/CourseRenamerTest.php | 2 +- 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 tests/Mooc/Courses/Application/Find/CourseFinderTest.php diff --git a/tests/Mooc/Courses/Application/Create/CreateCourseCommandHandlerTest.php b/tests/Mooc/Courses/Application/Create/CreateCourseCommandHandlerTest.php index 6a85c1f1a..dcf5b35c8 100644 --- a/tests/Mooc/Courses/Application/Create/CreateCourseCommandHandlerTest.php +++ b/tests/Mooc/Courses/Application/Create/CreateCourseCommandHandlerTest.php @@ -34,4 +34,4 @@ public function it_should_create_a_valid_course(): void $this->dispatch($command, $this->handler); } -} +} \ No newline at end of file diff --git a/tests/Mooc/Courses/Application/Find/CourseFinderTest.php b/tests/Mooc/Courses/Application/Find/CourseFinderTest.php new file mode 100644 index 000000000..e6a500e56 --- /dev/null +++ b/tests/Mooc/Courses/Application/Find/CourseFinderTest.php @@ -0,0 +1,47 @@ +finder = new CourseFinder($this->repository()); + } + + /** @test */ + public function it_should_throw_an_exception_when_the_course_not_exist(): void + { + $this->expectException(CourseNotExist::class); + + $id = CourseIdMother::create(); + + $this->shouldSearch($id, null); + + $this->finder->__invoke($id); + } + + /** @test */ + public function it_should_find_an_existing_courses(): void + { + $course = CourseMother::create(); + + $this->shouldSearch($course->id(), $course); + + $courseFromRepository = $this->finder->__invoke($course->id()); + + $this->assertEquals($courseFromRepository, $course); + } +} \ No newline at end of file diff --git a/tests/Mooc/Courses/Application/Update/CourseRenamerTest.php b/tests/Mooc/Courses/Application/Update/CourseRenamerTest.php index 2815aa7fe..240cfc628 100644 --- a/tests/Mooc/Courses/Application/Update/CourseRenamerTest.php +++ b/tests/Mooc/Courses/Application/Update/CourseRenamerTest.php @@ -48,4 +48,4 @@ public function it_should_throw_an_exception_when_the_course_not_exist(): void $this->renamer->__invoke($id, CourseNameMother::create()); } -} +} \ No newline at end of file From 587cd5eb4c96429db42bc03825a1e4faf2f630cb Mon Sep 17 00:00:00 2001 From: Ivan Cordon Date: Sat, 24 Apr 2021 12:51:11 +0200 Subject: [PATCH 4/5] Added CourseFinderTest. Update video title command: Add command, handler and tests --- .../Update/UpdateVideoTitleCommand.php | 28 +++++++++++ .../Update/UpdateVideoTitleCommandHandler.php | 25 ++++++++++ .../UpdateVideoTitleCommandHandlerTest.php | 37 +++++++++++++++ .../Update/UpdateVideoTitleCommandMother.php | 29 ++++++++++++ tests/Mooc/Videos/Domain/VideoIdMother.php | 17 +++++++ tests/Mooc/Videos/Domain/VideoMother.php | 47 +++++++++++++++++++ tests/Mooc/Videos/Domain/VideoTitleMother.php | 16 +++++++ tests/Mooc/Videos/Domain/VideoTypeMother.php | 16 +++++++ tests/Mooc/Videos/Domain/VideoUrlMother.php | 17 +++++++ .../VideosModuleUnitTestCase.php | 43 +++++++++++++++++ tests/Shared/Domain/TypeMother.php | 17 +++++++ tests/Shared/Domain/UrlMother.php | 13 +++++ 12 files changed, 305 insertions(+) create mode 100644 src/Mooc/Videos/Application/Update/UpdateVideoTitleCommand.php create mode 100644 src/Mooc/Videos/Application/Update/UpdateVideoTitleCommandHandler.php create mode 100644 tests/Mooc/Videos/Application/Update/UpdateVideoTitleCommandHandlerTest.php create mode 100644 tests/Mooc/Videos/Application/Update/UpdateVideoTitleCommandMother.php create mode 100644 tests/Mooc/Videos/Domain/VideoIdMother.php create mode 100644 tests/Mooc/Videos/Domain/VideoMother.php create mode 100644 tests/Mooc/Videos/Domain/VideoTitleMother.php create mode 100644 tests/Mooc/Videos/Domain/VideoTypeMother.php create mode 100644 tests/Mooc/Videos/Domain/VideoUrlMother.php create mode 100644 tests/Mooc/Videos/Infrastructure/VideosModuleUnitTestCase.php create mode 100644 tests/Shared/Domain/TypeMother.php create mode 100644 tests/Shared/Domain/UrlMother.php diff --git a/src/Mooc/Videos/Application/Update/UpdateVideoTitleCommand.php b/src/Mooc/Videos/Application/Update/UpdateVideoTitleCommand.php new file mode 100644 index 000000000..dfdc9634f --- /dev/null +++ b/src/Mooc/Videos/Application/Update/UpdateVideoTitleCommand.php @@ -0,0 +1,28 @@ +id; + } + + public function getTitle(): 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 000000000..f4c208cdc --- /dev/null +++ b/src/Mooc/Videos/Application/Update/UpdateVideoTitleCommandHandler.php @@ -0,0 +1,25 @@ +getId()); + $title = new VideoTitle($command->getTitle()); + + $this->titleUpdater->__invoke($id, $title); + } +} diff --git a/tests/Mooc/Videos/Application/Update/UpdateVideoTitleCommandHandlerTest.php b/tests/Mooc/Videos/Application/Update/UpdateVideoTitleCommandHandlerTest.php new file mode 100644 index 000000000..74b3b5d90 --- /dev/null +++ b/tests/Mooc/Videos/Application/Update/UpdateVideoTitleCommandHandlerTest.php @@ -0,0 +1,37 @@ +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/UpdateVideoTitleCommandMother.php b/tests/Mooc/Videos/Application/Update/UpdateVideoTitleCommandMother.php new file mode 100644 index 000000000..e9ff97b96 --- /dev/null +++ b/tests/Mooc/Videos/Application/Update/UpdateVideoTitleCommandMother.php @@ -0,0 +1,29 @@ +value() ?? VideoIdMother::create()->value(), + $title->value() ?? VideoTitleMother::create()->value() + ); + } + + public static function withIdAndTitle(VideoId $id, VideoTitle $title): UpdateVideoTitleCommand + { + return self::create($id, $title); + } +} diff --git a/tests/Mooc/Videos/Domain/VideoIdMother.php b/tests/Mooc/Videos/Domain/VideoIdMother.php new file mode 100644 index 000000000..3558b16ce --- /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 000000000..4cfb4f1c5 --- /dev/null +++ b/tests/Mooc/Videos/Domain/VideoTitleMother.php @@ -0,0 +1,16 @@ +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/TypeMother.php b/tests/Shared/Domain/TypeMother.php new file mode 100644 index 000000000..ca6b887b1 --- /dev/null +++ b/tests/Shared/Domain/TypeMother.php @@ -0,0 +1,17 @@ +value(); + } +} diff --git a/tests/Shared/Domain/UrlMother.php b/tests/Shared/Domain/UrlMother.php new file mode 100644 index 000000000..5bb1f3f2f --- /dev/null +++ b/tests/Shared/Domain/UrlMother.php @@ -0,0 +1,13 @@ +url; + } +} From 074b0ecc5df2503e0cf1da9085e9f147e04eb5cb Mon Sep 17 00:00:00 2001 From: Ivan Cordon Date: Sat, 24 Apr 2021 13:03:25 +0200 Subject: [PATCH 5/5] Update video title command: Add test case when video does not exist --- .../UpdateVideoTitleCommandHandlerTest.php | 16 ++++++++++++++++ .../Update/UpdateVideoTitleCommandMother.php | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/tests/Mooc/Videos/Application/Update/UpdateVideoTitleCommandHandlerTest.php b/tests/Mooc/Videos/Application/Update/UpdateVideoTitleCommandHandlerTest.php index 74b3b5d90..6dce6e15f 100644 --- a/tests/Mooc/Videos/Application/Update/UpdateVideoTitleCommandHandlerTest.php +++ b/tests/Mooc/Videos/Application/Update/UpdateVideoTitleCommandHandlerTest.php @@ -4,6 +4,8 @@ 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; @@ -34,4 +36,18 @@ public function it_should_update_video_title_when_video_exists(): void $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); + } + } diff --git a/tests/Mooc/Videos/Application/Update/UpdateVideoTitleCommandMother.php b/tests/Mooc/Videos/Application/Update/UpdateVideoTitleCommandMother.php index e9ff97b96..e7248da62 100644 --- a/tests/Mooc/Videos/Application/Update/UpdateVideoTitleCommandMother.php +++ b/tests/Mooc/Videos/Application/Update/UpdateVideoTitleCommandMother.php @@ -22,6 +22,11 @@ public static function create( ); } + 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);