From acd82fe94d2b61b8bb9ec7ef4981630653f49edf Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 27 Nov 2026 13:14:56 +0000 Subject: [PATCH] Only count a socket the scenarios can find as available @require-mysql-socket treated a socket path given as the suffix of WP_CLI_TEST_DBHOST as available. The scenarios carrying the tag look for the socket in WP_CLI_TEST_DBSOCKET and the two default locations only, so where the host was the only source, the tag let the scenario run and it still failed with "No socket found". The tag now looks in exactly the places those scenarios do. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01CE81GsxUY597AdaMP1NXzk --- tests/tests/TestBehatTags.php | 26 ++++++++++++++++++++++++++ utils/behat-tags.php | 11 ----------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/tests/tests/TestBehatTags.php b/tests/tests/TestBehatTags.php index 81ebd85f0..566fd5d33 100644 --- a/tests/tests/TestBehatTags.php +++ b/tests/tests/TestBehatTags.php @@ -584,6 +584,32 @@ public function test_require_mysql_socket_runs_with_a_socket(): void { $this->assertStringNotContainsString( '@require-mysql-socket', (string) $output ); } + /** + * A socket given only as part of WP_CLI_TEST_DBHOST is not one the scenarios using this tag + * can find, so it must not count as available. + */ + public function test_require_mysql_socket_ignores_a_socket_in_the_host(): void { + foreach ( array( '/var/run/mysqld/mysqld.sock', '/tmp/mysql.sock' ) as $location ) { + if ( file_exists( $location ) ) { + $this->markTestSkipped( "A socket exists at {$location}, which counts as available regardless of the host." ); + } + } + + $this->write_tagged_feature( '@require-mysql-socket' ); + + $socket = $this->temp_dir . DIRECTORY_SEPARATOR . 'mysql.sock'; + touch( $socket ); + + $output = $this->run_with_env( + array( + 'WP_CLI_TEST_DBSOCKET' => null, + 'WP_CLI_TEST_DBHOST' => 'localhost:' . $socket, + ) + ); + + $this->assertStringContainsString( '~@require-mysql-socket', (string) $output ); + } + /** * Tags no scenario carries do not need to be filtered out. */ diff --git a/utils/behat-tags.php b/utils/behat-tags.php index 6e8468f20..5ff1df282 100644 --- a/utils/behat-tags.php +++ b/utils/behat-tags.php @@ -182,17 +182,6 @@ function has_mysql_socket() { return file_exists( $socket ); } - // Anything but a port number after the colon in the host is a socket path. - $host = getenv( 'WP_CLI_TEST_DBHOST' ); - - if ( is_string( $host ) && false !== strpos( $host, ':' ) ) { - $after_colon = substr( $host, strrpos( $host, ':' ) + 1 ); - - if ( '' !== $after_colon && ! is_numeric( $after_colon ) ) { - return file_exists( $after_colon ); - } - } - foreach ( array( '/var/run/mysqld/mysqld.sock', '/tmp/mysql.sock' ) as $location ) { if ( file_exists( $location ) ) { return true;