Skip to content

Command fixes #81

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 2 commits into from
Jan 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
use Symfony\Component\Filesystem\Filesystem;

return [
'appName' => $_SERVER['argv'][0],
'appName' => basename($_SERVER['argv'][0]),
ExerciseDispatcher::class => factory(function (ContainerInterface $c) {
$dispatcher = new ExerciseDispatcher(
$c->get(RunnerFactory::class),
Expand Down Expand Up @@ -139,6 +139,7 @@

PrintCommand::class => factory(function (ContainerInterface $c) {
return new PrintCommand(
$c->get('appName'),
$c->get(ExerciseRepository::class),
$c->get(UserState::class),
$c->get(MarkdownRenderer::class),
Expand Down
12 changes: 11 additions & 1 deletion src/Command/PrintCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
*/
class PrintCommand
{
/**
* @var string
*/
private $appName;

/**
* @var MarkdownRenderer
*/
Expand All @@ -34,17 +39,20 @@ class PrintCommand
private $exerciseRepository;

/**
* @param string $appName
* @param ExerciseRepository $exerciseRepository
* @param UserState $userState
* @param MarkdownRenderer $markdownRenderer
* @param OutputInterface $output
*/
public function __construct(
$appName,
ExerciseRepository $exerciseRepository,
UserState $userState,
MarkdownRenderer $markdownRenderer,
OutputInterface $output
) {
$this->appName = $appName;
$this->markdownRenderer = $markdownRenderer;
$this->output = $output;
$this->userState = $userState;
Expand All @@ -65,6 +73,8 @@ public function __invoke()
$exercise = $this->exerciseRepository->findByName($currentExercise);

$markDown = file_get_contents($exercise->getProblem());
$this->output->write($this->markdownRenderer->render($markDown));
$doc = $this->markdownRenderer->render($markDown);
$doc = str_replace('{appname}', $this->appName, $doc);
$this->output->write($doc);
}
}
2 changes: 1 addition & 1 deletion src/ExerciseRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function __invoke(CliMenu $menu)
*/
private function helpLine($text, $cmd)
{
$cmd = $this->color->__invoke(sprintf('php %s %s', $this->appName, $cmd))->yellow()->__toString();
$cmd = $this->color->__invoke(sprintf('%s %s', $this->appName, $cmd))->yellow()->__toString();
return sprintf(
" %s %s: %s\n",
$this->color->__invoke("»")->bold()->__toString(),
Expand Down
4 changes: 2 additions & 2 deletions test/Command/PrintCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testErrorIsPrintedIfNoExerciseAssigned()
->method('printError')
->with('No active exercises. Select one from the menu');

$command = new PrintCommand($repo, $state, $renderer, $output);
$command = new PrintCommand('phpschool', $repo, $state, $renderer, $output);
$this->assertSame(1, $command->__invoke());
}

Expand Down Expand Up @@ -76,7 +76,7 @@ public function testExerciseIsPrintedIfAssigned()
->method('write')
->with('### Exercise 1');

$command = new PrintCommand($repo, $state, $renderer, $output);
$command = new PrintCommand('phpschool', $repo, $state, $renderer, $output);
$command->__invoke();

unlink($file);
Expand Down
8 changes: 4 additions & 4 deletions test/res/exercise-help-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
### Exercise Content


» To print these instructions again, run: php phpschool print
» To execute your program in a test environment, run: php phpschool run program.php
» To verify your program, run: php phpschool verify program.php
» For help run: php phpschool help
» To print these instructions again, run: phpschool print
» To execute your program in a test environment, run: phpschool run program.php
» To verify your program, run: phpschool verify program.php
» For help run: phpschool help