Skip to content

Commit 1ed0b2b

Browse files
authored
Merge pull request #174 from php-school/prophecy-to-phpunit
Prophecy to phpunit
2 parents e4dcebd + 472911f commit 1ed0b2b

21 files changed

+510
-407
lines changed

phpunit.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,4 @@
1010
<directory suffix=".php">./src</directory>
1111
</whitelist>
1212
</filter>
13-
<php>
14-
<env name="SYMFONY_PHPUNIT_REMOVE" value="symfony/yaml"/>
15-
</php>
1613
</phpunit>

src/Exercise/ProvidesSolution.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ interface ProvidesSolution
1414
*
1515
* @return SolutionInterface
1616
*/
17-
public function getSolution();
17+
public function getSolution(): SolutionInterface;
1818
}

test/Asset/CgiExerciseImpl.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface;
77
use PhpSchool\PhpWorkshop\Exercise\ExerciseType;
88
use PhpSchool\PhpWorkshop\ExerciseDispatcher;
9+
use PhpSchool\PhpWorkshop\Solution\SolutionInterface;
910
use Psr\Http\Message\RequestInterface;
1011

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

34-
public function getSolution(): string
35+
public function getSolution(): SolutionInterface
3536
{
3637
// TODO: Implement getSolution() method.
3738
}

test/Asset/CliExerciseImpl.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
use PhpSchool\PhpWorkshop\Exercise\CliExercise;
66
use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface;
77
use PhpSchool\PhpWorkshop\Exercise\ExerciseType;
8+
use PhpSchool\PhpWorkshop\Exercise\ProvidesSolution;
89
use PhpSchool\PhpWorkshop\ExerciseDispatcher;
10+
use PhpSchool\PhpWorkshop\Solution\SolutionInterface;
911

1012
class CliExerciseImpl implements ExerciseInterface, CliExercise
1113
{
@@ -15,6 +17,11 @@ class CliExerciseImpl implements ExerciseInterface, CliExercise
1517
*/
1618
private $name;
1719

20+
/**
21+
* @var SolutionInterface
22+
*/
23+
private $solution;
24+
1825
public function __construct(string $name = 'my-exercise')
1926
{
2027
$this->name = $name;
@@ -30,9 +37,14 @@ public function getDescription(): string
3037
return $this->name;
3138
}
3239

33-
public function getSolution(): string
40+
public function setSolution(SolutionInterface $solution): void
41+
{
42+
$this->solution = $solution;
43+
}
44+
45+
public function getSolution(): SolutionInterface
3446
{
35-
// TODO: Implement getSolution() method.
47+
return $this->solution;
3648
}
3749

3850
public function getProblem(): string

test/Check/PhpLintCheckTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function testFailure(): void
5151
);
5252
$this->assertInstanceOf(Failure::class, $failure);
5353
$this->assertMatchesRegularExpression(
54-
"/(PHP )?Parse error:\W+syntax error, unexpected end of file, expecting '[,;]' or '[;,]'/",
54+
"/(PHP )?Parse error:\W+syntax error, unexpected end of file, expecting ['\"][,;]['\"] or ['\"][;,]['\"]/",
5555
$failure->getReason()
5656
);
5757
}

test/CodePatcherTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public function testDefaultPatchIsAppliedIfAvailable(): void
2929
$this->assertEquals($expected, $patcher->patch($exercise, '<?php $original = true;'));
3030
}
3131

32-
3332
public function testPatcherDoesNotApplyPatchIfNotPatchableExercise(): void
3433
{
3534
$patcher = new CodePatcher((new ParserFactory())->create(ParserFactory::PREFER_PHP7), new Standard());

test/Command/PrintCommandTest.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,20 @@ public function testExerciseIsPrintedIfAssigned(): void
1818
$file = tempnam(sys_get_temp_dir(), 'pws');
1919
file_put_contents($file, '### Exercise 1');
2020

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

26-
$repo = new ExerciseRepository([$exercise->reveal()]);
26+
$exercise
27+
->method('getType')
28+
->willReturn(ExerciseType::CLI());
29+
30+
$exercise
31+
->method('getName')
32+
->willReturn('some-exercise');
33+
34+
$repo = new ExerciseRepository([$exercise]);
2735

2836
$state = new UserState();
2937
$state->setCurrentExercise('some-exercise');

test/Command/RunCommandTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ public function test(): void
2828
$color->setForceStyle(true);
2929
$output = new StdOutput($color, $this->createMock(Terminal::class));
3030

31-
$dispatcher = $this->prophesize(ExerciseDispatcher::class);
32-
$dispatcher->run($exercise, $input, $output)->shouldBeCalled();
31+
$dispatcher = $this->createMock(ExerciseDispatcher::class);
32+
$dispatcher
33+
->expects($this->once())
34+
->method('run')
35+
->with($exercise, $input, $output);
3336

34-
$command = new RunCommand($repo, $dispatcher->reveal(), $state, $output);
37+
$command = new RunCommand($repo, $dispatcher, $state, $output);
3538
$command->__invoke($input);
3639
}
3740
}

0 commit comments

Comments
 (0)