Skip to content

Commit fcbbeba

Browse files
committed
Introduce new event for exercise runners to ease dealing with input and exercise
1 parent a395588 commit fcbbeba

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

src/Event/ExerciseRunnerEvent.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace PhpSchool\PhpWorkshop\Event;
4+
5+
use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface;
6+
use PhpSchool\PhpWorkshop\Input\Input;
7+
8+
/**
9+
* @author Aydin Hassan <aydin@hotmail.co.uk>
10+
*/
11+
class ExerciseRunnerEvent extends Event
12+
{
13+
14+
/**
15+
* @var ExerciseInterface
16+
*/
17+
private $exercise;
18+
19+
/**
20+
* @var Input
21+
*/
22+
private $input;
23+
24+
/**
25+
* @param string $name
26+
* @param ExerciseInterface $exercise
27+
* @param Input $input
28+
* @param array $parameters
29+
*/
30+
public function __construct($name, ExerciseInterface $exercise, Input $input, array $parameters = [])
31+
{
32+
$parameters['input'] = $input;
33+
$parameters['exercise'] = $exercise;
34+
parent::__construct($name, $parameters);
35+
36+
$this->exercise = $exercise;
37+
$this->input = $input;
38+
}
39+
40+
/**
41+
* @return Input
42+
*/
43+
public function getInput()
44+
{
45+
return $this->input;
46+
}
47+
48+
/**
49+
* @return ExerciseInterface
50+
*/
51+
public function getExercise()
52+
{
53+
return $this->exercise;
54+
}
55+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace PhpSchool\PhpWorkshopTest\Event;
4+
5+
use PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent;
6+
use PhpSchool\PhpWorkshop\Input\Input;
7+
use PhpSchool\PhpWorkshopTest\Asset\CliExerciseImpl;
8+
use PHPUnit_Framework_TestCase;
9+
10+
/**
11+
* @author Aydin Hassan <aydin@hotmail.co.uk>
12+
*/
13+
class ExerciseRunnerEventTest extends PHPUnit_Framework_TestCase
14+
{
15+
public function testGetters()
16+
{
17+
$exercise = new CliExerciseImpl;
18+
$input = new Input('app');
19+
20+
$event = new ExerciseRunnerEvent('Some Event', $exercise, $input, ['number' => 1]);
21+
self::assertSame($exercise, $event->getExercise());
22+
self::assertSame($input, $event->getInput());
23+
self::assertEquals(
24+
[
25+
'exercise' => $exercise,
26+
'input' => $input,
27+
'number' => 1
28+
],
29+
$event->getParameters()
30+
);
31+
}
32+
}

0 commit comments

Comments
 (0)