-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRunnerManagerTest.php
More file actions
72 lines (56 loc) 路 2.77 KB
/
Copy pathRunnerManagerTest.php
File metadata and controls
72 lines (56 loc) 路 2.77 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
<?php
namespace PhpSchool\PhpWorkshopTest\ExerciseRunner;
use PhpSchool\PhpWorkshop\CommandDefinition;
use PhpSchool\PhpWorkshop\Exception\InvalidArgumentException;
use PhpSchool\PhpWorkshop\ExerciseRunner\Factory\ExerciseRunnerFactoryInterface;
use PhpSchool\PhpWorkshop\ExerciseRunner\RunnerManager;
use PhpSchool\PhpWorkshopTest\Asset\CliExerciseImpl;
use PHPUnit\Framework\TestCase;
class RunnerManagerTest extends TestCase
{
public function testConfigureInputCallsCorrectFactory(): void
{
$exercise = new CliExerciseImpl();
$manager = new RunnerManager();
$command = new CommandDefinition('my-command', [], 'var_dump');
$factory1 = $this->createMock(ExerciseRunnerFactoryInterface::class);
$factory1->method('supports')->with($exercise)->willReturn(false);
$factory1->expects($this->never())->method('configureInput')->with($command);
$factory2 = $this->createMock(ExerciseRunnerFactoryInterface::class);
$factory2->method('supports')->with($exercise)->willReturn(true);
$factory2->expects($this->once())->method('configureInput')->with($command);
$manager->addFactory($factory1);
$manager->addFactory($factory2);
$manager->configureInput($exercise, $command);
}
public function testGetRunnerCallsCorrectFactory(): void
{
$exercise = new CliExerciseImpl();
$manager = new RunnerManager();
$factory1 = $this->createMock(ExerciseRunnerFactoryInterface::class);
$factory1->method('supports')->with($exercise)->willReturn(false);
$factory1->expects($this->never())->method('create')->with($exercise);
$factory2 = $this->createMock(ExerciseRunnerFactoryInterface::class);
$factory2->method('supports')->with($exercise)->willReturn(true);
$factory2->expects($this->once())->method('create')->with($exercise);
$manager->addFactory($factory1);
$manager->addFactory($factory2);
$manager->getRunner($exercise);
}
public function testExceptionIsThrownWhenConfiguringInputIfNoFactorySupportsExercise(): void
{
$exercise = new CliExerciseImpl();
$manager = new RunnerManager();
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Exercise Type: "CLI" not supported');
$manager->configureInput($exercise, new CommandDefinition('my-command', [], 'var_dump'));
}
public function testExceptionIsThrownWhenGettingRunnerIfNoFactorySupportsExercise(): void
{
$exercise = new CliExerciseImpl();
$manager = new RunnerManager();
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Exercise Type: "CLI" not supported');
$manager->getRunner($exercise);
}
}