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

[11.x] Make tests pass on Herd #54171

Merged
merged 6 commits into from
Jan 13, 2025

Conversation

SanderMuller
Copy link
Contributor

Fix Test Compatibility with Herd by Standardizing Binary Handling

This PR fixes tests that use PHP_BINARY and therefore fail when running via Herd.

It standardizes the handling of PHP and Artisan binaries via the existing php_binary function (or Application::phpBinary() for console operations) and the newly added artisan_binary function.

Key Changes:

  • Ensured compatibility with Herd by centralizing binary handling.
  • Added the artisan_binary helper in Illuminate\Support\functions.php to standardize access to the Artisan binary path.
  • Refactored core framework files and test cases to use the artisan_binary helper, replacing inline checks like defined('ARTISAN_BINARY').

Benefits:

  • Tests now pass reliably under Herd.
  • Cleaner and more maintainable binary handling across the framework.
  • Backward-compatible refactor with no breaking changes.

Tests have been updated and verified to maintain existing behavior while ensuring compatibility with Herd. This change focuses on improving developer experience in environments using Herd.

@@ -95,7 +96,7 @@ public static function phpBinary()
*/
public static function artisanBinary()
{
return ProcessUtils::escapeArgument(defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan');
return ProcessUtils::escapeArgument(artisan_binary());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel like we need to introduce artisan_binary() helper since calling Illuminate\Console\Application::artisanBinary() would always yield the correct value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return ProcessUtils::escapeArgument(artisan_binary());
return ProcessUtils::escapeArgument(defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Illuminate\Console\Application::phpBinary() also uses the php_binary() helper, and this way defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan' is now only used inside that helper, nowhere else. I would be fine with accepting your commit suggestion (or you can push it yourself), but it feels like a step bakc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this method should return without quote in Laravel 12 and let method that needs it to explicit espace the argument.

Escaping argument is only needed when we providing string instead of array to Symfony Process.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

artisan_binary() also returns without quotes, the change on this line doesn't change the output from defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan'

I agree with you that there's further cleanup possible for v12

@@ -68,7 +69,7 @@ public function handle()
if ($this->option('passport')) {
Process::run(array_filter([
php_binary(),
defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan',
artisan_binary(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
artisan_binary(),
\Illuminate\Console\Application::artisanBinary(),

@@ -133,7 +134,7 @@ protected function installSanctum()
if (! $migrationPublished) {
Process::run([
php_binary(),
defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan',
artisan_binary(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
artisan_binary(),
\Illuminate\Console\Application::artisanBinary(),

@@ -156,7 +157,7 @@ protected function installReverb()

Process::run([
php_binary(),
defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan',
artisan_binary(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
artisan_binary(),
\Illuminate\Console\Application::artisanBinary(),

@@ -72,7 +73,7 @@ protected function phpBinary()
*/
protected function artisanBinary()
{
return defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan';
return artisan_binary();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return artisan_binary();
return \Illuminate\Console\Application::artisanBinary();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is functionally different since \Illuminate\Console\Application::artisanBinary() escapes it using ProcessUtils::escapeArgument()

@crynobone
Copy link
Member

Marking as draft since few tests on Windows are failing.

@crynobone crynobone marked this pull request as draft January 13, 2025 11:28
@crynobone crynobone marked this pull request as ready for review January 13, 2025 11:33
@SanderMuller
Copy link
Contributor Author

@crynobone thank you for reviewing, please let me know if you are looking for any additional changes at this point

@taylorotwell taylorotwell merged commit 9b5484f into laravel:11.x Jan 13, 2025
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants