Giter Site home page Giter Site logo

wp-cli-tests's Introduction

wp-cli/wp-cli-tests

WP-CLI testing framework

Testing

Quick links: Using | Contributing | Support

Using

To make use of the WP-CLI testing framework, you need to complete the following steps from within the package you want to add them to:

  1. Add the testing framework as a development requirement:

    composer require --dev wp-cli/wp-cli-tests
  2. Add the required test scripts to the composer.json file:

    "scripts": {
        "behat": "run-behat-tests",
        "behat-rerun": "rerun-behat-tests",
        "lint": "run-linter-tests",
        "phpcs": "run-phpcs-tests",
        "phpcbf": "run-phpcbf-cleanup",
        "phpunit": "run-php-unit-tests",
        "prepare-tests": "install-package-tests",
        "test": [
            "@lint",
            "@phpcs",
            "@phpunit",
            "@behat"
        ]
    }

    You can of course remove the ones you don't need.

  3. Optionally add a modified process timeout to the composer.json file to make sure scripts can run until their work is completed:

    "config": {
        "process-timeout": 1800
    },

    The timeout is expressed in seconds.

  4. Optionally add a behat.yml file to the package root with the following content:

    default:
      suites:
        default:
          contexts:
            - WP_CLI\Tests\Context\FeatureContext
          paths:
            - features

    This will make sure that the automated Behat system works across all platforms. This is needed on Windows.

  5. Optionally add a phpcs.xml.dist file to the package root to enable code style and best practice checks using PHP_CodeSniffer.

    Example of a minimal custom ruleset based on the defaults set in the WP-CLI testing framework:

    <?xml version="1.0"?>
    <ruleset name="WP-CLI-PROJECT-NAME">
    <description>Custom ruleset for WP-CLI PROJECT NAME</description>
    
        <!-- What to scan. -->
        <file>.</file>
    
        <!-- Show progress. -->
        <arg value="p"/>
    
        <!-- Strip the filepaths down to the relevant bit. -->
        <arg name="basepath" value="./"/>
    
        <!-- Check up to 8 files simultaneously. -->
        <arg name="parallel" value="8"/>
    
        <!-- For help understanding the `testVersion` configuration setting:
             https://github.com/PHPCompatibility/PHPCompatibility#sniffing-your-code-for-compatibility-with-specific-php-versions -->
        <config name="testVersion" value="5.4-"/>
    
        <!-- Rules: Include the base ruleset for WP-CLI projects. -->
        <rule ref="WP_CLI_CS"/>
    
    </ruleset>

    All other PHPCS configuration options are, of course, available.

  6. Update your composer dependencies and regenerate your autoloader and binary folders:

    composer update

You are now ready to use the testing framework from within your package.

Launching the tests

You can use the following commands to control the tests:

  • composer prepare-tests - Set up the database that is needed for running the functional tests. This is only needed once.
  • composer test - Run all test suites.
  • composer lint - Run only the linting test suite.
  • composer phpcs - Run only the code sniffer test suite.
  • composer phpcbf - Run only the code sniffer cleanup.
  • composer phpunit - Run only the unit test suite.
  • composer behat - Run only the functional test suite.

Controlling what to test

To send one or more arguments to one of the test tools, prepend the argument(s) with a double dash. As an example, here's how to run the functional tests for a specific feature file only:

composer behat -- features/cli-info.feature

Prepending with the double dash is needed because the arguments would otherwise be sent to Composer itself, not the tool that Composer executes.

Controlling the test environment

WordPress Version

You can run the tests against a specific version of WordPress by setting the WP_VERSION environment variable.

This variable understands any numeric version, as well as the special terms latest and trunk.

Note: This only applies to the Behat functional tests. All other tests never load WordPress.

Here's how to run your tests against the latest trunk version of WordPress:

WP_VERSION=trunk composer behat

WP-CLI Binary

You can run the tests against a specific WP-CLI binary, instead of using the one that has been built in your project's vendor/bin folder.

