Skip to content

Commit

Permalink
Get version from instance so it can be mocked
Browse files Browse the repository at this point in the history
Just saves on testing logic as we can fix the version
  • Loading branch information
caendesilva committed Nov 12, 2023
1 parent 9b43269 commit e666159
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/realtime-compiler/src/ConsoleOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function printStartMessage(string $host, int $port): void
$url = sprintf('%s://%s:%d', $port === 443 ? 'https' : 'http', $host, $port);

$lines = [
sprintf('<span class="text-blue-500">%s</span> <span class="text-gray">%s</span>', 'HydePHP Realtime Compiler', 'v'.Hyde::version()),
sprintf('<span class="text-blue-500">%s</span> <span class="text-gray">%s</span>', 'HydePHP Realtime Compiler', 'v'.Hyde::getInstance()->version()),
'',
sprintf('<span class="text-white">Listening on</span> <a href="%s" class="text-yellow-500">%s</a>', $url, $url),
];
Expand Down
13 changes: 11 additions & 2 deletions packages/realtime-compiler/tests/ConsoleOutputTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Hyde\Foundation\HydeKernel;
use Symfony\Component\Console\Output\BufferedOutput;
use Termwind\Repositories\Styles;

Expand All @@ -13,18 +14,26 @@
renderUsing(null);

Styles::flush();

HydeKernel::setInstance(new HydeKernel());
});

test('printStartMessage method', function () {
// Todo handle version dynamically
HydeKernel::setInstance(new class extends HydeKernel
{
public static function version(): string
{
return '1.2.3';
}
});

$output = new \Hyde\RealtimeCompiler\ConsoleOutput();
$output->printStartMessage('localhost', 8000);
$this->assertSame(<<<'TXT'
╭────────────────────────────────────╮
│ │
│ HydePHP Realtime Compiler v1.3.3 │
│ HydePHP Realtime Compiler v1.2.3 │
│ │
│ Listening on http://localhost:8000 │
│ │
Expand Down

0 comments on commit e666159

Please sign in to comment.