Skip to content
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: 0 additions & 3 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,4 @@
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<php>
<env name="SYMFONY_PHPUNIT_REMOVE" value="symfony/yaml"/>
</php>
</phpunit>
2 changes: 1 addition & 1 deletion src/Exercise/ProvidesSolution.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ interface ProvidesSolution
*
* @return SolutionInterface
*/
public function getSolution();
public function getSolution(): SolutionInterface;
}
3 changes: 2 additions & 1 deletion test/Asset/CgiExerciseImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface;
use PhpSchool\PhpWorkshop\Exercise\ExerciseType;
use PhpSchool\PhpWorkshop\ExerciseDispatcher;
use PhpSchool\PhpWorkshop\Solution\SolutionInterface;
use Psr\Http\Message\RequestInterface;

class CgiExerciseImpl implements ExerciseInterface, CgiExercise
Expand All @@ -31,7 +32,7 @@ public function getDescription(): string
return $this->name;
}

public function getSolution(): string
public function getSolution(): SolutionInterface
{
// TODO: Implement getSolution() method.
}
Expand Down
16 changes: 14 additions & 2 deletions test/Asset/CliExerciseImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
use PhpSchool\PhpWorkshop\Exercise\CliExercise;
use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface;
use PhpSchool\PhpWorkshop\Exercise\ExerciseType;
use PhpSchool\PhpWorkshop\Exercise\ProvidesSolution;
use PhpSchool\PhpWorkshop\ExerciseDispatcher;
use PhpSchool\PhpWorkshop\Solution\SolutionInterface;

class CliExerciseImpl implements ExerciseInterface, CliExercise
{
Expand All @@ -15,6 +17,11 @@ class CliExerciseImpl implements ExerciseInterface, CliExercise
*/
private $name;

/**
* @var SolutionInterface
*/
private $solution;

public function __construct(string $name = 'my-exercise')
{
$this->name = $name;
Expand All @@ -30,9 +37,14 @@ public function getDescription(): string
return $this->name;
}

public function getSolution(): string
public function setSolution(SolutionInterface $solution): void
{
$this->solution = $solution;
}

public function getSolution(): SolutionInterface
{
// TODO: Implement getSolution() method.
return $this->solution;
}

public function getProblem(): string
Expand Down
2 changes: 1 addition & 1 deletion test/Check/PhpLintCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function testFailure(): void
);
$this->assertInstanceOf(Failure::class, $failure);
$this->assertMatchesRegularExpression(
"/(PHP )?Parse error:\W+syntax error, unexpected end of file, expecting '[,;]' or '[;,]'/",
"/(PHP )?Parse error:\W+syntax error, unexpected end of file, expecting ['\"][,;]['\"] or ['\"][;,]['\"]/",
$failure->getReason()
);
}
Expand Down
1 change: 0 additions & 1 deletion test/CodePatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public function testDefaultPatchIsAppliedIfAvailable(): void
$this->assertEquals($expected, $patcher->patch($exercise, '<?php $original = true;'));
}


public function testPatcherDoesNotApplyPatchIfNotPatchableExercise(): void
{
$patcher = new CodePatcher((new ParserFactory())->create(ParserFactory::PREFER_PHP7), new Standard());
Expand Down
18 changes: 13 additions & 5 deletions test/Command/PrintCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,20 @@ public function testExerciseIsPrintedIfAssigned(): void
$file = tempnam(sys_get_temp_dir(), 'pws');
file_put_contents($file, '### Exercise 1');

$exercise = $this->prophesize(CliExerciseInterface::class);
$exercise->getProblem()->willReturn($file);
$exercise->getType()->willReturn(ExerciseType::CLI());
$exercise->getName()->willReturn('some-exercise');
$exercise = $this->createMock(CliExerciseInterface::class);
$exercise
->method('getProblem')
->willReturn($file);

$repo = new ExerciseRepository([$exercise->reveal()]);
$exercise
->method('getType')
->willReturn(ExerciseType::CLI());

$exercise
->method('getName')
->willReturn('some-exercise');

$repo = new ExerciseRepository([$exercise]);

$state = new UserState();
$state->setCurrentExercise('some-exercise');
Expand Down
9 changes: 6 additions & 3 deletions test/Command/RunCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ public function test(): void
$color->setForceStyle(true);
$output = new StdOutput($color, $this->createMock(Terminal::class));

$dispatcher = $this->prophesize(ExerciseDispatcher::class);
$dispatcher->run($exercise, $input, $output)->shouldBeCalled();
$dispatcher = $this->createMock(ExerciseDispatcher::class);
$dispatcher
->expects($this->once())
->method('run')
->with($exercise, $input, $output);

$command = new RunCommand($repo, $dispatcher->reveal(), $state, $output);
$command = new RunCommand($repo, $dispatcher, $state, $output);
$command->__invoke($input);
}
}
Loading