Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions tests/tests/TestBehatTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
11 changes: 0 additions & 11 deletions utils/behat-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading