Skip to content

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

Merged
taylorotwell merged 6 commits into
laravel:11.xfrom
SanderMuller:herd-binary-tests
Jan 13, 2025
Merged

[11.x] Make tests pass on Herd#54171
taylorotwell merged 6 commits into
laravel:11.xfrom
SanderMuller:herd-binary-tests

Conversation

@SanderMuller
Copy link
Copy Markdown
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.

public static function artisanBinary()
{
return ProcessUtils::escapeArgument(defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan');
return ProcessUtils::escapeArgument(artisan_binary());
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Process::run(array_filter([
php_binary(),
defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan',
artisan_binary(),
Copy link
Copy Markdown
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(),

Process::run([
php_binary(),
defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan',
artisan_binary(),
Copy link
Copy Markdown
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(),

Process::run([
php_binary(),
defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan',
artisan_binary(),
Copy link
Copy Markdown
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(),

protected function artisanBinary()
{
return defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan';
return artisan_binary();
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
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