Skip to content

Commit 1d7935e

Browse files
committed
more php8 fixes
1 parent 50a1e3e commit 1d7935e

17 files changed

+348
-244
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/ExerciseRunner/CliRunnerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function testVerifyThrowsExceptionIfSolutionFailsExecution(): void
7575
->willReturn([[]]);
7676

7777
$regex = "/^PHP Code failed to execute\\. Error: \"PHP Parse error: syntax error, unexpected end of file";
78-
$regex .= ", expecting '[,;]' or '[;,]'/";
78+
$regex .= ", expecting ['\"][,;]['\"] or ['\"][;,]['\"]/";
7979
$this->expectException(SolutionExecutionException::class);
8080
$this->expectExceptionMessageMatches($regex);
8181
$this->runner->verify(new Input('app', ['program' => '']));
@@ -139,7 +139,7 @@ public function testVerifyReturnsFailureIfUserSolutionFailsToExecute(): void
139139
$failure = $this->runner->verify(new Input('app', ['program' => __DIR__ . '/../res/cli/user-error.php']));
140140

141141
$failureMsg = '/^PHP Code failed to execute. Error: "PHP Parse error: syntax error, ';
142-
$failureMsg .= "unexpected end of file, expecting '[,;]' or '[;,]'/";
142+
$failureMsg .= "unexpected end of file, expecting ['\"][,;]['\"] or ['\"][;,]['\"]/";
143143

144144
$this->assertInstanceOf(CliResult::class, $failure);
145145
$this->assertCount(1, $failure);
@@ -212,7 +212,7 @@ public function testRunPassesOutputAndReturnsFailureIfScriptFails(): void
212212
->willReturn([[1, 2, 3]]);
213213

214214
$this->expectOutputRegex(
215-
'/(PHP )?Parse error:\W+syntax error, unexpected end of file, expecting \'[,;]\' or \'[;,]\' /'
215+
"/(PHP )?Parse error:\W+syntax error, unexpected end of file, expecting ['\"][,;]['\"] or ['\"][;,]['\"] /"
216216
);
217217

218218
$success = $this->runner->run(new Input('app', ['program' => __DIR__ . '/../res/cli/user-error.php']), $output);

test/ExerciseRunner/Factory/CgiRunnerFactoryTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ public function setUp(): void
3232

3333
public function testSupports(): void
3434
{
35-
$exercise1 = $this->prophesize(ExerciseInterface::class);
36-
$exercise2 = $this->prophesize(ExerciseInterface::class);
35+
$exercise1 = $this->createMock(ExerciseInterface::class);
36+
$exercise2 = $this->createMock(ExerciseInterface::class);
3737

38-
$exercise1->getType()->willReturn(ExerciseType::CGI());
39-
$exercise2->getType()->willReturn(ExerciseType::CLI());
38+
$exercise1->method('getType')->willReturn(ExerciseType::CGI());
39+
$exercise2->method('getType')->willReturn(ExerciseType::CLI());
4040

41-
$this->assertTrue($this->factory->supports($exercise1->reveal()));
42-
$this->assertFalse($this->factory->supports($exercise2->reveal()));
41+
$this->assertTrue($this->factory->supports($exercise1));
42+
$this->assertFalse($this->factory->supports($exercise2));
4343
}
4444

4545
public function testConfigureInputAddsProgramArgument(): void

test/ExerciseRunner/Factory/CliRunnerFactoryTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ public function setUp(): void
3131

3232
public function testSupports(): void
3333
{
34-
$exercise1 = $this->prophesize(ExerciseInterface::class);
35-
$exercise2 = $this->prophesize(ExerciseInterface::class);
34+
$exercise1 = $this->createMock(ExerciseInterface::class);
35+
$exercise2 = $this->createMock(ExerciseInterface::class);
3636

37-
$exercise1->getType()->willReturn(ExerciseType::CLI());
38-
$exercise2->getType()->willReturn(ExerciseType::CGI());
37+
$exercise1->method('getType')->willReturn(ExerciseType::CLI());
38+
$exercise2->method('getType')->willReturn(ExerciseType::CGI());
3939

40-
$this->assertTrue($this->factory->supports($exercise1->reveal()));
41-
$this->assertFalse($this->factory->supports($exercise2->reveal()));
40+
$this->assertTrue($this->factory->supports($exercise1));
41+
$this->assertFalse($this->factory->supports($exercise2));
4242
}
4343

4444
public function testConfigureInputAddsProgramArgument(): void

