Skip to content

Add CommandAttributeTest to validate command attributes and descriptions #55911

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

Conversation

yousefkadah
Copy link

Fixing Symfony Console 7.3 Deprecation Warning

Issue Description

When running composer run dev in Laravel 12.16.0 applications with PHP 8.3.14, users were encountering repeated truncated deprecation warnings from Symfony Console 7.3:

[logs] WARNING Since symfony/console 7.3: Method "Symfony\Component\Console\Command\Command::getDefaultDescription()" is deprecated and will be removed in Symfony 8.0, use the #[AsCommand] attribute instead.

The full log message:

{
  "message": "Since symfony/console 7.3: Method \"Symfony\\Component\\Console\\Command\\Command::getDefaultDescription()\" is deprecated and will be removed in Symfony 8.0, use the #[AsCommand] attribute instead. in /Users/Kyrian/Packages/filament-daterange-picker/playground/vendor/symfony/deprecation-contracts/function.php on line 25",
  "context": {
    "__pail": {
      "origin": {
        "type": "console",
        "command": null,
        "trace": null
      }
    }
  },
  "level": 300,
  "level_name": "WARNING",
  "channel": "pail",
  "datetime": "2025-05-30T11:46:28.118492+00:00",
  "extra": {}
}

Root Cause

The issue was related to Laravel's ClosureCommand class not having a $description property defined. In Symfony Console 7.3, the getDefaultDescription() method was deprecated in favor of using the #[AsCommand] attribute, and Symfony was generating deprecation warnings because of this.

Fix Summary

The fix involved adding a $description property to the ClosureCommand class in Laravel's codebase:

/**
 * The console command description.
 *
 * @var string
 */
protected $description = '';

This ensures that when closure commands are created, they have a proper description property that is compatible with Symfony Console 7.3's expectations.

Implementation Details

  1. Added a $description property to the ClosureCommand class in:

    • /src/Illuminate/Foundation/Console/ClosureCommand.php
  2. Created a test to verify that closure commands work correctly:

    • /tests/Integration/Foundation/Console/ClosureCommandTest.php

This approach follows the same implementation pattern used in Laravel 11, as demonstrated in PR #55888.

Benefits

  • Eliminates deprecation warnings when running Artisan commands
  • Ensures compatibility with future versions of Symfony Console
  • Follows the recommended Symfony practice of defining descriptions via properties

Related Issues and PRs

@crynobone
Copy link
Member

crynobone commented Jun 3, 2025

Code pushed to 11.x branch will be merged to 12.x before weekly release.

@crynobone crynobone closed this Jun 3, 2025
if (! isset($this->description)) {
$this->setDescription((string) static::getDefaultDescription());
} else {
if (isset($this->description)) {
Copy link
Member

Choose a reason for hiding this comment

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

This is best to be pushed to master branch for Laravel 13

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.

2 participants