This can be useful to run your tests against a specific Phar version of WP_CLI.

To do this, you can set the WP_CLI_BIN_DIR environment variable to point to a folder that contains an executable wp binary. Note: the binary has to be named wp to be properly recognized.

As an example, here's how to run your tests against a specific Phar version you've downloaded.

# Prepare the binary you've downloaded into the ~/wp-cli folder first.
mv ~/wp-cli/wp-cli-1.2.0.phar ~/wp-cli/wp
chmod +x ~/wp-cli/wp

WP_CLI_BIN_DIR=~/wp-cli composer behat

Setting up the tests in Travis CI

Basic rules for setting up the test framework with Travis CI:

  • composer prepare-tests needs to be called once per environment.
  • linting and sniffing is a static analysis, so it shouldn't depend on any specific environment. You should do this only once, as a separate stage, instead of per environment.
  • composer behat || composer behat-rerun causes the Behat tests to run in their entirety first, and in case their were failed scenarios, a second run is done with only the failed scenarios. This usually gets around intermittent issues like timeouts or similar.

Here's a basic setup of how you can configure Travis CI to work with the test framework (extract):

install:
  - composer install
  - composer prepare-tests

script:
  - composer phpunit
  - composer behat || composer behat-rerun

jobs:
  include:
    - stage: sniff
      script:
        - composer lint
        - composer phpcs
      env: BUILD=sniff
    - stage: test
      php: 7.2
      env: WP_VERSION=latest
    - stage: test
      php: 7.2
      env: WP_VERSION=3.7.11
    - stage: test
      php: 7.2
      env: WP_VERSION=trunk

WP-CLI version

You can point the tests to a specific version of WP-CLI through the WP_CLI_BIN_DIR constant:

WP_CLI_BIN_DIR=~/my-custom-wp-cli/bin composer behat

WordPress version

If you want to run the feature tests against a specific WordPress version, you can use the WP_VERSION constant:

WP_VERSION=4.2 composer behat

The WP_VERSION constant also understands the latest and trunk as valid version targets.

The database credentials

By default, the tests are run in a database named wp_cli_test with the user also named wp_cli_test with password password1. This should be set up via the composer prepare-tests command.

The following environment variables can be set to override the default database credentials.

  • WP_CLI_TEST_DBHOST is the host to use and can include a port, i.e "127.0.0.1:33060" (defaults to "localhost")
  • WP_CLI_TEST_DBROOTUSER is the user that has permission to administer databases and users (defaults to "root").
  • WP_CLI_TEST_DBROOTPASS is the password to use for the above user (defaults to an empty password).
  • WP_CLI_TEST_DBNAME is the database that the tests run under (defaults to "wp_cli_test").
  • WP_CLI_TEST_DBUSER is the user that the tests run under (defaults to "wp_cli_test").
  • WP_CLI_TEST_DBPASS is the password to use for the above user (defaults to "password1").
  • WP_CLI_TEST_DBTYPE is the database engine type to use, i.e. "sqlite" for running tests on SQLite instead of MySQL (defaults to "mysql").

Environment variables can be set for the whole session via the following syntax: export WP_CLI_TEST_DBNAME=custom_db.

They can also be set for a single execution by prepending them before the Behat command: WP_CLI_TEST_DBNAME=custom_db composer behat.

Contributing

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.

For a more thorough introduction, check out WP-CLI's guide to contributing. This package follows those policy and guidelines.

Reporting a bug

Think you’ve found a bug? We’d love for you to help us get it fixed.

Before you create a new issue, you should search existing issues to see if there’s an existing resolution to it, or if it’s already been fixed in a newer version.

Once you’ve done a bit of searching and discovered there isn’t an open or fixed issue for your bug, please create a new issue. Include as much detail as you can, and clear steps to reproduce if possible. For more guidance, review our bug report documentation.

Creating a pull request

Want to contribute a new feature? Please first open a new issue to discuss whether the feature is a good fit for the project.

