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

Update debug command to print binary path when running in the Phar standalone #1667

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions packages/framework/src/Console/Commands/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();

Expand Down
33 changes: 33 additions & 0 deletions packages/framework/tests/Feature/Commands/DebugCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
}
Loading