test/ExerciseRunner/Factory/CustomVerifyingRunnerFactoryTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ public function setUp(): void
2424

2525
public function testSupports(): void
2626
{
27-
$exercise1 = $this->prophesize(ExerciseInterface::class);
28-
$exercise2 = $this->prophesize(ExerciseInterface::class);
29-
$exercise3 = $this->prophesize(ExerciseInterface::class);
27+
$exercise1 = $this->createMock(ExerciseInterface::class);
28+
$exercise2 = $this->createMock(ExerciseInterface::class);
29+
$exercise3 = $this->createMock(ExerciseInterface::class);
3030

31-
$exercise1->getType()->willReturn(ExerciseType::CLI());
32-
$exercise2->getType()->willReturn(ExerciseType::CGI());
33-
$exercise3->getType()->willReturn(ExerciseType::CUSTOM());
31+
$exercise1->method('getType')->willReturn(ExerciseType::CLI());
32+
$exercise2->method('getType')->willReturn(ExerciseType::CGI());
33+
$exercise3->method('getType')->willReturn(ExerciseType::CUSTOM());
3434

35-
$this->assertFalse($this->factory->supports($exercise1->reveal()));
36-
$this->assertFalse($this->factory->supports($exercise2->reveal()));
37-
$this->assertTrue($this->factory->supports($exercise3->reveal()));
35+
$this->assertFalse($this->factory->supports($exercise1));
36+
$this->assertFalse($this->factory->supports($exercise2));
37+
$this->assertTrue($this->factory->supports($exercise3));
3838
}
3939

4040
public function testConfigureInputAddsNoArgument(): void

test/ExerciseRunner/RunnerManagerTest.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ public function testConfigureInputCallsCorrectFactory(): void
1717
$manager = new RunnerManager();
1818
$command = new CommandDefinition('my-command', [], 'var_dump');
1919

20-
$factory1 = $this->prophesize(ExerciseRunnerFactoryInterface::class);
21-
$factory1->supports($exercise)->willReturn(false);
22-
$factory1->configureInput($command)->shouldNotBeCalled();
20+
$factory1 = $this->createMock(ExerciseRunnerFactoryInterface::class);
21+
$factory1->method('supports')->with($exercise)->willReturn(false);
22+
$factory1->expects($this->never())->method('configureInput')->with($command);
2323

24-
$factory2 = $this->prophesize(ExerciseRunnerFactoryInterface::class);
25-
$factory2->supports($exercise)->willReturn(true);
26-
$factory2->configureInput($command)->shouldBeCalled();
24+
$factory2 = $this->createMock(ExerciseRunnerFactoryInterface::class);
25+
$factory2->method('supports')->with($exercise)->willReturn(true);
26+
$factory2->expects($this->once())->method('configureInput')->with($command);
2727

28-
$manager->addFactory($factory1->reveal());
29-
$manager->addFactory($factory2->reveal());
28+
$manager->addFactory($factory1);
29+
$manager->addFactory($factory2);
3030
$manager->configureInput($exercise, $command);
3131
}
3232

@@ -35,16 +35,16 @@ public function testGetRunnerCallsCorrectFactory(): void
3535
$exercise = new CliExerciseImpl();
3636
$manager = new RunnerManager();
3737

38-
$factory1 = $this->prophesize(ExerciseRunnerFactoryInterface::class);
39-
$factory1->supports($exercise)->willReturn(false);
40-
$factory1->create($exercise)->shouldNotBeCalled();
38+
$factory1 = $this->createMock(ExerciseRunnerFactoryInterface::class);
39+
$factory1->method('supports')->with($exercise)->willReturn(false);
40+
$factory1->expects($this->never())->method('create')->with($exercise);
4141

42-
$factory2 = $this->prophesize(ExerciseRunnerFactoryInterface::class);
43-
$factory2->supports($exercise)->willReturn(true);
44-
$factory2->create($exercise)->shouldBeCalled();
42+
$factory2 = $this->createMock(ExerciseRunnerFactoryInterface::class);
43+
$factory2->method('supports')->with($exercise)->willReturn(true);
44+
$factory2->expects($this->once())->method('create')->with($exercise);
4545

46-
$manager->addFactory($factory1->reveal());
47-
$manager->addFactory($factory2->reveal());
46+
$manager->addFactory($factory1);
47+
$manager->addFactory($factory2);
4848
$manager->getRunner($exercise);
4949
}
5050

0 commit comments

Comments
 (0)