From c18f45a04c4f05c159cb0f2f288eaf834041fcb9 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 17 Apr 2024 13:00:13 +0200 Subject: [PATCH] Update debug command to print the binary path when running in Phar --- RELEASE_NOTES.md | 1 + .../src/Console/Commands/DebugCommand.php | 6 ++++ .../Feature/Commands/DebugCommandTest.php | 33 +++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 3529f658206..e48fab3905a 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -19,6 +19,7 @@ This serves two purposes: ### Changed - The `features` array in the `config/hyde.php` configuration file is now an array of `Feature` enums in https://github.com/hydephp/develop/pull/1650 - Sitemap generation will now be skipped if a base URL is not set, as Google now will not index sitemaps without a base URL in https://github.com/hydephp/develop/pull/1660 +- Updated the debug command to print the binary path when running in a standalone Phar in https://github.com/hydephp/develop/pull/1667 ### Deprecated - Deprecated the static `Features` flag methods used in the configuration files in https://github.com/hydephp/develop/pull/1650 and will be removed in HydePHP v2.0 diff --git a/packages/framework/src/Console/Commands/DebugCommand.php b/packages/framework/src/Console/Commands/DebugCommand.php index b722fb70bcb..cd87f65c5d4 100644 --- a/packages/framework/src/Console/Commands/DebugCommand.php +++ b/packages/framework/src/Console/Commands/DebugCommand.php @@ -7,11 +7,13 @@ use Hyde\Hyde; use Hyde\Facades\Config; use Composer\InstalledVersions; +use Hyde\Foundation\PharSupport; use LaravelZero\Framework\Commands\Command; use function str_replace; use function realpath; use function app; +use function get_included_files; /** * Print debug information. @@ -50,6 +52,10 @@ public function handle(): int $this->printVerbosePathInformation(); } else { $this->comment('Project directory: '.Hyde::path()); + + if (PharSupport::running()) { + $this->comment('Application binary path: '.get_included_files()[0]); + } } $this->newLine(); diff --git a/packages/framework/tests/Feature/Commands/DebugCommandTest.php b/packages/framework/tests/Feature/Commands/DebugCommandTest.php index 5cd341b0dc7..9d0c72dce8d 100644 --- a/packages/framework/tests/Feature/Commands/DebugCommandTest.php +++ b/packages/framework/tests/Feature/Commands/DebugCommandTest.php @@ -4,7 +4,11 @@ namespace Hyde\Framework\Testing\Feature\Commands; +use Mockery; use Hyde\Testing\TestCase; +use Hyde\Foundation\PharSupport; +use Illuminate\Console\OutputStyle; +use Hyde\Console\Commands\DebugCommand; /** * @covers \Hyde\Console\Commands\DebugCommand @@ -46,4 +50,33 @@ public function testItPrintsVerboseDebugInformation() ->expectsOutputToContain('(real)') ->assertExitCode(0); } + + public function testItPrintsPharDebugInformation() + { + PharSupport::mock('running', true); + + $wasCalled = false; + + $output = Mockery::mock(OutputStyle::class, [ + 'writeln' => null, + 'newLine' => null, + 'isVerbose' => false, + ])->makePartial(); + + $output->shouldReceive('writeln')->withArgs(function ($message) use (&$wasCalled) { + if (str_contains($message, 'Application binary path:')) { + $wasCalled = true; + } + + return true; + }); + + $command = new DebugCommand(); + $command->setOutput($output); + $command->handle(); + + $this->assertTrue($wasCalled, 'Expected "Application binary path" to be called'); + + PharSupport::clearMocks(); + } }