Skip to content

Commit cb0a456

Browse files
committed
Fix + add test
1 parent 5c7ab03 commit cb0a456

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

test/Command/RunCommandTest.php

+28-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace PhpSchool\PhpWorkshopTest\Command;
44

55
use Colors\Color;
6+
use PhpSchool\PhpWorkshop\Exercise\TemporaryDirectoryTrait;
7+
use PhpSchool\PhpWorkshopTest\BaseTest;
68
use PhpSchool\Terminal\Terminal;
79
use PhpSchool\PhpWorkshop\Command\RunCommand;
810
use PhpSchool\PhpWorkshop\ExerciseDispatcher;
@@ -13,11 +15,11 @@
1315
use PhpSchool\PhpWorkshopTest\Asset\CliExerciseImpl;
1416
use PHPUnit\Framework\TestCase;
1517

16-
class RunCommandTest extends TestCase
18+
class RunCommandTest extends BaseTest
1719
{
1820
public function test(): void
1921
{
20-
$input = new Input('appName', ['program' => 'solution.php']);
22+
$input = new Input('appName', ['program' => $this->getTemporaryFile('solution.php')]);
2123

2224
$exercise = new CliExerciseImpl();
2325
$repo = new ExerciseRepository([$exercise]);
@@ -37,4 +39,28 @@ public function test(): void
3739
$command = new RunCommand($repo, $dispatcher, $state, $output);
3840
$command->__invoke($input);
3941
}
42+
43+
public function testWithNonExistingFile(): void
44+
{
45+
$input = new Input('appName', ['program' => 'solution.php']);
46+
47+
$exercise = new CliExerciseImpl();
48+
$repo = new ExerciseRepository([$exercise]);
49+
50+
$state = new UserState();
51+
$state->setCurrentExercise('my-exercise');
52+
$color = new Color();
53+
$color->setForceStyle(true);
54+
$output = new StdOutput($color, $this->createMock(Terminal::class));
55+
56+
$dispatcher = $this->createMock(ExerciseDispatcher::class);
57+
$dispatcher
58+
->expects($this->never())
59+
->method('run');
60+
61+
$this->expectOutputString(file_get_contents(__DIR__ . '/../res/app-run-missing-solution-expected.txt'));
62+
63+
$command = new RunCommand($repo, $dispatcher, $state, $output);
64+
$command->__invoke($input);
65+
}
4066
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
 
3+
 File: "solution.php" does not exist 
4+
 
5+

0 commit comments

Comments
 (0)