1010
1111final class CourseStepsGetTest extends TestCase
1212{
13+ private Platform $ platform ;
14+ private CourseStepsGetController $ courseStepGetController ;
15+
16+ public function setUp (): void
17+ {
18+ $ this ->platform = $ this ->createMock (Platform::class);
19+ $ this ->courseStepGetController = new CourseStepsGetController ($ this ->platform );
20+ }
21+
1322 /** @test */
1423 public function shouldReturnEmptyStepList (): void
1524 {
16- $ platform = $ this ->createMock (Platform::class);
17- $ platform
18- ->method ('findCourseSteps ' )
19- ->willReturn ('' );
20-
21- $ sut = new CourseStepsGetController ($ platform );
25+ $ courseId = '8fe17ce6-1d33-4b6b-a27c-4e0d1f870a19 ' ;
26+ $ emptyCsv = '' ;
27+ $ this ->givenPlatformReturnsCourseStepCsv ($ courseId , $ emptyCsv );
2228
23- $ results = $ sut -> get (' 73D74817-CC25-477D-BF3E-36130087293F ' );
29+ $ results = $ this -> courseStepGetController -> get ($ courseId );
2430
2531 self ::assertSame ('[] ' , $ results );
2632 }
2733
2834 /** @test */
2935 public function shouldReturnExistingCourseSteps (): void
3036 {
31- $ platform = $ this ->createMock (Platform::class);
32- $ platform
33- ->method ('findCourseSteps ' )
34- ->with ('73D74817-CC25-477D-BF3E-36130087293F ' )
35- ->willReturn (
36- '"1","video","","13"
37- "2","quiz","5","" '
38- );
37+ $ courseId = '8fe17ce6-1d33-4b6b-a27c-4e0d1f870a19 ' ;
38+ $ csv = '"1","video","","13"
39+ "2","quiz","5","" ' ;
40+ $ this ->givenPlatformReturnsCourseStepCsv ($ courseId , $ csv );
3941
40- $ sut = new CourseStepsGetController ($ platform );
41-
42- $ results = $ sut ->get ('73D74817-CC25-477D-BF3E-36130087293F ' );
42+ $ results = $ this ->courseStepGetController ->get ($ courseId );
4343
4444 $ expected = '[{"id":"1","type":"video","duration":14.3,"points":1430},{"id":"2","type":"quiz","duration":2.5,"points":25}] ' ;
4545 self ::assertSame ($ expected , $ results );
@@ -48,18 +48,20 @@ public function shouldReturnExistingCourseSteps(): void
4848 /** @test */
4949 public function shouldIgnoreStepsWithInvalidType (): void
5050 {
51- $ platform = $ this ->createMock (Platform::class);
52- $ platform
53- ->method ('findCourseSteps ' )
54- ->with ('73D74817-CC25-477D-BF3E-36130087293F ' )
55- ->willReturn (
56- '"1","survey","","13" '
57- );
51+ $ courseId = '8fe17ce6-1d33-4b6b-a27c-4e0d1f870a19 ' ;
52+ $ csv = '"1","survey","","13" ' ;
53+ $ this ->givenPlatformReturnsCourseStepCsv ($ courseId , $ csv );
5854
59- $ sut = new CourseStepsGetController ($ platform );
60-
61- $ results = $ sut ->get ('73D74817-CC25-477D-BF3E-36130087293F ' );
55+ $ results = $ this ->courseStepGetController ->get ($ courseId );
6256
6357 self ::assertSame ('[] ' , $ results );
6458 }
59+
60+ private function givenPlatformReturnsCourseStepCsv (string $ courseId , string $ csv ): void
61+ {
62+ $ this ->platform
63+ ->method ('findCourseSteps ' )
64+ ->with ($ courseId )
65+ ->willReturn ($ csv );
66+ }
6567}
0 commit comments