From fb134b0380dbbb9b8af91873906483146a7ab730 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Fri, 24 Jan 2020 23:06:39 +0100 Subject: [PATCH] Catch MySQL connection error on unit tests Fixes: https://github.com/phpmyadmin/scripts/issues/22 Signed-off-by: William Desportes --- test/selenium/TestBase.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/test/selenium/TestBase.php b/test/selenium/TestBase.php index c33ef57d7b0a..3368198e3f2f 100644 --- a/test/selenium/TestBase.php +++ b/test/selenium/TestBase.php @@ -86,13 +86,18 @@ protected function setUp(): void return; } - $this->_mysqli = new mysqli( - $GLOBALS['TESTSUITE_SERVER'], - $GLOBALS['TESTSUITE_USER'], - $GLOBALS['TESTSUITE_PASSWORD'], - 'mysql', - (int) $GLOBALS['TESTSUITE_PORT'] - ); + try { + $this->_mysqli = new mysqli( + $GLOBALS['TESTSUITE_SERVER'], + $GLOBALS['TESTSUITE_USER'], + $GLOBALS['TESTSUITE_PASSWORD'], + 'mysql', + (int) $GLOBALS['TESTSUITE_PORT'] + ); + } catch (Exception $e) { + // when localhost is used, it tries to connect to a socket and throws and error + $this->markTestSkipped('Failed to connect to MySQL (' . $e->getMessage() . ')'); + } if ($this->_mysqli->connect_errno) { $this->markTestSkipped('Failed to connect to MySQL (' . $this->_mysqli->error . ')');