|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace PhpSchool\PHP8AppreciateTest\Exercise; |
| 4 | + |
| 5 | +use PhpSchool\PHP8Appreciate\Exercise\LordOfTheStrings; |
| 6 | +use PhpSchool\PhpWorkshop\Application; |
| 7 | +use PhpSchool\PhpWorkshop\Result\Failure; |
| 8 | +use PhpSchool\PhpWorkshop\Result\FunctionRequirementsFailure; |
| 9 | +use PhpSchool\PhpWorkshop\TestUtils\WorkshopExerciseTest; |
| 10 | + |
| 11 | +class LordOfTheStringsTest extends WorkshopExerciseTest |
| 12 | +{ |
| 13 | + |
| 14 | + public function getApplication(): Application |
| 15 | + { |
| 16 | + return require __DIR__ . '/../../app/bootstrap.php'; |
| 17 | + } |
| 18 | + |
| 19 | + public function getExerciseClass(): string |
| 20 | + { |
| 21 | + return LordOfTheStrings::class; |
| 22 | + } |
| 23 | + |
| 24 | + public function testWithNoComposerFile(): void |
| 25 | + { |
| 26 | + $this->runExercise('solution-no-code.php'); |
| 27 | + |
| 28 | + $this->assertVerifyWasNotSuccessful(); |
| 29 | + $this->assertResultsHasFailure(Failure::class, 'No composer.json file found'); |
| 30 | + } |
| 31 | + |
| 32 | + public function testWithNoCode(): void |
| 33 | + { |
| 34 | + $this->runExercise('no-code/solution.php'); |
| 35 | + |
| 36 | + $this->assertVerifyWasNotSuccessful(); |
| 37 | + |
| 38 | + $this->assertResultsHasFailure(Failure::class, 'No code was found'); |
| 39 | + } |
| 40 | + |
| 41 | + public function testUsingBannedFunction(): void |
| 42 | + { |
| 43 | + $this->runExercise('banned-functions/solution.php'); |
| 44 | + |
| 45 | + $this->assertVerifyWasNotSuccessful(); |
| 46 | + |
| 47 | + $this->assertResultsHasFailureAndMatches( |
| 48 | + FunctionRequirementsFailure::class, |
| 49 | + function (FunctionRequirementsFailure $failure) { |
| 50 | + self::assertSame( |
| 51 | + [ |
| 52 | + ['function' => 'strpos', 'line' => 14], |
| 53 | + ['function' => 'strpos', 'line' => 15], |
| 54 | + ['function' => 'substr', 'line' => 16], |
| 55 | + ], |
| 56 | + $failure->getBannedFunctions() |
| 57 | + ); |
| 58 | + |
| 59 | + self::assertSame( |
| 60 | + ['str_contains', 'str_starts_with', 'str_ends_with'], |
| 61 | + $failure->getMissingFunctions() |
| 62 | + ); |
| 63 | + |
| 64 | + return true; |
| 65 | + } |
| 66 | + ); |
| 67 | + } |
| 68 | + |
| 69 | + public function testWithCorrectSolution(): void |
| 70 | + { |
| 71 | + $this->runExercise('correct-solution/solution.php'); |
| 72 | + |
| 73 | + $this->assertVerifyWasSuccessful(); |
| 74 | + } |
| 75 | +} |
0 commit comments