-
Notifications
You must be signed in to change notification settings - Fork 4
Custom runner #141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Custom runner #141
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9b72245
Custom Runner
AydinHassan 2b789d8
cs
AydinHassan 20c8183
Rename custom runner
AydinHassan 2746dd3
Fix config
AydinHassan 2efb7d6
Fix patch revert listener
AydinHassan 4a83de4
Test getRequiredChecks
AydinHassan f8b96bf
Update doc blocks
AydinHassan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace PhpSchool\PhpWorkshop\Exercise; | ||
|
||
use PhpSchool\PhpWorkshop\Result\ResultInterface; | ||
|
||
/** | ||
* @author Aydin Hassan <[email protected]> | ||
*/ | ||
interface CustomVerifyingExercise | ||
{ | ||
/** | ||
* @return ResultInterface | ||
*/ | ||
public function verify(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
namespace PhpSchool\PhpWorkshop\ExerciseRunner; | ||
|
||
use PhpSchool\PhpWorkshop\Exercise\CustomVerifyingExercise; | ||
use PhpSchool\PhpWorkshop\Input\Input; | ||
use PhpSchool\PhpWorkshop\Output\OutputInterface; | ||
use PhpSchool\PhpWorkshop\Result\ResultInterface; | ||
|
||
/** | ||
* @author Aydin Hassan <[email protected]> | ||
*/ | ||
class CustomVerifyingRunner implements ExerciseRunnerInterface | ||
{ | ||
/** | ||
* @var CustomVerifyingExercise | ||
*/ | ||
private $exercise; | ||
|
||
/** | ||
* @param CustomVerifyingExercise $exercise | ||
*/ | ||
public function __construct(CustomVerifyingExercise $exercise) | ||
{ | ||
$this->exercise = $exercise; | ||
} | ||
|
||
/** | ||
* Get the name of the exercise runner. | ||
* | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
return 'Custom Verifying Runner'; | ||
} | ||
|
||
/** | ||
* Get an array of the class names of the required checks this runner needs. | ||
* | ||
* @return array | ||
*/ | ||
public function getRequiredChecks() | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* Verify a solution to an exercise. Verification involves executing the reference solution | ||
* and the student's solution and comparing their output. If the output is the same | ||
* an instance of `PhpSchool\PhpWorkshop\Result\SuccessInterface` should be returned, if the output | ||
* is not the same, or something else went wrong then an instance of | ||
* `\PhpSchool\PhpWorkshop\Result\FailureInterface` should be returned. | ||
* | ||
* Other things that could go wrong include the student's solution returning a non-zero | ||
* exit code, or a notice/warning being exhibited. | ||
* | ||
* @param Input $input The command line arguments passed to the command. | ||
* @return ResultInterface The result of the check. | ||
*/ | ||
public function verify(Input $input) | ||
{ | ||
return $this->exercise->verify(); | ||
} | ||
|
||
/** | ||
* Run a solution to an exercise. This simply run's the student's solution with the correct input from the exercise | ||
* (such as the CLI arguments) and prints the output directly. This allows the student to have the environment | ||
* setup for them including getting a different set of arguments each time (if the exercise supports that). | ||
* | ||
* @param Input $input The command line arguments passed to the command. | ||
* @param OutputInterface $output A wrapper around STDOUT. | ||
* @return bool If the solution was successfully executed, eg. exit code was 0. | ||
*/ | ||
public function run(Input $input, OutputInterface $output) | ||
{ | ||
$message = 'Nothing to run here. This exercise does not require a code solution, '; | ||
$message .= 'so there is nothing to execute.'; | ||
$output->writeLine($message); | ||
return true; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/ExerciseRunner/Factory/CustomVerifyingRunnerFactory.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace PhpSchool\PhpWorkshop\ExerciseRunner\Factory; | ||
|
||
use PhpSchool\PhpWorkshop\CommandDefinition; | ||
use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface; | ||
use PhpSchool\PhpWorkshop\Exercise\ExerciseType; | ||
use PhpSchool\PhpWorkshop\ExerciseRunner\CustomVerifyingRunner; | ||
use PhpSchool\PhpWorkshop\ExerciseRunner\ExerciseRunnerInterface; | ||
|
||
/** | ||
* @author Aydin Hassan <[email protected]> | ||
*/ | ||
class CustomVerifyingRunnerFactory implements ExerciseRunnerFactoryInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private static $type = ExerciseType::CUSTOM; | ||
|
||
/** | ||
* Whether the factory supports this exercise type. | ||
* | ||
* @param ExerciseInterface $exercise | ||
* @return bool | ||
*/ | ||
public function supports(ExerciseInterface $exercise) | ||
{ | ||
return $exercise->getType()->getValue() === self::$type; | ||
} | ||
|
||
/** | ||
* Add any extra required arguments to the command. | ||
* | ||
* @param CommandDefinition $commandDefinition | ||
*/ | ||
public function configureInput(CommandDefinition $commandDefinition) | ||
{ | ||
} | ||
|
||
/** | ||
* Create and return an instance of the runner. | ||
* | ||
* @param ExerciseInterface $exercise | ||
* @return ExerciseRunnerInterface | ||
*/ | ||
public function create(ExerciseInterface $exercise) | ||
{ | ||
return new CustomVerifyingRunner($exercise); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace PhpSchool\PhpWorkshopTest\Asset; | ||
|
||
use PhpSchool\PhpWorkshop\Exercise\AbstractExercise; | ||
use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface; | ||
use PhpSchool\PhpWorkshop\Exercise\ExerciseType; | ||
use PhpSchool\PhpWorkshop\Exercise\CustomVerifyingExercise; | ||
use PhpSchool\PhpWorkshop\Result\ResultInterface; | ||
use PhpSchool\PhpWorkshop\Result\Success; | ||
|
||
/** | ||
* @author Aydin Hassan <[email protected]> | ||
*/ | ||
class CustomVerifyingExerciseImpl extends AbstractExercise implements ExerciseInterface, CustomVerifyingExercise | ||
{ | ||
|
||
/** | ||
* Get the name of the exercise, like `Hello World!`. | ||
* | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
return 'Custom Verifying exercise'; | ||
} | ||
|
||
/** | ||
* A short description of the exercise. | ||
* | ||
* @return string | ||
*/ | ||
public function getDescription() | ||
{ | ||
return 'Custom Verifying exercise'; | ||
} | ||
|
||
/** | ||
* Return the type of exercise. This is an ENUM. See `PhpSchool\PhpWorkshop\Exercise\ExerciseType`. | ||
* | ||
* @return ExerciseType | ||
*/ | ||
public function getType() | ||
{ | ||
return ExerciseType::CUSTOM(); | ||
} | ||
|
||
/** | ||
* @return ResultInterface | ||
*/ | ||
public function verify() | ||
{ | ||
return new Success('success'); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace PhpSchool\PhpWorkshop\ExerciseRunner; | ||
|
||
use Colors\Color; | ||
use PhpSchool\CliMenu\Terminal\TerminalInterface; | ||
use PhpSchool\PhpWorkshop\Input\Input; | ||
use PhpSchool\PhpWorkshop\Output\StdOutput; | ||
use PhpSchool\PhpWorkshopTest\Asset\CustomVerifyingExerciseImpl; | ||
use PHPUnit_Framework_TestCase; | ||
|
||
/** | ||
* @author Aydin Hassan <[email protected]> | ||
*/ | ||
class ExtRunnerTest extends PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var CustomVerifyingRunner | ||
*/ | ||
private $runner; | ||
|
||
/** | ||
* @var CustomVerifyingExerciseImpl | ||
*/ | ||
private $exercise; | ||
|
||
public function setUp() | ||
{ | ||
$this->exercise = new CustomVerifyingExerciseImpl; | ||
$this->runner = new CustomVerifyingRunner($this->exercise); | ||
|
||
$this->assertEquals('Custom Verifying Runner', $this->runner->getName()); | ||
} | ||
|
||
public function testRequiredChecks() | ||
{ | ||
$this->assertEquals([], $this->runner->getRequiredChecks()); | ||
} | ||
|
||
public function testRunOutputsErrorMessage() | ||
{ | ||
$color = new Color; | ||
$color->setForceStyle(true); | ||
$output = new StdOutput($color, $this->createMock(TerminalInterface::class)); | ||
|
||
$exp = 'Nothing to run here. This exercise does not require a code solution, '; | ||
$exp .= "so there is nothing to execute.\n"; | ||
|
||
$this->expectOutputString($exp); | ||
|
||
$this->runner->run(new Input('app'), $output); | ||
} | ||
|
||
public function testVerifyProxiesToExercise() | ||
{ | ||
self::assertEquals($this->exercise->verify(), $this->runner->verify(new Input('app'))); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update comments here