Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HydePHP v1.4.0 - 2023-12-11 #585

Merged
merged 25 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d513376
Merge pull request #1431 from hydephp/navigation-discovery-improvements
invalid-email-address Nov 6, 2023
3692696
Merge pull request #1432 from hydephp/normalize-navigation-menu-confi…
invalid-email-address Nov 7, 2023
9d158d6
Merge branch 'master' into develop
caendesilva Nov 8, 2023
c1852df
Merge pull request #1435 from hydephp/update-internal-testing-scripts
invalid-email-address Nov 8, 2023
0a6c944
Merge pull request #1437 from hydephp/sync-downstream-repositories
invalid-email-address Nov 8, 2023
b177e63
Merge pull request #1438 from hydephp/dynamic-setup-php-action-versio…
invalid-email-address Nov 8, 2023
3d60d27
Merge pull request #1445 from hydephp/serve-command-tests
invalid-email-address Nov 9, 2023
c23d073
Merge pull request #1444 from hydephp/fancy-serve-command
invalid-email-address Nov 10, 2023
a29a52f
Skip test when dependent class does not exist https://github.com/hyde…
invalid-email-address Nov 10, 2023
0268b18
Merge pull request #1447 from hydephp/fancy-serve-command
invalid-email-address Nov 11, 2023
8dfa059
Merge pull request #1449 from hydephp/fancy-serve-command
invalid-email-address Nov 11, 2023
5d162ac
Merge pull request #1450 from hydephp/pass-through-settings-to-realti…
invalid-email-address Nov 12, 2023
72f51b1
Merge pull request #1453 from hydephp/pass-through-settings-to-realti…
invalid-email-address Nov 12, 2023
e288c53
Merge pull request #1458 from hydephp/realtime-compiler-live-edit
invalid-email-address Nov 14, 2023
f729bd7
Merge pull request #1472 from hydephp/add-documentation-index-page-to…
invalid-email-address Nov 26, 2023
eb44791
Merge branch 'master' into develop
caendesilva Nov 26, 2023
c03d972
Merge pull request #1477 from hydephp/documentation-sidebar-footer-co…
invalid-email-address Nov 26, 2023
66f03c8
Merge pull request #1478 from hydephp/fix-dot-notation-support-in-yam…
invalid-email-address Nov 27, 2023
e785f00
Use relative sitemap links when site URL is for localhost https://git…
invalid-email-address Nov 27, 2023
cdb2b01
Revert changes not ready for merge
invalid-email-address Nov 27, 2023
8943332
Merge pull request #1479 from hydephp/add-sitemap-fallback-for-missin…
invalid-email-address Nov 27, 2023
20276a1
Merge pull request #1481 from hydephp/customizable-automatic-sidebar-…
invalid-email-address Nov 27, 2023
5028631
Merge pull request #1485 from hydephp/refactor-internal-phar-support
invalid-email-address Dec 1, 2023
79f6317
Merge pull request #1483 from hydephp/add-open-flag-to-serve-command
invalid-email-address Dec 1, 2023
a22891a
Merge pull request #1490 from hydephp/release-v1.4.0
invalid-email-address Dec 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge pull request #1444 from hydephp/fancy-serve-command
Fancy serve command hydephp/develop@1fafeb5
  • Loading branch information
github-actions committed Nov 10, 2023
commit c23d073710a7771679418ddf79f1d70bf3e633c0
33 changes: 30 additions & 3 deletions src/Console/Commands/ServeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

namespace Hyde\Console\Commands;

use Closure;
use Hyde\Hyde;
use Hyde\Facades\Config;
use Hyde\RealtimeCompiler\ConsoleOutput;
use Illuminate\Support\Facades\Process;
use LaravelZero\Framework\Commands\Command;

use function sprintf;
use function class_exists;

