Skip to content

Commit 80079cb

Browse files
committed
Merge pull request #81 from php-school/command-fixes
Command fixes
2 parents 9dd33ed + 3dcd464 commit 80079cb

File tree

5 files changed

+20
-9
lines changed

5 files changed

+20
-9
lines changed

app/config.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
use Symfony\Component\Filesystem\Filesystem;
6868

6969
return [
70-
'appName' => $_SERVER['argv'][0],
70+
'appName' => basename($_SERVER['argv'][0]),
7171
ExerciseDispatcher::class => factory(function (ContainerInterface $c) {
7272
$dispatcher = new ExerciseDispatcher(
7373
$c->get(RunnerFactory::class),
@@ -139,6 +139,7 @@
139139

140140
PrintCommand::class => factory(function (ContainerInterface $c) {
141141
return new PrintCommand(
142+
$c->get('appName'),
142143
$c->get(ExerciseRepository::class),
143144
$c->get(UserState::class),
144145
$c->get(MarkdownRenderer::class),

src/Command/PrintCommand.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
*/
1414
class PrintCommand
1515
{
16+
/**
17+
* @var string
18+
*/
19+
private $appName;
20+
1621
/**
1722
* @var MarkdownRenderer
1823
*/
@@ -34,17 +39,20 @@ class PrintCommand
3439
private $exerciseRepository;
3540

3641
/**
42+
* @param string $appName
3743
* @param ExerciseRepository $exerciseRepository
3844
* @param UserState $userState
3945
* @param MarkdownRenderer $markdownRenderer
4046
* @param OutputInterface $output
4147
*/
4248
public function __construct(
49+
$appName,
4350
ExerciseRepository $exerciseRepository,
4451
UserState $userState,
4552
MarkdownRenderer $markdownRenderer,
4653
OutputInterface $output
4754
) {
55+
$this->appName = $appName;
4856
$this->markdownRenderer = $markdownRenderer;
4957
$this->output = $output;
5058
$this->userState = $userState;
@@ -65,6 +73,8 @@ public function __invoke()
6573
$exercise = $this->exerciseRepository->findByName($currentExercise);
6674

6775
$markDown = file_get_contents($exercise->getProblem());
68-
$this->output->write($this->markdownRenderer->render($markDown));
76+
$doc = $this->markdownRenderer->render($markDown);
77+
$doc = str_replace('{appname}', $this->appName, $doc);
78+
$this->output->write($doc);
6979
}
7080
}

src/ExerciseRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function __invoke(CliMenu $menu)
120120
*/
121121
private function helpLine($text, $cmd)
122122
{
123-
$cmd = $this->color->__invoke(sprintf('php %s %s', $this->appName, $cmd))->yellow()->__toString();
123+
$cmd = $this->color->__invoke(sprintf('%s %s', $this->appName, $cmd))->yellow()->__toString();
124124
return sprintf(
125125
" %s %s: %s\n",
126126
$this->color->__invoke("»")->bold()->__toString(),

test/Command/PrintCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testErrorIsPrintedIfNoExerciseAssigned()
3333
->method('printError')
3434
->with('No active exercises. Select one from the menu');
3535

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

@@ -76,7 +76,7 @@ public function testExerciseIsPrintedIfAssigned()
7676
->method('write')
7777
->with('### Exercise 1');
7878

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

8282
unlink($file);

test/res/exercise-help-expected.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
### Exercise Content
99

1010

11-
» To print these instructions again, run: php phpschool print
12-
» To execute your program in a test environment, run: php phpschool run program.php
13-
» To verify your program, run: php phpschool verify program.php
14-
» For help run: php phpschool help
11+
» To print these instructions again, run: phpschool print
12+
» To execute your program in a test environment, run: phpschool run program.php
13+
» To verify your program, run: phpschool verify program.php
14+
» For help run: phpschool help
1515

1616

0 commit comments

Comments
 (0)