Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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
28 changes: 28 additions & 0 deletions 28 src/Mooc/Videos/Application/Update/UpdateVideoTitleCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace CodelyTv\Mooc\Videos\Application\Update;

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

class UpdateVideoTitleCommand implements Command
{

public function __construct(
private string $id,
private string $title
)
{
}

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

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


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

namespace CodelyTv\Mooc\Videos\Application\Update;

use CodelyTv\Mooc\Videos\Domain\VideoId;
use CodelyTv\Mooc\Videos\Domain\VideoTitle;
use CodelyTv\Shared\Domain\Bus\Command\CommandHandler;

class UpdateVideoTitleCommandHandler implements CommandHandler
{

private VideoTitleUpdater $titleUpdater;

public function __construct(VideoTitleUpdater $titleUpdater)
{
$this->titleUpdater = $titleUpdater;
}

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

$this->titleUpdater->__invoke($id, $title);
}
}
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);
}
}
36 changes: 36 additions & 0 deletions 36 tests/Mooc/Videos/Application/Update/VideoFinderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

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

use CodelyTv\Mooc\Videos\Application\Update\UpdateVideoTitleCommandHandler;
use CodelyTv\Mooc\Videos\Application\Update\VideoTitleUpdater;
use CodelyTv\Tests\Mooc\Videos\Domain\VideoMother;
use CodelyTv\Tests\Mooc\Videos\Domain\VideoTitleMother;
use CodelyTv\Tests\Mooc\Videos\VideosModuleUnitTestCase;
use CodelyTv\Tests\Shared\Domain\DuplicatorMother;

class VideoFinderTest 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);
}
}
44 changes: 44 additions & 0 deletions 44 tests/Mooc/Videos/Application/Update/VideoRenamerCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

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

use CodelyTv\Mooc\Videos\Application\Find\VideoFinder;
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\VideosModuleUnitTestCase;

class VideoRenamerCommandTest extends VideosModuleUnitTestCase
{
private VideoFinder|null $finder;

protected function setUp(): void
{
parent::setUp();
$this->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);
}
}
17 changes: 17 additions & 0 deletions 17 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\Shared\Domain\Courses\CourseId;
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());
}
}
46 changes: 46 additions & 0 deletions 46 tests/Mooc/Videos/Domain/VideoMother.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace CodelyTv\Tests\Mooc\Videos\Domain;

use CodelyTv\Mooc\Courses\Application\Create\CreateCourseCommand;
use CodelyTv\Mooc\Courses\Domain\Course;
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()),
);
}
}
14 changes: 14 additions & 0 deletions 14 tests/Mooc/Videos/Domain/VideoTitleMother.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace CodelyTv\Tests\Mooc\Videos\Domain;

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

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

namespace CodelyTv\Tests\Mooc\Videos\Domain;

use CodelyTv\Mooc\Videos\Domain\VideoType;

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

namespace CodelyTv\Tests\Mooc\Videos\Domain;

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

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

declare(strict_types=1);

namespace CodelyTv\Tests\Mooc\Videos;

use CodelyTv\Mooc\Courses\Domain\Course;
use CodelyTv\Mooc\Courses\Domain\CourseRepository;
use CodelyTv\Mooc\Shared\Domain\Courses\CourseId;
use CodelyTv\Mooc\Videos\Domain\Video;
use CodelyTv\Mooc\Videos\Domain\VideoId;
use CodelyTv\Mooc\Videos\Domain\VideoRepository;
use CodelyTv\Tests\Shared\Infrastructure\PhpUnit\UnitTestCase;
use Mockery\MockInterface;

abstract class VideosModuleUnitTestCase extends UnitTestCase
{
private VideoRepository|MockInterface|null $repository;

protected function shouldSave(Video $video): void
{
$this->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);
}
}
11 changes: 11 additions & 0 deletions 11 tests/Shared/Domain/UrlMother.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace CodelyTv\Tests\Shared\Domain;

class UrlMother
{
public static function create(): string
{
return MotherCreator::random()->url;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.