|
21 | 21 | use PhpSchool\PhpWorkshop\Result\ResultGroupInterface;
|
22 | 22 | use PhpSchool\PhpWorkshop\Result\ResultInterface;
|
23 | 23 | use PhpSchool\PhpWorkshop\ResultAggregator;
|
| 24 | +use PhpSchool\PhpWorkshop\Utils\ArrayObject; |
24 | 25 | use PhpSchool\PhpWorkshop\Utils\Collection;
|
25 | 26 | use PHPUnit\Framework\ExpectationFailedException;
|
26 | 27 | use PHPUnit\Framework\TestCase;
|
27 | 28 | use Psr\Container\ContainerInterface;
|
28 | 29 | use PhpSchool\PhpWorkshop\Input\Input;
|
| 30 | +use Symfony\Component\Filesystem\Filesystem; |
29 | 31 | use Symfony\Component\Process\Process;
|
30 | 32 |
|
31 | 33 | abstract class WorkshopExerciseTest extends TestCase
|
@@ -58,7 +60,7 @@ abstract public function getExerciseClass(): string;
|
58 | 60 |
|
59 | 61 | abstract public function getApplication(): Application;
|
60 | 62 |
|
61 |
| - private function getExercise(): ExerciseInterface |
| 63 | + protected function getExercise(): ExerciseInterface |
62 | 64 | {
|
63 | 65 | return $this->container->get(ExerciseRepository::class)
|
64 | 66 | ->findByClassName($this->getExerciseClass());
|
@@ -147,7 +149,26 @@ public function assertResultsHasFailure(string $resultClass, string $reason): vo
|
147 | 149 | return $failure->getReason() === $reason;
|
148 | 150 | });
|
149 | 151 |
|
150 |
| - $this->assertCount(1, $failures, "No failure with reason: '$reason'"); |
| 152 | + $allFailures = (new Collection($this->results->getIterator()->getArrayCopy())) |
| 153 | + ->filter(function (ResultInterface $result) { |
| 154 | + return $result instanceof FailureInterface; |
| 155 | + }) |
| 156 | + ->map(function (FailureInterface $failure) { |
| 157 | + return sprintf( |
| 158 | + ' * %s%s', |
| 159 | + get_class($failure), |
| 160 | + $failure instanceof Failure ? ": {$failure->getReason()}" : '' |
| 161 | + ); |
| 162 | + }) |
| 163 | + ->implode("\n"); |
| 164 | + |
| 165 | + if ($allFailures) { |
| 166 | + $allFailures = "\n\nAll Failures:\n$allFailures\n\n"; |
| 167 | + } else { |
| 168 | + $allFailures = ""; |
| 169 | + } |
| 170 | + |
| 171 | + $this->assertCount(1, $failures, "No failure with reason: '$reason'.$allFailures"); |
151 | 172 | }
|
152 | 173 |
|
153 | 174 | public function assertOutputWasIncorrect(): void
|
@@ -203,4 +224,16 @@ public function assertResultsHasFailureAndMatches(string $resultClass, callable
|
203 | 224 | $this->assertTrue($matcher($failure));
|
204 | 225 | });
|
205 | 226 | }
|
| 227 | + |
| 228 | + public function removeSolutionAsset(string $file): void |
| 229 | + { |
| 230 | + $path = sprintf( |
| 231 | + '%s/test/solutions/%s/%s', |
| 232 | + rtrim($this->container->get('basePath'), '/'), |
| 233 | + AbstractExercise::normaliseName($this->getExercise()->getName()), |
| 234 | + $file |
| 235 | + ); |
| 236 | + |
| 237 | + (new Filesystem())->remove($path); |
| 238 | + } |
206 | 239 | }
|
0 commit comments