-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoundTurtleScenario.php
More file actions
65 lines (56 loc) · 1.75 KB
/
BoundTurtleScenario.php
File metadata and controls
65 lines (56 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
declare(strict_types=1);
namespace Nassau\Turtle\BoundTurtle;
use Nassau\Turtle\BusinessTurtle;
use Nassau\Turtle\State\Point;
use Nassau\Turtle\State\TurtleState;
use PHPUnit\Framework\TestCase;
use Throwable;
final class BoundTurtleScenario
{
private Rectangle $boundingBox;
private Throwable|TurtleState $actual;
public static function of(TestCase $testCase): self
{
return new self($testCase);
}
private function __construct(private readonly TestCase $testCase)
{
$this->boundingBox = Rectangle::of(Point::of(1, 1), Point::of(0, 0));
}
public function givenBoundingBox(Rectangle $boundingBox): self
{
$this->boundingBox = $boundingBox;
return $this;
}
public function whenTurtleMoves(int $distance): self
{
$sut = new BoundTurtle($this->boundingBox, new BusinessTurtle());
try {
$this->actual = $sut->moveForward(TurtleState::initial(), $distance);
} catch (Throwable $e) {
$this->actual = $e;
}
return $this;
}
public function thenThePositionIs(Point $expected): self
{
$this->testCase::assertEquals(
TurtleState::class,
$this->actual::class,
'SUT did not return expected state',
);
$this->testCase::assertEquals($expected, $this->actual->position);
return $this;
}
public function thenOutOfBoundsExceptionIsExpected(string $message): self
{
$this->testCase::assertEquals(
OutOfBoundsException::class,
$this->actual::class,
'SUT did not throw the expected exception',
);
$this->testCase::assertEquals($message, $this->actual->getMessage());
return $this;
}
}