Once you've decided to commit the time to seeing your pull request through, please follow our guidelines for creating a pull request to make sure it's a pleasant experience. See "Setting up" for details specific to working on this package locally.

Support

GitHub issues aren't for general support questions, but there are other venues you can try: https://wp-cli.org/#support

wp-cli-tests's People

Contributors

aaemnnosttv avatar clemens-tolboom avatar danielbachhuber avatar dependabot-preview[bot] avatar dependabot[bot] avatar francescolaffi avatar garyjones avatar gitlost avatar jacklowrie avatar janw-me avatar japh avatar jmslbam avatar johnbillion avatar jrfnl avatar lewiscowles1986 avatar lkwdwrd avatar miya0001 avatar mpeshev avatar mrsdizzie avatar mwilliamson avatar natewr avatar nyordanov avatar richdavis1 avatar schlessera avatar scribu avatar swissspidy avatar szepeviktor avatar thelovekesh avatar wesm87 avatar wojsmol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wp-cli-tests's Issues

Using TEST_DB where it should be TEST_USER

Howdy @schlessera!

As we talked yesterday, I'm submitting the bug we found during the #WCEU2022ContributorDay.

It's located in vendor/wp-cli/wp-cli-tests/bin/install-package-tests in Line #54.

mysql -e "CREATE USER IF NOT EXISTS \${TEST_DB}`@'%' IDENTIFIED WITH mysql_native_password BY '${TEST_PASSWORD}'" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"`

Should be:

mysql -e "CREATE USER IF NOT EXISTS \${TEST_USER}`@'%' IDENTIFIED WITH mysql_native_password BY '${TEST_PASSWORD}'" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"`

Will send a PR for this ASAP.

Update to WPCS 3.0.0

WPCS 3.0.0 was recently released. We should update WP-CLI to use it!

https://github.com/WordPress/WordPress-Coding-Standards/wiki/Upgrade-Guide-to-WordPressCS-3.0.0-for-Developers-of-external-standards

  • wp-cli/automated-tests
  • wp-cli/admin-command
  • wp-cli/cache-command
  • wp-cli/checksum-command
  • wp-cli/config-command
  • wp-cli/core-command
  • wp-cli/cron-command
  • wp-cli/db-command
  • wp-cli/dist-archive-command
  • wp-cli/doctor-command
  • wp-cli/embed-command
  • wp-cli/entity-command
  • wp-cli/eval-command
  • wp-cli/export-command
  • wp-cli/extension-command
  • wp-cli/find-command
  • wp-cli/i18n-command
  • wp-cli/import-command
  • wp-cli/language-command
  • wp-cli/maintenance-mode-command
  • wp-cli/media-command
  • wp-cli/package-command
  • wp-cli/php-cli-tools
  • wp-cli/profile-command
  • wp-cli/restful
  • wp-cli/rewrite-command
  • wp-cli/role-command
  • wp-cli/scaffold-command
  • wp-cli/scaffold-package-command
  • wp-cli/search-replace-command
  • wp-cli/server-command
  • wp-cli/shell-command
  • wp-cli/snapshot-command
  • wp-cli/super-admin-command
  • wp-cli/widget-command
  • wp-cli/wp-cli
  • wp-cli/wp-cli-bundle
  • wp-cli/wp-cli-dev
  • wp-cli/wp-cli-tests
  • wp-cli/wp-cli.github.com
  • wp-cli/wp-config-transformer
  • wp-cli/wp-super-cache-cli

Done is:

  • This repository is updated to WPCS 3.0.0.
  • All of our repositories are updated to the latest version of this test package and passing.

Update PHPUnit to Version 4

After installing the project requirements as part of WP-CLI Hack Day and running ./vendor/bin/phpunit, I was greeted by a PHP Fatal Error due to inconsistent function signature discrepancies in PHPUnit. The source of the problem appeared to be related to my relatively modern version of PHP (7.2.7), compared with the older version of PHPUnit that WP-CLI runs on (3.7.38).

