|
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,23 @@ 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 | + |
| 164 | + $help = $allFailures->isEmpty() |
| 165 | + ? "" |
| 166 | + : sprintf("\n\nAll Failures:\n\n\n", $allFailures->implode("\n")); |
| 167 | + |
| 168 | + $this->assertCount(1, $failures, "No failure with reason: '$reason' . $help"); |
151 | 169 | }
|
152 | 170 |
|
153 | 171 | public function assertOutputWasIncorrect(): void
|
@@ -203,4 +221,16 @@ public function assertResultsHasFailureAndMatches(string $resultClass, callable
|
203 | 221 | $this->assertTrue($matcher($failure));
|
204 | 222 | });
|
205 | 223 | }
|
| 224 | + |
| 225 | + public function removeSolutionAsset(string $file): void |
| 226 | + { |
| 227 | + $path = sprintf( |
| 228 | + '%s/test/solutions/%s/%s', |
| 229 | + rtrim($this->container->get('basePath'), '/'), |
| 230 | + AbstractExercise::normaliseName($this->getExercise()->getName()), |
| 231 | + $file |
| 232 | + ); |
| 233 | + |
| 234 | + (new Filesystem())->remove($path); |
| 235 | + } |
206 | 236 | }
|
0 commit comments