Skip to content
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ vendor/
.env

build/
.idea
.env.local
apps/*/*/var/
26 changes: 0 additions & 26 deletions src/Mooc/Steps/Application/Create/CreateStepCommandHandler.php

This file was deleted.

9 changes: 1 addition & 8 deletions src/Mooc/Videos/Application/Create/CreateVideoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,21 @@

final class CreateVideoCommand extends Command
{
private $id;
private $type;
private $title;
private $url;
private $courseId;

public function __construct(Uuid $commandId, string $id, string $type, string $title, string $url, string $courseId)
public function __construct(Uuid $commandId, string $type, string $title, string $url, string $courseId)
{
parent::__construct($commandId);

$this->id = $id;
$this->type = $type;
$this->title = $title;
$this->url = $url;
$this->courseId = $courseId;
}

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

public function type(): string
{
return $this->type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ public function __construct(VideoCreator $creator)

public function __invoke(CreateVideoCommand $command)
{
$id = new VideoId($command->id());
$type = new VideoType($command->type());
$title = new VideoTitle($command->title());
$url = new VideoUrl($command->url());
$courseId = new CourseId($command->courseId());

$this->creator->create($id, $type, $title, $url, $courseId);
$this->creator->create($type, $title, $url, $courseId);
}
}
4 changes: 2 additions & 2 deletions src/Mooc/Videos/Application/Create/VideoCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public function __construct(VideoRepository $repository, DomainEventPublisher $p
$this->publisher = $publisher;
}

public function create(VideoId $id, VideoType $type, VideoTitle $title, VideoUrl $url, CourseId $courseId): void
public function create(VideoType $type, VideoTitle $title, VideoUrl $url, CourseId $courseId): void
{
$video = Video::create($id, $type, $title, $url, $courseId);
$video = Video::create($type, $title, $url, $courseId);

$this->repository->save($video);

Expand Down
8 changes: 5 additions & 3 deletions src/Mooc/Videos/Domain/Video.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use CodelyTv\Mooc\Shared\Domain\Courses\CourseId;
use CodelyTv\Mooc\Shared\Domain\Videos\VideoUrl;
use CodelyTv\Shared\Domain\Aggregate\AggregateRoot;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidFactory;

final class Video extends AggregateRoot
{
Expand All @@ -26,17 +28,17 @@ public function __construct(VideoId $id, VideoType $type, VideoTitle $title, Vid
}

public static function create(
VideoId $id,
VideoType $type,
VideoTitle $title,
VideoUrl $url,
CourseId $courseId
): Video {
$video = new self($id, $type, $title, $url, $courseId);
$videoId = new VideoId(Uuid::uuid4()->toString());
$video = new self($videoId, $type, $title, $url, $courseId);

$video->record(
new VideoCreatedDomainEvent(
$id->value(),
$videoId->value(),
[
'type' => $type->value(),
'title' => $title->value(),
Expand Down
6 changes: 4 additions & 2 deletions tests/src/Mooc/Videos/Application/Create/CreateVideoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use CodelyTv\Mooc\Videos\Application\Create\CreateVideoCommandHandler;
use CodelyTv\Mooc\Videos\Application\Create\VideoCreator;
use CodelyTv\Shared\Domain\ValueObject\Uuid;
use CodelyTv\Test\Mooc\Shared\Domain\Courses\CourseIdMother;
use CodelyTv\Test\Mooc\Shared\Domain\Videos\VideoUrlMother;
use CodelyTv\Test\Mooc\Videos\Domain\VideoCreatedDomainEventMother;
Expand All @@ -32,21 +33,22 @@ protected function setUp()
/** @test */
public function it_should_create_a_video(): void
{
// given
$command = CreateVideoCommandMother::random();

$id = VideoIdMother::create($command->id());
$id = VideoIdMother::create(Uuid::random()->value());
$type = VideoTypeMother::create($command->type());
$title = VideoTitleMother::create($command->title());
$url = VideoUrlMother::create($command->url());
$courseId = CourseIdMother::create($command->courseId());

$video = VideoMother::create($id, $type, $title, $url, $courseId);

$domainEvent = VideoCreatedDomainEventMother::create($id, $type, $title, $url, $courseId);

$this->shouldSaveVideo($video);
$this->shouldPublishDomainEvents($domainEvent);

// when
$this->dispatch($command, $this->handler);
}
}