As part of the v2 release of WP-CLI, we should consider updating PHPUnit to the latest 4.* release, which officially supports PHP 5.3, 5.4, and 5.5. I attempted to do this locally, and after running ./vendor/bin/phpunit again, I was greeted with but a few PHP deprecated function warnings, but all tests successfully ran.

Documentation for PHPUnit 4 can be found here.

Document Behat steps

Behat steps should be documented through docblocks. These can then be pulled into both the handbook as well as this repo's README.md file.

WordPress.PHP.DisallowShortTernary has been removed in upstream development WordPress-Coding-Standards

I had to update to PHP 8 and WordPress-Coding-Standards intentionally doesn't support PHP 8 on their main branch, but only the development branch:

WordPress/WordPress-Coding-Standards#2035 (comment)

Their development branch uses https://github.com/PHPCSStandards/PHPCSExtra as a new dependency

And they have removed WordPress.PHP.DisallowShortTernary in favor of Universal.Operators.DisallowShortTernary here:

WordPress/WordPress-Coding-Standards#1911

So now with this setup WP_CLI_CS returns ERROR: Referenced sniff "WordPress.PHP.DisallowShortTernary" does not exist

<exclude name="WordPress.PHP.DisallowShortTernary"/>

I don't know if there is a fix right now, because there isn't a separate development branch of this sniff that would track WordPress-Coding-Standards but I'll leave it here for the future.

Setup issue, native wp functions not found, inability to complete prepare-tests

After installing everything according to the docs, phpunit is still unable to find native wp functions such as 'get_user_meta'.

Am I missing a step? I have wp-cli/wp-cli-tests autoloaded & composer has been updated with autoload optimized.

Only step I believe that's missing is composer prepare-tests which logs the following error:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

When I add a password to the install-package-tests.sh file mysql -e 'CREATE DATABASE IF NOT EXISTS wp_cli_test;' -uroot -p[pw] the script hangs.

Any help would be greatly appreciated.

Make the PHPCS setup more reusable

Would you be interested in a PR which will make the PHPCS setup re-usable by other WP-CLI packages ? (including documentation on how to use)

Add automatic support for `behat --rerun`

The Behat tooling should provide automated support for the --rerun. This could work so that the --rerun flag is always appended with a filename in a temporary folder. If rerunning was not requested, then the file should be erased first, so that the test suite runs in its entirety.

Rerunning might work through something like composer behat-rerun or similar.

As a result, general usage would always run the entire test suite, but when you had failures, you can just type composer behat-rerun to only run the failed scenarios. You never need to remember to first record the run for the --rerun to be available.

Documented install command fails

The documented install command composer require --dev wp-cli/wp-cli-tests will fail if your project's composer.json does not use a minimum-stability: dev due to its dependency on roave/security-advisories:dev-master.

