-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathCourseRenamerTest.php
51 lines (38 loc) · 1.51 KB
/
CourseRenamerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
declare(strict_types=1);
namespace CodelyTv\Tests\Mooc\Courses\Application\Update;
use CodelyTv\Mooc\Courses\Application\Update\CourseRenamer;
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;
use CodelyTv\Tests\Mooc\Courses\Domain\CourseNameMother;
use CodelyTv\Tests\Shared\Domain\DuplicatorMother;
final class CourseRenamerTest extends CoursesModuleUnitTestCase
{
private CourseRenamer|null $renamer;
protected function setUp(): void
{
parent::setUp();
$this->renamer = new CourseRenamer($this->repository(), $this->eventBus());
}
/** @test */
public function it_should_rename_an_existing_course(): void
{
$course = CourseMother::create();
$newName = CourseNameMother::create();
$renamedCourse = DuplicatorMother::with($course, ['name' => $newName]);
$this->shouldSearch($course->id(), $course);
$this->shouldSave($renamedCourse);
$this->shouldNotPublishDomainEvent();
$this->renamer->__invoke($course->id(), $newName);
}
/** @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->renamer->__invoke($id, CourseNameMother::create());
}
}