Skip to content

Fix wp ability list --format=ids output - #16

Open
softglazee wants to merge 1 commit into
wp-cli:mainfrom
softglazee:fix/list-ids-format
Open

softglazee wants to merge 1 commit into
wp-cli:mainfrom
softglazee:fix/list-ids-format

Conversation

@softglazee

Copy link
Copy Markdown

wp ability list documents ids as a format, but the ability rows were passed to the formatter as arrays. The output was Array Array ... with one "Array to string conversion" warning per ability.

This PR passes the ability names to the formatter when --format=ids is used, the same way wp cron event list passes the hook names, and adds a Behat step for it.

Fixes #15

Testing Instructions

Environment

  • OS: Linux (Docker container on WSL2, kernel 6.18.33.2)
  • Web Server: n/a (command line test)
  • PHP: 8.5.9
  • WordPress: 7.2-beta1-64691 (nightly)
  • Database: MariaDB 11.8.9
  • WP-CLI: wp-cli/wp-cli main (a1735b03), ability-command main (7a6437b) with this PR
  • Browser: n/a (command line test)
  • Theme: Ipsum 1.0 (default theme of the nightly)
  • Active Plugins:
    • WordPress Importer 0.9.7 (registers no abilities)

Steps to Reproduce

  1. wp ability list --format=ids
  2. 🐞 Bug occurs: STDOUT is Array Array Array Array Array Array and STDERR has six Warning: Array to string conversion in .../php/WP_CLI/Formatter.php on line 384 lines.

Expected Results

  • ✅ STDOUT is core/get-site-info core/get-user-info core/get-environment-info core/settings-get core/users-query core/content-query.
  • ✅ STDERR is empty and the exit code is 0.
  • ✅ The other formats and --field=name are unchanged.

With this PR on the same site (run from the ability-command checkout):

$ vendor/bin/wp --path=/tmp/lab ability list --format=ids
core/get-site-info core/get-user-info core/get-environment-info core/settings-get core/users-query core/content-query

STDERR was empty and the exit code was 0.

Test results

Behat ran with WP_VERSION=nightly, PHP 8.5.9 and MariaDB 11.8.9.

Before, on main:

$ vendor/bin/behat --format progress features/ability.feature:15
..............F-

--- Failed steps:

001 Scenario: Register and list abilities. # features/ability.feature:15
      Then STDOUT should be:               # features/ability.feature:99
        $ wp ability list --category=test-category --format=ids
        Array Array
        cwd: /tmp/wp-cli-test-run--6adc16195f1c90.37151094/
        run time: 1.3647840023041
        exit status: 0

        Output does not exactly match expected string:
        test-plugin/get-site-title test-plugin/echo-input

        --- Expected
        +++ Actual
        @@ @@
        -test-plugin/get-site-title test-plugin/echo-input
        +Array Array

1 scenario (1 failed)
16 steps (14 passed, 1 failed, 1 skipped)

After, with this PR:

$ vendor/bin/behat --format progress features/ability.feature:15
................

1 scenario (1 passed)
16 steps (16 passed)

Full suite with this PR (features/, without the two @less-than-wp-6.9 scenarios, which do not apply to the nightly): 16 scenarios (16 passed), 143 steps (143 passed).

composer phpcs -- src/Ability_Command.php and composer phpstan report no errors. The Gherkin linter (gherkin-lint-plus 1.0.2 with the wp-cli-tests config) passes on features/ability.feature.

AI assistance: Yes. I used an AI assistant to help investigate and draft this; I ran and checked every test and result myself.

The `ids` format of the formatter expects plain values, but the
ability rows were passed as arrays, which printed "Array" once per
ability and an "Array to string conversion" warning each.

Pass the ability names instead, the same way `wp cron event list`
passes the hook names.
@softglazee
softglazee requested a review from a team as a code owner October 24, 2026 08:14
@coderabbitai

coderabbitai Bot commented Oct 24, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 51975423-6a55-4bb2-9a20-e51dacda7f31
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Hello! 👋

Thanks for opening this pull request! Please check out our contributing guidelines. We appreciate you taking the initiative to contribute to this project.

Contributing isn't limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation.

Here are some useful Composer commands to get you started:

  • composer install: Install dependencies.
  • composer test: Run the full test suite.
  • composer phpcs: Check for code style violations.
  • composer phpcbf: Automatically fix code style violations.
  • composer phpunit: Run unit tests.
  • composer behat: Run behavior-driven tests.

To run a single Behat test, you can use the following command:

# Run all tests in a single file
composer behat features/some-feature.feature

# Run only a specific scenario (where 123 is the line number of the "Scenario:" title)
composer behat features/some-feature.feature:123

You can find a list of all available Behat steps in our handbook.

@github-actions github-actions Bot added bug Something isn't working command:ability Related to 'ability' command command:ability-list Related to 'ability list' command scope:testing Related to testing labels Oct 24, 2026
@codecov

codecov Bot commented Oct 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working command:ability Related to 'ability' command command:ability-list Related to 'ability list' command scope:testing Related to testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wp ability list --format=ids prints "Array" for each ability

1 participant