-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathCourseFinderTest.php
58 lines (47 loc) · 1.82 KB
/
CourseFinderTest.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
52
53
54
55
56
57
58
<?php
namespace CodelyTv\Tests\Mooc\Courses\Application\Find;
use CodelyTv\Mooc\Courses\Application\Find\CourseFinder;
use CodelyTv\Mooc\Courses\Domain\CourseNotExist;
use CodelyTv\Mooc\Shared\Domain\Courses\CourseId;
use CodelyTv\Tests\Mooc\Courses\CoursesModuleUnitTestCase;
use CodelyTv\Tests\Mooc\Courses\Domain\CourseMother;
use CodelyTv\Mooc\Courses\Domain\Course;
class CourseFinderTest extends CoursesModuleUnitTestCase
{
private CourseFinder $courseFinder;
protected function setUp(): void
{
parent::setUp();
$this->courseFinder = new CourseFinder($this->repository());
}
public function testCourseFinderShouldFindAnExistingCourse()
{
$course = $this->givenACourse();
$actual = $this->whenFinderIsInvoked($course->id(), $course);
$this->thenTheCourseShouldBeTheExpected($course, $actual);
}
public function testCourseFinderShouldThrowExceptionWhenCourseNotFound()
{
$course = $this->givenACourse();
$this->whenFinderIsInvokedThenShouldThrowCourseNotFoundException($course->id());
}
private function givenACourse(): Course
{
return CourseMother::create();
}
private function whenFinderIsInvoked(CourseId $courseId, Course $course): Course
{
$this->shouldSearch($courseId, $course);
return $this->courseFinder->__invoke($course->id());
}
private function thenTheCourseShouldBeTheExpected(Course $course, Course $actual): void
{
$this->assertSimilar($course, $actual);
}
private function whenFinderIsInvokedThenShouldThrowCourseNotFoundException(CourseId $courseId)
{
$this->expectException(CourseNotExist::class);
$this->searchShouldThrowException($courseId, new CourseNotExist($courseId));
$this->courseFinder->__invoke($courseId);
}
}