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;