File tree Expand file tree Collapse file tree 2 files changed +57
-1
lines changed
Expand file tree Collapse file tree 2 files changed +57
-1
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace PhpSchool \PhpWorkshopTest \Asset ;
4+
5+ use PhpSchool \PhpWorkshop \Exercise \AbstractExercise ;
6+ use PhpSchool \PhpWorkshop \Exercise \ExerciseInterface ;
7+ use PhpSchool \PhpWorkshop \Exercise \ExerciseType ;
8+
9+ /**
10+ * @author Aydin Hassan <aydin@hotmail.co.uk>
11+ */
12+ class CliExerciseMissingInterface extends AbstractExercise implements ExerciseInterface
13+ {
14+
15+ /**
16+ * Get the name of the exercise, like `Hello World!`.
17+ *
18+ * @return string
19+ */
20+ public function getName ()
21+ {
22+ return 'CLI exercise missing interface ' ;
23+ }
24+
25+ /**
26+ * A short description of the exercise.
27+ *
28+ * @return string
29+ */
30+ public function getDescription ()
31+ {
32+ return 'CLI exercise missing interface ' ;
33+ }
34+
35+ /**
36+ * Return the type of exercise. This is an ENUM. See `PhpSchool\PhpWorkshop\Exercise\ExerciseType`.
37+ *
38+ * @return ExerciseType
39+ */
40+ public function getType ()
41+ {
42+ return ExerciseType::CLI ();
43+ }
44+ }
Original file line number Diff line number Diff line change 22
33namespace PhpSchool \PhpWorkshopTest ;
44
5- use InvalidArgumentException ;
5+ use PhpSchool \ PhpWorkshop \ Exception \ InvalidArgumentException ;
66use PhpSchool \PhpWorkshop \Exercise \ExerciseType ;
77use PhpSchool \PhpWorkshopTest \Asset \CliExerciseImpl ;
88use PhpSchool \PhpWorkshopTest \Asset \CliExerciseInterface ;
9+ use PhpSchool \PhpWorkshopTest \Asset \CliExerciseMissingInterface ;
910use PHPUnit_Framework_TestCase ;
1011use PhpSchool \PhpWorkshop \Exercise \ExerciseInterface ;
1112use PhpSchool \PhpWorkshop \ExerciseRepository ;
@@ -81,4 +82,15 @@ public function testIterator()
8182 $ repo = new ExerciseRepository ($ exercises );
8283 $ this ->assertEquals ($ exercises , iterator_to_array ($ repo ));
8384 }
85+
86+ public function testExceptionIsThrownWhenTryingToAddExerciseWhichDoesNotImplementCorrectInterface ()
87+ {
88+ $ this ->expectException (InvalidArgumentException::class);
89+ $ message = '"PhpSchool\PhpWorkshopTest\Asset\CliExerciseMissingInterface" is required to implement ' ;
90+ $ message .= '"PhpSchool\PhpWorkshop\Exercise\CliExercise", but it does not ' ;
91+ $ this ->expectExceptionMessage ($ message );
92+
93+ $ exercise = new CliExerciseMissingInterface ;
94+ new ExerciseRepository ([$ exercise ]);
95+ }
8496}
You can’t perform that action at this time.
0 commit comments