diff --git a/src/Template/Border.php b/src/Template/Border.php index 9e29f01..428eec8 100644 --- a/src/Template/Border.php +++ b/src/Template/Border.php @@ -199,7 +199,7 @@ public function getBuffer(int $width, int $height): Buffer // Bottom bar $this->drawHorizontal( $cornerWidth, - $height - count(explode(PHP_EOL, $this->horizontal)), + $height - substr_count($this->horizontal, PHP_EOL) - 1, $width - $cornerWidth * 2, $buffer, ); @@ -239,8 +239,12 @@ public function getBuffer(int $width, int $height): Buffer $buffer, ); } elseif ($connection->type === Connection::TYPE_VERTICAL) { - // TODO: implement vertical connections - die('Vertical Connections are not implemented yet.'); + $this->drawVertical( + $beginX, + $beginY + substr_count($beginConnection, PHP_EOL) + 1, + $endY - $beginY - substr_count($beginConnection, PHP_EOL) - 1, + $buffer, + ); } } diff --git a/tests/Template/BorderTest.php b/tests/Template/BorderTest.php index 2e916ce..19e1b21 100644 --- a/tests/Template/BorderTest.php +++ b/tests/Template/BorderTest.php @@ -8,6 +8,8 @@ use PHPUnit\Framework\TestCase; use RobertWesner\AWDY\Template\Border; use RobertWesner\AWDY\Template\Buffer; +use RobertWesner\AWDY\Template\Connection; +use RobertWesner\AWDY\Template\Facing; #[CoversClass(Border::class)] #[UsesClass(Buffer::class)] @@ -131,6 +133,118 @@ public static function dataProvider(): array ) // TODO: test connections ], + 'connections' => [ + <<horizontal(<<vertical(<<corners( + topLeft: <<connectFacing( + left: <<connections([ + Connection::horizontal() + ->begin(0, -8, Facing::RIGHT) + ->end(-5, -8, Facing::LEFT), + Connection::vertical() + ->begin(20, 0, Facing::BOTTOM) + ->end(20, -8, Facing::TOP), + ]) + ] ]; }