Skip to content

Commit

Permalink
Update debug command to print the binary path when running in Phar
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Apr 17, 2024
1 parent e9a4cc2 commit c18f45a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
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();
}
}

0 comments on commit c18f45a

Please sign in to comment.