A screenshot of zeroing in on where to find the socket for the Local site.

WPCLI Focus Time – 2021-10-01

WordCamp US 2021 is happening, but in between sessions, I’ve been trying to get a better setup for doing development work on WPCLI.

Trying out the wp-cli-dev repo

As I found in my last Open-source block time, the commands I had installed locally were missing various subcommands that were installed within my shell of a Local site.

Thanks to a pointer by @schlessera in the WordPress #cli slack channel, there’s the wp-cli/wp-cli-dev package that attempts to make it easier to download and scaffold out a full wpcli dev environment.

It wasn’t a seamless path since it seems like Github was throttling me, or in some way rejecting my key. To solve it, I temporarily commented out a call to refresh the various repos right after cloning them. This allowed the composer install command to finish cleanly and put all the various repos into place.

A screenshot showing the commented out line that allowed the composer install command to finish successfully.

I use Local. How do I run Behat?

Doing the above allowed me to run some of the initial things like PHP_Codesniffer, but when I ran Behat (and probably PHPUnit) I wasn’t able to connect to the DB.

A screenshot showing the MySQL error related to connecting to the MySQL socket.

Here’s that specific error:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

This basically means that MySQL is having issues connecting to the default socket. But since I use Local to quickly create environments instead of directly installing things like MySQL — what do I need to do?

The general flow was to:

  1. Find the configuration file for he running MySQL process.
  2. Search that config file for the socket.
  3. Export the WP_CLI_TEST_DBHOST environment variable.
  4. Run the tests!

For me, under a Local site’s environment, that process looks something like this:

ps aux | grep mysql
grep 'socket' ~/Library/Application\ Support/Local/run/o5ykeOZFY/conf/mysql/my.cnf                             
export WP_CLI_TEST_DBHOST='localhost:/Users/ben.turner/Library/Application Support/Local/run/o5ykeOZFY/mysql/mysqld.sock'
composer run behat
A screenshot of zeroing in on where to find the socket for the Local site.