/**
* Start the realtime compiler server.
Expand All @@ -26,7 +29,7 @@ class ServeCommand extends Command

public function handle(): int
{
$this->line('<info>Starting the HydeRC server...</info> Press Ctrl+C to stop');
$this->printStartMessage();

$this->runServerProcess(sprintf('php -S %s:%d %s',
$this->getHostSelection(),
Expand Down Expand Up @@ -54,8 +57,32 @@ protected function getExecutablePath(): string

protected function runServerProcess(string $command): void
{
Process::forever()->run($command, function (string $type, string $line): void {
Process::forever()->env($this->getEnvironmentVariables())->run($command, $this->getOutputHandler());
}

protected function getEnvironmentVariables(): array
{
return [
'HYDE_RC_REQUEST_OUTPUT' => ! $this->option('no-ansi'),
];
}

protected function printStartMessage(): void
{
$this->useBasicOutput()
? $this->line('<info>Starting the HydeRC server...</info> Press Ctrl+C to stop')
: ConsoleOutput::printStartMessage($this->getHostSelection(), $this->getPortSelection());
}

protected function getOutputHandler(): Closure
{
return $this->useBasicOutput() ? function (string $type, string $line): void {
$this->output->write($line);
});
} : ConsoleOutput::getFormatter($this->output->isVerbose());
}

protected function useBasicOutput(): bool
{
return $this->option('no-ansi') || ! class_exists(ConsoleOutput::class);
}
}
40 changes: 28 additions & 12 deletions tests/Feature/Commands/ServeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function setUp(): void

public function test_hyde_serve_command()
{
$this->artisan('serve')
$this->artisan('serve --no-ansi')
->expectsOutput('Starting the HydeRC server... Press Ctrl+C to stop')
->assertExitCode(0);

Expand All @@ -33,7 +33,7 @@ public function test_hyde_serve_command()

public function test_hyde_serve_command_with_port_option()
{
$this->artisan('serve --port=8081')
$this->artisan('serve --no-ansi --port=8081')
->expectsOutput('Starting the HydeRC server... Press Ctrl+C to stop')
->assertExitCode(0);

Expand All @@ -42,7 +42,7 @@ public function test_hyde_serve_command_with_port_option()

public function test_hyde_serve_command_with_host_option()
{
$this->artisan('serve --host=foo')
$this->artisan('serve --no-ansi --host=foo')
->expectsOutput('Starting the HydeRC server... Press Ctrl+C to stop')
->assertExitCode(0);

Expand All @@ -51,7 +51,7 @@ public function test_hyde_serve_command_with_host_option()

public function test_hyde_serve_command_with_port_and_host_option()
{
$this->artisan('serve --port=8081 --host=foo')
$this->artisan('serve --no-ansi --port=8081 --host=foo')
->expectsOutput('Starting the HydeRC server... Press Ctrl+C to stop')
->assertExitCode(0);

Expand All @@ -62,7 +62,7 @@ public function test_hyde_serve_command_with_port_defined_in_config()
{
config(['hyde.server.port' => 8081]);

$this->artisan('serve')
$this->artisan('serve --no-ansi')
->expectsOutput('Starting the HydeRC server... Press Ctrl+C to stop')
->assertExitCode(0);

Expand All @@ -73,7 +73,7 @@ public function test_hyde_serve_command_with_port_defined_in_config_and_port_opt
{
config(['hyde.server.port' => 8081]);

$this->artisan('serve --port=8082')
$this->artisan('serve --no-ansi --port=8082')
->expectsOutput('Starting the HydeRC server... Press Ctrl+C to stop')
->assertExitCode(0);

Expand All @@ -84,7 +84,7 @@ public function test_hyde_serve_command_with_port_missing_in_config_and_port_opt
{
config(['hyde.server.port' => null]);

$this->artisan('serve --port=8081')
$this->artisan('serve --no-ansi --port=8081')
->expectsOutput('Starting the HydeRC server... Press Ctrl+C to stop')
->assertExitCode(0);

Expand All @@ -95,7 +95,7 @@ public function test_hyde_serve_command_with_host_defined_in_config()
{
config(['hyde.server.host' => 'foo']);

$this->artisan('serve')
$this->artisan('serve --no-ansi')
->expectsOutput('Starting the HydeRC server... Press Ctrl+C to stop')
->assertExitCode(0);

Expand All @@ -106,7 +106,7 @@ public function test_hyde_serve_command_with_host_defined_in_config_and_host_opt
{
config(['hyde.server.host' => 'foo']);

$this->artisan('serve --host=bar')
$this->artisan('serve --no-ansi --host=bar')
->expectsOutput('Starting the HydeRC server... Press Ctrl+C to stop')
->assertExitCode(0);

Expand All @@ -117,7 +117,7 @@ public function test_hyde_serve_command_with_host_missing_in_config_and_host_opt
{
config(['hyde.server.host' => null]);

$this->artisan('serve --host=foo')
$this->artisan('serve --no-ansi --host=foo')
->expectsOutput('Starting the HydeRC server... Press Ctrl+C to stop')
->assertExitCode(0);

Expand All @@ -129,7 +129,7 @@ public function test_hyde_serve_command_with_invalid_config_value()
$this->expectException(TypeError::class);
config(['hyde.server.port' => 'foo']);

$this->artisan('serve')
$this->artisan('serve --no-ansi')
->expectsOutput('Starting the HydeRC server... Press Ctrl+C to stop')
->assertExitCode(0);
}
Expand All @@ -141,6 +141,11 @@ public function test_hyde_serve_command_passes_through_process_output()
->withNoArgs()
->andReturnSelf();

Process::shouldReceive('env')
->once()
->with(['HYDE_RC_REQUEST_OUTPUT' => false])
->andReturnSelf();

Process::shouldReceive('run')
->once()
->withArgs(function (string $command, Closure $handle) {
Expand All @@ -150,12 +155,23 @@ public function test_hyde_serve_command_passes_through_process_output()
})
->andReturnSelf();

$this->artisan('serve')
$this->artisan('serve --no-ansi')
->expectsOutput('Starting the HydeRC server... Press Ctrl+C to stop')
->expectsOutput('foo')
->assertExitCode(0);
}

public function testWithFancyOutput()
{
Process::fake(['php -S localhost:8080 {$this->binaryPath()}' => 'foo']);

$this->artisan('serve')
->expectsOutputToContain('HydePHP Realtime Compiler')
->assertExitCode(0);

Process::assertRan("php -S localhost:8080 {$this->binaryPath()}");
}

protected function binaryPath(): string
{
return Hyde::path('vendor/hyde/realtime-compiler/bin/server.php');
Expand Down