File tree Expand file tree Collapse file tree 5 files changed +162
-0
lines changed Expand file tree Collapse file tree 5 files changed +162
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace PhpSchool \PhpWorkshop \Exercise \Scenario ;
4+
5+ use Psr \Http \Message \RequestInterface ;
6+
7+ class CgiScenario extends ExerciseScenario
8+ {
9+ /**
10+ * @var array<RequestInterface>
11+ */
12+ private array $ executions = [];
13+
14+ public function withExecution (RequestInterface $ request ): self
15+ {
16+ $ this ->executions [] = $ request ;
17+
18+ return $ this ;
19+ }
20+
21+ /**
22+ * @return array<RequestInterface>
23+ */
24+ public function getExecutions (): array
25+ {
26+ return $ this ->executions ;
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace PhpSchool \PhpWorkshop \Exercise \Scenario ;
4+
5+ use PhpSchool \PhpWorkshop \Utils \Collection ;
6+
7+ class CliScenario extends ExerciseScenario
8+ {
9+ /**
10+ * @var array<Collection<int, string>>
11+ */
12+ private array $ executions = [];
13+
14+ /**
15+ * @param array<string> $args
16+ */
17+ public function withExecution (array $ args = []): static
18+ {
19+ $ this ->executions [] = new Collection ($ args );
20+
21+ return $ this ;
22+ }
23+
24+ /**
25+ * @return array<Collection<int, string>>
26+ */
27+ public function getExecutions (): array
28+ {
29+ return $ this ->executions ;
30+ }
31+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace PhpSchool \PhpWorkshop \Exercise \Scenario ;
4+
5+ abstract class ExerciseScenario
6+ {
7+ /**
8+ * @var array<string, string>
9+ */
10+ private array $ files = [];
11+
12+ public function withFile (string $ relativeFileName , string $ content ): static
13+ {
14+ $ this ->files [$ relativeFileName ] = $ content ;
15+
16+ return $ this ;
17+ }
18+
19+ /**
20+ * @return array<string, string>
21+ */
22+ public function getFiles (): array
23+ {
24+ return $ this ->files ;
25+ }
26+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace PhpSchool \PhpWorkshopTest \Exercise \Scenario ;
4+
5+ use PhpSchool \PhpWorkshop \Exercise \Scenario \CgiScenario ;
6+ use PhpSchool \PhpWorkshop \Utils \Collection ;
7+ use PHPUnit \Framework \TestCase ;
8+ use Psr \Http \Message \RequestInterface ;
9+
10+ class CgiScenarioTest extends TestCase
11+ {
12+ public function testScenario (): void
13+ {
14+ $ requestOne = $ this ->createMock (RequestInterface::class);
15+ $ requestTwo = $ this ->createMock (RequestInterface::class);
16+
17+ $ scenario = (new CgiScenario ())
18+ ->withFile ('file1.txt ' , 'content1 ' )
19+ ->withFile ('file2.txt ' , 'content2 ' )
20+ ->withExecution ($ requestOne )
21+ ->withExecution ($ requestTwo );
22+
23+ static ::assertEquals (
24+ [
25+ 'file1.txt ' => 'content1 ' ,
26+ 'file2.txt ' => 'content2 ' ,
27+ ],
28+ $ scenario ->getFiles ()
29+ );
30+
31+ static ::assertEquals (
32+ [
33+ $ requestOne ,
34+ $ requestTwo
35+ ],
36+ $ scenario ->getExecutions ()
37+ );
38+ }
39+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace PhpSchool \PhpWorkshopTest \Exercise \Scenario ;
4+
5+ use PhpSchool \PhpWorkshop \Exercise \Scenario \CliScenario ;
6+ use PhpSchool \PhpWorkshop \Utils \Collection ;
7+ use PHPUnit \Framework \TestCase ;
8+
9+ class CliScenarioTest extends TestCase
10+ {
11+ public function testScenario (): void
12+ {
13+ $ scenario = (new CliScenario ())
14+ ->withFile ('file1.txt ' , 'content1 ' )
15+ ->withFile ('file2.txt ' , 'content2 ' )
16+ ->withExecution (['arg1 ' , 'arg2 ' ])
17+ ->withExecution (['arg3 ' , 'arg4 ' ]);
18+
19+ static ::assertEquals (
20+ [
21+ 'file1.txt ' => 'content1 ' ,
22+ 'file2.txt ' => 'content2 ' ,
23+ ],
24+ $ scenario ->getFiles ()
25+ );
26+
27+ static ::assertEquals (
28+ [
29+ ['arg1 ' , 'arg2 ' ],
30+ ['arg3 ' , 'arg4 ' ],
31+ ],
32+ array_map (
33+ fn (Collection $ collection ) => $ collection ->getArrayCopy (),
34+ $ scenario ->getExecutions ()
35+ )
36+ );
37+ }
38+ }
You can’t perform that action at this time.
0 commit comments