Skip to content

Commit 652fa66

Browse files
committed
Add tests
1 parent 4443035 commit 652fa66

File tree

11 files changed

+2775
-0
lines changed

11 files changed

+2775
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "php8-appreciate/lord-of-the-strings",
3+
"description": "String manipulation with Composer",
4+
"require": {
5+
"symfony/console": "^5"
6+
}
7+
}

0 commit comments

Comments
 (0)