Instead, installing in this context produces an error like this:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - wp-cli/wp-cli-tests v2.0.9 requires roave/security-advisories dev-master -> satisfiable by roave/security-advisories[dev-master] but these conflict with your requirements or minimum-stability.
    - wp-cli/wp-cli-tests v2.0.8 requires roave/security-advisories dev-master -> satisfiable by roave/security-advisories[dev-master] but these conflict with your requirements or minimum-stability.
    - wp-cli/wp-cli-tests v2.0.7 requires roave/security-advisories dev-master -> satisfiable by roave/security-advisories[dev-master] but these conflict with your requirements or minimum-stability.
    - wp-cli/wp-cli-tests v2.0.6 requires roave/security-advisories dev-master -> satisfiable by roave/security-advisories[dev-master] but these conflict with your requirements or minimum-stability.
    - wp-cli/wp-cli-tests v2.0.5 requires roave/security-advisories dev-master -> satisfiable by roave/security-advisories[dev-master] but these conflict with your requirements or minimum-stability.
    - wp-cli/wp-cli-tests v2.0.4 requires roave/security-advisories dev-master -> satisfiable by roave/security-advisories[dev-master] but these conflict with your requirements or minimum-stability.
    - wp-cli/wp-cli-tests v2.0.3 requires roave/security-advisories dev-master -> satisfiable by roave/security-advisories[dev-master] but these conflict with your requirements or minimum-stability.
    - wp-cli/wp-cli-tests v2.0.2 requires roave/security-advisories dev-master -> satisfiable by roave/security-advisories[dev-master] but these conflict with your requirements or minimum-stability.
    - wp-cli/wp-cli-tests v2.0.13 requires roave/security-advisories dev-master -> satisfiable by roave/security-advisories[dev-master] but these conflict with your requirements or minimum-stability.
    - wp-cli/wp-cli-tests v2.0.12 requires roave/security-advisories dev-master -> satisfiable by roave/security-advisories[dev-master] but these conflict with your requirements or minimum-stability.
    - wp-cli/wp-cli-tests v2.0.11 requires roave/security-advisories dev-master -> satisfiable by roave/security-advisories[dev-master] but these conflict with your requirements or minimum-stability.
    - wp-cli/wp-cli-tests v2.0.10 requires roave/security-advisories dev-master -> satisfiable by roave/security-advisories[dev-master] but these conflict with your requirements or minimum-stability.
    - wp-cli/wp-cli-tests v2.0.1 requires roave/security-advisories dev-master -> satisfiable by roave/security-advisories[dev-master] but these conflict with your requirements or minimum-stability.
    - wp-cli/wp-cli-tests v2.0.0 requires roave/security-advisories dev-master -> satisfiable by roave/security-advisories[dev-master] but these conflict with your requirements or minimum-stability.
    - Installation request for wp-cli/wp-cli-tests ^2.0 -> satisfiable by wp-cli/wp-cli-tests[v2.0.0, v2.0.1, v2.0.10, v2.0.11, v2.0.12, v2.0.13, v2.0.2, v2.0.3, v2.0.4, v2.0.5, v2.0.6, v2.0.7, v2.0.8, v2.0.9].

A few solutions:

  • Remove this as a dependency since it only exists as a dev-master but add it to the package's suggest to request it to be installed at the package level
  • Document the dependency and add the package to the install command
    composer require --dev wp-cli/wp-cli-tests roave/security-advisories:dev-master
  • Document requiring your package's minimum-stability should be dev (with prefer-stable: true)

Thoughts?

Use alternative theme for testing as `P2` theme has been retired

Bug Report

Describe the current, buggy behavior

P2 theme has been removed from the directory. Ref: https://themes.trac.wordpress.org/ticket/30322

We need to find more reliable alternative theme for feature tests.

Reference of P2 theme in our tests: https://github.com/search?q=org%3Awp-cli%20%22wp%20theme%20install%20p2%22&type=code

Fix install-package-tests random build failures

Builds fail quite frequently with this error:

> install-package-tests
Warning: arning] Using a password on the command line interface can be insecure.
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:32768' (111)
/home/runner/work/extension-command/extension-command/vendor/wp-cli/wp-cli-tests/bin/install-package-tests: 81: [: Illegal number: 
Detected MySQL at version .
+ mysql -e CREATE DATABASE IF NOT EXISTS `wp_cli_test`; -h127.0.0.1 -P32768 --protocol=tcp -uroot -proot
Warning: arning] Using a password on the command line interface can be insecure.
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:32768' (111)
Script install-package-tests handling the prepare-tests event returned with error code 1
Error: Process completed with exit code 1.

image

Done is:

  • Builds no longer randomly fail with this error.

Properly support `@require-wp-latest`

Bug Report

Describe the current, buggy behavior

I spotted a few instances of @require-wp-latest in our code base, but I don't think it actually works. At least that wasn't the case when I tried it at wp-cli/doctor-command#165

run-behat-tests already grabs the latest version of WordPress, so when we do things like WP_VERSION=6.2 composer behat, it could pass this info on to behat-tags.php so that the script knows that 6.2 is lower than the current latest.

Describe what you would expect as the correct outcome

@require-wp-latest works as expected

Provide a possible solution

Provide additional context/Screenshots

`WP_VERSION` should default to latest patch if not provided

