@@ -160,6 +160,62 @@ Feature: Create a wp-config file
160160 Error: Database connection error
161161 """
162162
163+ @require-mysql
164+ Scenario: Configure with database credentials using socket path
165+ Given an empty directory
166+ And WP files
167+ And a find-socket.php file:
168+ """
169+ <?php
170+ // The WP_CLI_TEST_DBSOCKET variable can be set in the environment to
171+ // override the default locations and will take precedence.
172+ if ( ! empty( getenv( 'WP_CLI_TEST_DBSOCKET' ) ) ) {
173+ echo getenv( 'WP_CLI_TEST_DBSOCKET' );
174+ exit(0);
175+ }
176+ // From within Behat, the WP_CLI_TEST_DBSOCKET will be mapped to the internal
177+ // DB_SOCKET variable, as Behat pushes a new environment context.
178+ $locations = [
179+ '{DB_SOCKET}',
180+ '/var/run/mysqld/mysqld.sock',
181+ '/tmp/mysql.sock',
182+ ];
183+ foreach ( $locations as $location ) {
184+ if ( ! empty( $location ) && file_exists( $location ) ) {
185+ echo $location;
186+ exit(0);
187+ }
188+ }
189+ echo 'No socket found';
190+ exit(1);
191+ """
192+
193+ When I run `php find-socket.php`
194+ Then save STDOUT as {SOCKET}
195+ And STDOUT should not be empty
196+
197+ When I try `wget -O {RUN_DIR}/install-package-tests https://raw.githubusercontent.com/wp-cli/wp-cli-tests/main/bin/install-package-tests`
198+ Then STDERR should contain:
199+ """
200+ install-package-tests' saved
201+ """
202+
203+ When I run `chmod +x {RUN_DIR}/install-package-tests`
204+ Then STDERR should be empty
205+
206+ # We try to account for the warnings we get for passing the password on the command line.
207+ When I try `MYSQL_HOST=localhost WP_CLI_TEST_DBHOST='localhost:{SOCKET}' WP_CLI_TEST_DBROOTPASS='root' {RUN_DIR}/install-package-tests`
208+ Then STDOUT should contain:
209+ """
210+ Detected MySQL
211+ """
212+
213+ When I run `wp config create --dbname='{DB_NAME}' --dbuser='{DB_USER}' --dbpass='{DB_PASSWORD}' --dbhost='localhost:{SOCKET}'`
214+ Then the wp-config.php file should contain:
215+ """
216+ define( 'DB_HOST', 'localhost:{SOCKET}' );
217+ """
218+
163219 @require-php-7.0
164220 Scenario: Configure with salts generated
165221 Given an empty directory
0 commit comments