@@ -46,8 +46,7 @@ public function testExceptionIsThrownIfReferenceFileDoesNotExist(): void
4646
4747 public function testFailureIsReturnedIfStudentsFileDoesNotExist (): void
4848 {
49- $ file = $ this ->getTemporaryFile ('solution/some-file.txt ' );
50- file_put_contents ($ file , "name,age \nAydin,33 \nMichael,29 \n" );
49+ $ referenceFile = $ this ->getTemporaryFile ('solution/some-file.txt ' , "name,age \nAydin,33 \nMichael,29 \n" );
5150
5251 $ exercise = new FileComparisonExercise (['some-file.txt ' ]);
5352 $ exercise ->setSolution (new SingleFileSolution ($ this ->getTemporaryFile ('solution/solution.php ' )));
@@ -60,17 +59,15 @@ public function testFailureIsReturnedIfStudentsFileDoesNotExist(): void
6059
6160 public function testFailureIsReturnedIfStudentFileDosNotMatchReferenceFile (): void
6261 {
63- $ file = $ this ->getTemporaryFile ('solution/some-file.txt ' );
64- file_put_contents ($ file , "name,age \nAydin,33 \nMichael,29 \n" );
65-
66- $ studentSolution = $ this ->getTemporaryFile ('student/my-solution.php ' );
67- $ studentFile = $ this ->getTemporaryFile ('student/some-file.txt ' );
68- file_put_contents ($ studentFile , "somegibberish " );
62+ $ referenceFile = $ this ->getTemporaryFile ('solution/some-file.txt ' , "name,age \nAydin,33 \nMichael,29 \n" );
63+ $ studentFile = $ this ->getTemporaryFile ('student/some-file.txt ' , "somegibberish " );
6964
7065 $ exercise = new FileComparisonExercise (['some-file.txt ' ]);
7166 $ exercise ->setSolution (new SingleFileSolution ($ this ->getTemporaryFile ('solution/solution.php ' )));
7267
73- $ failure = $ this ->check ->check ($ exercise , new Input ('app ' , ['program ' => $ studentSolution ]));
68+ $ failure = $ this ->check ->check ($ exercise , new Input ('app ' , [
69+ 'program ' => $ this ->getTemporaryFile ('student/my-solution.php ' )
70+ ]));
7471
7572 $ this ->assertInstanceOf (FileComparisonFailure::class, $ failure );
7673 $ this ->assertEquals ($ failure ->getFileName (), 'some-file.txt ' );
@@ -80,19 +77,41 @@ public function testFailureIsReturnedIfStudentFileDosNotMatchReferenceFile(): vo
8077
8178 public function testSuccessIsReturnedIfFilesMatch (): void
8279 {
83- $ file = $ this ->getTemporaryFile ('solution/some-file.txt ' );
84- file_put_contents ($ file , "name,age \nAydin,33 \nMichael,29 \n" );
85-
86- $ studentSolution = $ this ->getTemporaryFile ('student/my-solution.php ' );
87- $ studentFile = $ this ->getTemporaryFile ('student/some-file.txt ' );
88- file_put_contents ($ studentFile , "name,age \nAydin,33 \nMichael,29 \n" );
80+ $ referenceFile = $ this ->getTemporaryFile ('solution/some-file.txt ' , "name,age \nAydin,33 \nMichael,29 \n" );
81+ $ studentFile = $ this ->getTemporaryFile ('student/some-file.txt ' , "name,age \nAydin,33 \nMichael,29 \n" );
8982
9083 $ exercise = new FileComparisonExercise (['some-file.txt ' ]);
9184 $ exercise ->setSolution (new SingleFileSolution ($ this ->getTemporaryFile ('solution/solution.php ' )));
9285
9386 $ this ->assertInstanceOf (
9487 Success::class,
95- $ this ->check ->check ($ exercise , new Input ('app ' , ['program ' => $ studentSolution ]))
88+ $ this ->check ->check ($ exercise , new Input ('app ' , [
89+ 'program ' => $ this ->getTemporaryFile ('student/my-solution.php ' )
90+ ]))
91+ );
92+ }
93+
94+ public function testFailureIsReturnedIfFileDoNotMatchUsingStrip (): void
95+ {
96+ $ referenceFile = $ this ->getTemporaryFile (
97+ 'solution/some-file.txt ' ,
98+ "01:03name,age \n04:05Aydin,33 \n17:21Michael,29 \n"
99+ );
100+ $ studentFile = $ this ->getTemporaryFile (
101+ 'student/some-file.txt ' ,
102+ "01:04name,age \n06:76Aydin,34 \n99:00Michael,29 \n"
96103 );
104+
105+ $ exercise = new FileComparisonExercise (['some-file.txt ' => ['strip ' => '/\d{2}:\d{2}/ ' ]]);
106+ $ exercise ->setSolution (new SingleFileSolution ($ this ->getTemporaryFile ('solution/solution.php ' )));
107+
108+ $ failure = $ this ->check ->check ($ exercise , new Input ('app ' , [
109+ 'program ' => $ this ->getTemporaryFile ('student/my-solution.php ' )
110+ ]));
111+
112+ $ this ->assertInstanceOf (FileComparisonFailure::class, $ failure );
113+ $ this ->assertEquals ($ failure ->getFileName (), 'some-file.txt ' );
114+ $ this ->assertEquals ($ failure ->getExpectedValue (), "01:03name,age \n04:05Aydin,33 \n17:21Michael,29 \n" );
115+ $ this ->assertEquals ($ failure ->getActualValue (), "01:04name,age \n06:76Aydin,34 \n99:00Michael,29 \n" );
97116 }
98117}
0 commit comments