Right now, if you provide the version as WP_VERSION=5.1, it will pull in WP version 5.1, even if 5.1.1 is available. This causes issues in tests that rely on the latest WP version, like the checks in the wp-cli/doctor-command.

It would make more sense for the WP_VERSION to behave more closely like semantic versioning.

So, if 5.1.2 would be the latest available version:

  • WP_VERSION=5.1 => "use latest patch verison for the 5.1 minor version" => installs 5.1.2
  • WP_VERSION=5.1.1 => "use exact patch version 5.1.1" => installs 5.1.1
  • WP_VERSION=5.1.0 => "use exact patch version 5.1.0" => installs 5.1 (as that is the equivalent to 5.1.0.

This effectively means that all the WP_VERSION=x.x requests will always include all security patches and hotfixes.

Indicate specific PHPCS issues in CI job

When PHPCS fails in a CI job, the job output looks like this:

CleanShot 2023-08-27 at 10 08 24@2x

Unfortunately, this makes it difficult to figure out what the actual problem is. It would be much better to show which line the error occurred on.

Done is:

  • At a minimum, we indicate which line the error appears on. We may also want to share the entire PHPCS output.

Incorrect temp dir check on macOS

I'm running macOS High Sierra (10.13) and PHP 7.2.6 (installed via Homebrew).

I noticed in wp-cli/language-command#38 that on macOS the following check always fails:

if ( 0 !== strpos( $dir, sys_get_temp_dir() ) ) {
throw new RuntimeException( sprintf( "Attempted to delete directory '%s' that is not in the temp directory '%s'. " . __FILE__ . ':' . __LINE__, $dir, sys_get_temp_dir() ) );
}

In my case, sys_get_temp_dir() points to /private/var/some-path-to-wp-cli.../.

$dir on the other hand points to /var/some-path-to-wp-cli.../. That's why I get an exception every time.

However, on macOS, /var is a symlink to /private/var though, so these paths are actually equal.

To solve this, realpath() needs to be used to resolve the symlinks before comparing the paths.

PR imminent.

Move PHPUnit tests for `behat-tags.php` over

The unit tests for behat-tags.php cannot be run in the wp-cli/wp-cli framework repo anymore, they need to be run here, where that file actually exists.

PHPUnit also needs to be set up to run in this repository.

  • Create tests folder
  • Add tests/test-behat-tags.php file (source)
  • Create phpunit.xml.dist file

composer prepare-tests error

I am getting an error when trying to run the prepare-tests script where I get the output ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Detected MySQL at version .
/home/customer/www/my-test-site/public_html/vendor/bin/install-package-tests: line 75: [: : integer expression expected

  • mysql -e 'CREATE DATABASE IF NOT EXISTS wp_cli_test;' -uroot ''
    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)--------------^ Click "Preview" for a nicer view!

GitHub issues are meant for enhancement requests and specific, reproducible bugs, not for general support questions. For support options, please review http://wp-cli.org/#support.

The easiest way to get support is to join us in the #cli channel on the Make WordPress Slack Team.

Add spellchecking

There should be a spellchecking test that verifies that documentation and docblocks don't contain any typos.

Language should be configurable per set of files/folders to allow for the translated pages in the https://github.com/wp-cli/wp-cli.github.com repository to be checked in the correct language.

Exceptions/custom dictionaries should be configurable both centrally in wp-cli/wp-cli-tests as well as on the target repository.

Error on MySQL 8

We will have an error on behat with MySQL client 8.x like following.

$ ./vendor/bin/behat features/post.feature 

OS:	Darwin 17.7.0 Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xnu-4570.71.2~1/RELEASE_X86_64 x86_64
Shell:	
PHP binary:	/usr/local/bin/php
PHP version:	7.2.8
php.ini used:	/usr/local/etc/php/7.2/php.ini
WP-CLI root dir:	/Users/miya/wp-cli/entity-command/vendor/wp-cli/wp-cli
WP-CLI vendor dir:	/Users/miya/wp-cli/entity-command/vendor
WP_CLI phar path:	
WP-CLI packages dir:	
WP-CLI global config:	/var/folders/js/nwh8hv756_v0qqlmmgdc531h0000gn/T/wp-cli-package-test/config.yml
WP-CLI project config:	/Users/miya/wp-cli/entity-command/wp-cli.yml
WP-CLI version:	1.5.1

WordPress 4.9.7

Feature: Manage WordPress posts

  Background:          # features/post.feature:3
mysqldump: Couldn't execute 'SELECT COLUMN_NAME,                       JSON_EXTRACT(HISTOGRAM, '$."number-of-buckets-specified"')                FROM information_schema.COLUMN_STATISTICS                WHERE SCHEMA_NAME = 'wp_cli_test' AND TABLE_NAME = 'wp_commentmeta';': Unknown table 'column_statistics' in information_schema (1109)

Related: wp-cli/db-command#105

Abandoned dependencies

After installing, Composer warns about these abandoned dependencies:

Package ramsey/array_column is abandoned, you should avoid using it. No replacement was suggested.
Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.

Improve Behat output to include diffs on failed comparisons

When Behat compares two elements and finds them to not match, it would be helpful for debugging purposes to have a diff available that shows the exact difference between the two elements, like in this example output:

image 2018-08-16 at 9 21 38 am

The SebastianBergmann\Diff\Differ class is available and can be used for that.

Fix `realpath()` issue on non-existent paths

The fix in #7 to use realpath() breaks when using non-existent paths. Normally, this would just be a no-op in the following remove directory operation. With realpath(), however, the non-existent path is turned into a boolean false an interpreted as an empty string.

cp -r causes issues with symlinks on MacOS

This function is used in a lot of the tests:

public static function copy_dir( $src_dir, $dest_dir ) {
Process::create( Utils\esc_cmd( 'cp -r %s/* %s', $src_dir, $dest_dir ) )->run_check();
}

On MacOS I have tests that fail with errors like:

--- Failed steps:

001 Scenario: Composer stack with both WordPress and wp-cli as dependencies (command line) # features/bootstrap.feature:321
      And a dependency on current wp-cli                                                   # features/bootstrap.feature:323
        $ cp -r '/Users/isla/source/wp-cli-dev/wp-cli'/* '/var/folders/v6/gqkd9_rd74171hsndwtjrxww0000gn/T/wp-cli-composer-local-652be01cc7a8d9.06666196/'

        cp: vendor/rmccue: No such file or directory
        cp: vendor/wp-cli/wp-cli-tests/vendor/rmccue: No such file or directory
        cp: vendor/wp-cli/wp-cli-tests/vendor/wp-cli: directory causes a cycle
        cp: vendor/wp-cli/find-command/vendor/rmccue: No such file or directory
        cp: vendor/wp-cli/find-command/vendor/wp-cli: directory causes a cycle
        cp: vendor/wp-cli/media-command/vendor/rmccue: No such file or directory

etc...

I believe this is caused by trying to copy symlinks around, as discussed here: https://unix.stackexchange.com/questions/500379/cp-works-differently-on-a-mac

I thought I could get around this by installing GNU cp from homebrew, but it doesn't work because even though I have it in my PATH, I think wp-cli is setting an empty ENV here:

https://github.com/wp-cli/wp-cli/blob/main/php/WP_CLI/Process.php#L52-L60

I'm not exactly sure what the solution is, but just want to document it here. Options seem to be:

  • Passing ENV along in the Process::create call and having users install GNU cp
  • Use cp -a instead
  • Something else that doesn't invlove using lots of symlinks?

Using the bundled PHP web server step triggers `Use of undefined constant WP_CLI_ROOT` warning

Bug Report

This is probably not specific to the \WP_CLI\Tests\Context\FeatureContext::start_php_server method but this is where I encountered it.

As of WP-CLI 2.7, this method raises the following warning:

Warning: Use of undefined constant WP_CLI_ROOT - assumed 'WP_CLI_ROOT' (this will throw an Error in a future version of PHP) in vendor/wp-cli/wp-cli/php/utils.php line 44

See wp-cli/wp-cli@b179c7a (Utils\inside_phar() references the constant)

Is your bug report directly related to a specific command?

No

Are you unsure about what repository to post the bug report into?

I think so – I suppose it can be moved if needed 😄

Describe the current, buggy behavior

See above

Describe how other contributors can replicate this bug

  • Test a Behat scenario that uses a (Given|And) a PHP built-in web server step

Is this really not used? 🤔
https://github.com/search?q=org%3Awp-cli+%22a+PHP+built-in+web+server%22

Describe what you would expect as the correct outcome

This would work as before without raising a warning (wp-cli < 2.7)

Let us know what environment you are running this on

2022-10-27T15:43:59.6826507Z ┌─ @BeforeSuite # WP_CLI_Login\Tests\Context\FeatureContext::prepare()
2022-10-27T15:43:59.6827925Z │
2022-10-27T15:43:59.6829160Z │  OS:	Linux 5.15.0-1022-azure #27~20.04.1-Ubuntu SMP Mon Oct 17 02:03:50 UTC 2022 x86_64
2022-10-27T15:43:59.6830110Z │  Shell:	
2022-10-27T15:43:59.6830441Z │  PHP binary:	/usr/bin/php
2022-10-27T15:43:59.6830806Z │  PHP version:	7.4.32
2022-10-27T15:43:59.6831131Z │  php.ini used:	/etc/php/7.4/cli/php.ini
2022-10-27T15:43:59.6831434Z │  MySQL binary:	/usr/bin/mysql
2022-10-27T15:43:59.6831849Z │  MySQL version:	mysql  Ver 8.0.31-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))
2022-10-27T15:43:59.6832169Z │  SQL modes:	
2022-10-27T15:43:59.6832627Z │  WP-CLI root dir:	/home/runner/work/wp-cli-login-command/wp-cli-login-command/vendor/wp-cli/wp-cli
2022-10-27T15:43:59.6833207Z │  WP-CLI vendor dir:	/home/runner/work/wp-cli-login-command/wp-cli-login-command/vendor
2022-10-27T15:43:59.6833623Z │  WP_CLI phar path:	
2022-10-27T15:43:59.6833886Z │  WP-CLI packages dir:	
2022-10-27T15:43:59.6834233Z │  WP-CLI cache dir:	/tmp/wp-cli-home/.wp-cli/cache
2022-10-27T15:43:59.6834650Z │  WP-CLI global config:	/tmp/wp-cli-package-test/config.yml
2022-10-27T15:43:59.6835157Z │  WP-CLI project config:	/home/runner/work/wp-cli-login-command/wp-cli-login-command/wp-cli.yml
2022-10-27T15:43:59.6835555Z │  WP-CLI version:	2.7.1

Improve run-behat-tests for custom setups

Feature Request

Describe your use case and the problem you are facing

This package recommends using run-behat-tests for running the Behat tests, which works fine for off-the-shelf WP-CLI command packages, but not for custom projects.

The script bails early if there's no features folder and it does not detect any custom behat.yml file in the project root.

That's why projects like the AMP plugin or Traduttore resort to using vendor/bin/behat directly:

https://github.com/ampproject/amp-wp/blob/d2d441cf6f1f4e9a7268a9c6e3360be309852a2c/.github/workflows/build-test-measure.yml#L703-L706
https://github.com/ampproject/amp-wp/blob/d2d441cf6f1f4e9a7268a9c6e3360be309852a2c/.github/workflows/build-test-measure.yml#L703-L706

Describe the solution you'd like

I think the run-behat-tests script (and potentially others, haven't checked) should first check for existence of behat.yml. If it exists, it should not bail early if there's no features folder and not set BEHAT_PARAMS and the like.

This are just some ideas off the top of my head, I haven't actually tried to implement it this way yet, so perhaps it doesn't even work. But I just wanted to write it down :-)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.