-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathExerciseRendererTest.php
More file actions
97 lines (82 loc) · 3.13 KB
/
ExerciseRendererTest.php
File metadata and controls
97 lines (82 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
namespace PhpSchool\PhpWorkshopTest;
use PhpSchool\CliMdRenderer\CliRendererFactory;
use Colors\Color;
use League\CommonMark\DocParser;
use League\CommonMark\Environment;
use PhpSchool\CliMenu\CliMenu;
use PhpSchool\CliMenu\MenuItem\MenuItemInterface;
use PhpSchool\PhpWorkshop\UserState\Serializer;
use PhpSchool\PhpWorkshop\UserState\UserState;
use PhpSchool\Terminal\Terminal;
use PHPUnit\Framework\TestCase;
use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface;
use PhpSchool\PhpWorkshop\ExerciseRenderer;
use PhpSchool\PhpWorkshop\ExerciseRepository;
use PhpSchool\PhpWorkshop\MarkdownRenderer;
use PhpSchool\PhpWorkshop\Output\StdOutput;
class ExerciseRendererTest extends TestCase
{
public function testExerciseRendererSetsCurrentExerciseAndRendersExercise(): void
{
$menu = $this->createMock(CliMenu::class);
$item = $this->createMock(MenuItemInterface::class);
$item
->method('getText')
->willReturn('Exercise 2');
$menu
->expects($this->once())
->method('getSelectedItem')
->willReturn($item);
$exercise1 = $this->createMock(ExerciseInterface::class);
$exercise2 = $this->createMock(ExerciseInterface::class);
$exercises = [$exercise1, $exercise2];
$exerciseRepository = $this->createMock(ExerciseRepository::class);
$userState = $this->createMock(UserState::class);
$userStateSerializer = $this->createMock(Serializer::class);
$exerciseRepository
->expects($this->once())
->method('findByName')
->with('Exercise 2')
->willReturn($exercise2);
$exerciseRepository
->expects($this->once())
->method('findAll')
->willReturn($exercises);
$userState
->expects($this->once())
->method('setCurrentExercise')
->with('Exercise 2');
$userStateSerializer
->expects($this->once())
->method('serialize')
->with($userState);
$problemFile = sprintf('%s/%s/problem.md', sys_get_temp_dir(), $this->getName());
$exercise2
->expects($this->once())
->method('getProblem')
->willReturn($problemFile);
if (!is_dir(dirname($problemFile))) {
mkdir(dirname($problemFile), 0775, true);
}
file_put_contents($problemFile, '### Exercise Content');
$markdownRenderer = new MarkdownRenderer(
new DocParser(Environment::createCommonMarkEnvironment()),
(new CliRendererFactory())->__invoke(),
);
$color = new Color();
$color->setForceStyle(true);
$exerciseRenderer = new ExerciseRenderer(
'phpschool',
$exerciseRepository,
$userState,
$userStateSerializer,
$markdownRenderer,
$color,
new StdOutput($color, $this->createMock(Terminal::class)),
);
$this->expectOutputString(file_get_contents(__DIR__ . '/res/exercise-help-expected.txt'));
$exerciseRenderer->__invoke($menu);
unlink($problemFile);
}
}