Skip to content

Commit d2e06f3

Browse files
committed
Configure Command Listener tests
1 parent aeb103b commit d2e06f3

File tree

2 files changed

+98
-2
lines changed

2 files changed

+98
-2
lines changed

test/Asset/CliExerciseImpl.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,33 @@
1616
class CliExerciseImpl implements ExerciseInterface, CliExercise
1717
{
1818

19+
/**
20+
* @var string
21+
*/
22+
private $name;
23+
24+
/**
25+
* @param string $name
26+
*/
27+
public function __construct($name = 'my-exercise')
28+
{
29+
$this->name = $name;
30+
}
31+
1932
/**
2033
* @return string
2134
*/
2235
public function getName()
2336
{
24-
return 'my-exercise';
37+
return $this->name;
2538
}
2639

2740
/**
2841
* @return string
2942
*/
3043
public function getDescription()
3144
{
32-
return 'my-exercise';
45+
return $this->name;
3346
}
3447

3548
/**
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
namespace PhpSchool\PhpWorkshopTest\Listener;
4+
5+
use PhpSchool\PhpWorkshop\CommandDefinition;
6+
use PhpSchool\PhpWorkshop\Event\Event;
7+
use PhpSchool\PhpWorkshop\ExerciseRepository;
8+
use PhpSchool\PhpWorkshop\ExerciseRunner\RunnerManager;
9+
use PhpSchool\PhpWorkshop\Listener\ConfigureCommandListener;
10+
use PhpSchool\PhpWorkshop\UserState;
11+
use PhpSchool\PhpWorkshopTest\Asset\CliExerciseImpl;
12+
use PHPUnit_Framework_TestCase;
13+
14+
/**
15+
* @author Aydin Hassan <aydin@hotmail.co.uk>
16+
*/
17+
class ConfigureCommandListenerTest extends PHPUnit_Framework_TestCase
18+
{
19+
/**
20+
* @dataProvider configurableCommands
21+
* @param string $commandName
22+
*/
23+
public function testInputIsConfiguredForCorrectCommands($commandName)
24+
{
25+
$command = new CommandDefinition($commandName, [], function () {
26+
});
27+
28+
$state = new UserState([], 'Exercise 1');
29+
$exercise = new CliExerciseImpl('Exercise 1');
30+
$repo = new ExerciseRepository([$exercise]);
31+
32+
$runnerManager = $this->prophesize(RunnerManager::class);
33+
$runnerManager->configureInput($exercise, $command)->shouldBeCalled();
34+
35+
$event = new Event('some-event', ['command' => $command]);
36+
(new ConfigureCommandListener($state, $repo, $runnerManager->reveal()))->__invoke($event);
37+
}
38+
39+
/**
40+
* @return array
41+
*/
42+
public function configurableCommands()
43+
{
44+
return [
45+
['verify'],
46+
['run'],
47+
];
48+
}
49+
50+
/**
51+
* @dataProvider nonConfigurableCommands
52+
* @param string $commandName
53+
*/
54+
public function testInputIsNotConfiguredForCorrectCommands($commandName)
55+
{
56+
$command = new CommandDefinition($commandName, [], function () {
57+
});
58+
59+
$state = new UserState([], 'Exercise 1');
60+
$exercise = new CliExerciseImpl('Exercise 1');
61+
$repo = new ExerciseRepository([$exercise]);
62+
63+
$runnerManager = $this->prophesize(RunnerManager::class);
64+
65+
$event = new Event('some-event', ['command' => $command]);
66+
(new ConfigureCommandListener($state, $repo, $runnerManager->reveal()))->__invoke($event);
67+
68+
$runnerManager->configureInput($exercise, $command)->shouldNotHaveBeenCalled();
69+
}
70+
71+
/**
72+
* @return array
73+
*/
74+
public function nonConfigurableCommands()
75+
{
76+
return [
77+
['print'],
78+
['help'],
79+
['credits'],
80+
['menu'],
81+
];
82+
}
83+
}

0 commit comments

Comments
 (0)