Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update video title command #248

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,25 @@ 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
image: docker.elastic.co/elasticsearch/elasticsearch:6.8.10
image: docker.elastic.co/elasticsearch/elasticsearch:7.12.0
ports:
- 9200:9200
- 9300:9300
Expand Down Expand Up @@ -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
28 changes: 28 additions & 0 deletions src/Mooc/Videos/Application/Update/UpdateVideoTitleCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace CodelyTv\Mooc\Videos\Application\Update;

use CodelyTv\Shared\Domain\Bus\Command\Command;

final class UpdateVideoTitleCommand implements Command
{
public function __construct(
private string $id,
private string $title
)
{
}

public function getId(): string
{
return $this->id;
}

public function getTitle(): string
{
return $this->title;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace CodelyTv\Mooc\Videos\Application\Update;


use CodelyTv\Mooc\Videos\Domain\VideoId;
use CodelyTv\Mooc\Videos\Domain\VideoTitle;

final class UpdateVideoTitleCommandHandler
{

public function __construct(private VideoTitleUpdater $titleUpdater)
{
}

public function __invoke(UpdateVideoTitleCommand $command)
{
$id = new VideoId($command->getId());
$title = new VideoTitle($command->getTitle());

$this->titleUpdater->__invoke($id, $title);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ public function it_should_create_a_valid_course(): void

$this->dispatch($command, $this->handler);
}
}
}
47 changes: 47 additions & 0 deletions tests/Mooc/Courses/Application/Find/CourseFinderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace CodelyTv\Tests\Mooc\Courses\Application\Find;


use CodelyTv\Mooc\Courses\Application\Find\CourseFinder;
use CodelyTv\Mooc\Courses\Domain\CourseNotExist;
use CodelyTv\Tests\Mooc\Courses\CoursesModuleUnitTestCase;
use CodelyTv\Tests\Mooc\Courses\Domain\CourseIdMother;
use CodelyTv\Tests\Mooc\Courses\Domain\CourseMother;

class CourseFinderTest extends CoursesModuleUnitTestCase
{
private CourseFinder|null $finder;

protected function setUp(): void
{
parent::setUp();
$this->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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ public function it_should_throw_an_exception_when_the_course_not_exist(): void

$this->renamer->__invoke($id, CourseNameMother::create());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace CodelyTv\Tests\Mooc\Videos\Application\Update;

use CodelyTv\Mooc\Videos\Application\Update\UpdateVideoTitleCommand;
use CodelyTv\Mooc\Videos\Domain\VideoId;
use CodelyTv\Mooc\Videos\Domain\VideoTitle;
use CodelyTv\Tests\Mooc\Videos\Domain\VideoIdMother;
use CodelyTv\Tests\Mooc\Videos\Domain\VideoTitleMother;
use PHPUnit\Framework\TestCase;

class UpdateVideoTitleCommandMother extends TestCase
{
public static function create(
?VideoId $id = null,
?VideoTitle $title = null
): UpdateVideoTitleCommand
{
return new UpdateVideoTitleCommand(
$id->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);
}
}
17 changes: 17 additions & 0 deletions tests/Mooc/Videos/Domain/VideoIdMother.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace CodelyTv\Tests\Mooc\Videos\Domain;


use CodelyTv\Mooc\Videos\Domain\VideoId;
use CodelyTv\Tests\Shared\Domain\UuidMother;

final class VideoIdMother
{
public static function create(?string $value = null): VideoId
{
return new VideoId($value ?? UuidMother::create());
}
}
47 changes: 47 additions & 0 deletions tests/Mooc/Videos/Domain/VideoMother.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);


namespace CodelyTv\Tests\Mooc\Videos\Domain;


use CodelyTv\Mooc\Shared\Domain\Courses\CourseId;
use CodelyTv\Mooc\Shared\Domain\Videos\VideoUrl;
use CodelyTv\Mooc\Videos\Application\Create\CreateVideoCommand;
use CodelyTv\Mooc\Videos\Domain\Video;
use CodelyTv\Mooc\Videos\Domain\VideoId;
use CodelyTv\Mooc\Videos\Domain\VideoTitle;
use CodelyTv\Mooc\Videos\Domain\VideoType;
use CodelyTv\Tests\Mooc\Courses\Domain\CourseIdMother;

final class VideoMother
{
public static function create(
?VideoId $id = null,
?VideoType $type = null,
?VideoTitle $title = null,
?VideoUrl $url = null,
?CourseId $courseId = null
): Video
{
return new Video(
$id ?? VideoIdMother::create(),
$type ?? VideoTypeMother::create(),
$title ?? VideoTitleMother::create(),
$url ?? VideoUrlMother::create(),
$courseId ?? CourseIdMother::create()
);
}

public static function fromRequest(CreateVideoCommand $request): Video
{
return self::create(
VideoIdMother::create($request->id()),
VideoTypeMother::create($request->type()),
VideoTitleMother::create($request->title()),
VideoUrlMother::create($request->url()),
CourseIdMother::create($request->courseId())
);
}
}
16 changes: 16 additions & 0 deletions tests/Mooc/Videos/Domain/VideoTitleMother.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace CodelyTv\Tests\Mooc\Videos\Domain;

use CodelyTv\Mooc\Videos\Domain\VideoTitle;
use CodelyTv\Tests\Shared\Domain\WordMother;

final class VideoTitleMother
{
public static function create(?string $value = null): VideoTitle
{
return new VideoTitle($value ?? WordMother::create());
}
}
16 changes: 16 additions & 0 deletions tests/Mooc/Videos/Domain/VideoTypeMother.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace CodelyTv\Tests\Mooc\Videos\Domain;

use CodelyTv\Mooc\Videos\Domain\VideoType;
use CodelyTv\Tests\Shared\Domain\TypeMother;

final class VideoTypeMother
{
public static function create(?string $value = null): VideoType
{
return new VideoType($value ?? TypeMother::create());
}
}
17 changes: 17 additions & 0 deletions tests/Mooc/Videos/Domain/VideoUrlMother.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace CodelyTv\Tests\Mooc\Videos\Domain;


use CodelyTv\Mooc\Shared\Domain\Videos\VideoUrl;
use CodelyTv\Tests\Shared\Domain\UrlMother;

final class VideoUrlMother
{
public static function create(?string $value = null): VideoUrl
{
return new VideoUrl($value ?? UrlMother::create());
}
}
Loading