From af97c92ee1f64e9685a4b2ea61b1f704613aa74f Mon Sep 17 00:00:00 2001 From: Kellie Brownell Date: Tue, 28 Feb 2017 15:46:38 -0800 Subject: [PATCH 1/4] Initial draft of definition to check version --- includes/bootstrap/SWSFeatureContext.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/includes/bootstrap/SWSFeatureContext.php b/includes/bootstrap/SWSFeatureContext.php index 4b7a0ace..365c561f 100644 --- a/includes/bootstrap/SWSFeatureContext.php +++ b/includes/bootstrap/SWSFeatureContext.php @@ -9,7 +9,7 @@ Behat\Behat\Context\TranslatedContextInterface, Behat\Behat\Context\BehatContext, Behat\Behat\Context\TranslatableContext, - Behat\Behat\Exception\PendingException, + Behat\Behat\Tester\Exception\PendingException, Behat\Behat\Hook\Scope\BeforeScenarioScope; use Behat\Mink\Exception\ExpectationException, @@ -109,6 +109,25 @@ public function iWaitSeconds($seconds) { $mink->getSession()->wait(1000 * $seconds); } + /** + * @Given the :arg1 module version is between :arg2 and :arg3 + */ + public function theModuleVersionIsBetweenAnd($arg1, $arg2, $arg3) { + $pmi = $this->getDriver()->drush('pm-info ' . $arg1); + $found = preg_match("/$arg1/", $pmi); + if (!$found) { + throw new Exception($pmi); + } + preg_match('/Version\s{1,}\:\s{1,}7.x-(.*)/', $pmi, $matches); + $installed_version=floatval($matches[1]); + if (!$installed_version) { + throw new Exception($pmi); + } + if ($installed_version < floatval($arg2) || $installed_version > floatval($arg3)) { + throw new PendingException("Skipping Scenario, module version is: " . $installed_version . "."); + } + } + /** * Invoking a php code with drush. * From f7a9a5698caf21e261e80c967fc914734e0614c4 Mon Sep 17 00:00:00 2001 From: Kellie Brownell Date: Thu, 2 Mar 2017 17:03:32 -0800 Subject: [PATCH 2/4] Add greater and less than or equal to --- includes/bootstrap/SWSFeatureContext.php | 38 ++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/includes/bootstrap/SWSFeatureContext.php b/includes/bootstrap/SWSFeatureContext.php index 365c561f..ac4f4dc5 100644 --- a/includes/bootstrap/SWSFeatureContext.php +++ b/includes/bootstrap/SWSFeatureContext.php @@ -128,6 +128,44 @@ public function theModuleVersionIsBetweenAnd($arg1, $arg2, $arg3) { } } + /** + * @Given the :arg1 module version is greater than or equal to :arg2 + */ + public function theModuleVersionIsGreaterThanOrEqualTo($arg1, $arg2) { + $pmi = $this->getDriver()->drush('pm-info ' . $arg1); + $found = preg_match("/$arg1/", $pmi); + if (!$found) { + throw new Exception($pmi); + } + preg_match('/Version\s{1,}\:\s{1,}7.x-(.*)/', $pmi, $matches); + $installed_version=floatval($matches[1]); + if (!$installed_version) { + throw new Exception($pmi); + } + if ($installed_version <= floatval($arg2)) { + throw new PendingException("Skipping Scenario, module version is: " . $installed_version . "."); + } + } + + /** + * @Given the :arg1 module version is less than or equal to :arg2 + */ + public function theModuleVersionIsLessThanOrEqualTo($arg1, $arg2) { + $pmi = $this->getDriver()->drush('pm-info ' . $arg1); + $found = preg_match("/$arg1/", $pmi); + if (!$found) { + throw new Exception($pmi); + } + preg_match('/Version\s{1,}\:\s{1,}7.x-(.*)/', $pmi, $matches); + $installed_version=floatval($matches[1]); + if (!$installed_version) { + throw new Exception($pmi); + } + if ($installed_version >= floatval($arg2)) { + throw new PendingException("Skipping Scenario, module version is: " . $installed_version . "."); + } + } + /** * Invoking a php code with drush. * From 35fd9a81e4ae7b644fec8d357fa01b5fce3e239b Mon Sep 17 00:00:00 2001 From: Kellie Brownell Date: Thu, 2 Mar 2017 17:35:08 -0800 Subject: [PATCH 3/4] drush sql 1.02 sec faster than pmi --- includes/bootstrap/SWSFeatureContext.php | 30 +++++++----------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/includes/bootstrap/SWSFeatureContext.php b/includes/bootstrap/SWSFeatureContext.php index ac4f4dc5..191ca8f5 100644 --- a/includes/bootstrap/SWSFeatureContext.php +++ b/includes/bootstrap/SWSFeatureContext.php @@ -113,15 +113,11 @@ public function iWaitSeconds($seconds) { * @Given the :arg1 module version is between :arg2 and :arg3 */ public function theModuleVersionIsBetweenAnd($arg1, $arg2, $arg3) { - $pmi = $this->getDriver()->drush('pm-info ' . $arg1); - $found = preg_match("/$arg1/", $pmi); - if (!$found) { - throw new Exception($pmi); - } - preg_match('/Version\s{1,}\:\s{1,}7.x-(.*)/', $pmi, $matches); + $version_query = $this->getDriver()->drush('sql-query "SELECT info FROM system WHERE name like \'' . $arg1 . '\'"'); + preg_match('/"version";s:7:"7.x-([0-9]{1,2}.[0-9]{1,3})"/', $version_query, $matches); $installed_version=floatval($matches[1]); if (!$installed_version) { - throw new Exception($pmi); + throw new Exception($version_query); } if ($installed_version < floatval($arg2) || $installed_version > floatval($arg3)) { throw new PendingException("Skipping Scenario, module version is: " . $installed_version . "."); @@ -132,15 +128,11 @@ public function theModuleVersionIsBetweenAnd($arg1, $arg2, $arg3) { * @Given the :arg1 module version is greater than or equal to :arg2 */ public function theModuleVersionIsGreaterThanOrEqualTo($arg1, $arg2) { - $pmi = $this->getDriver()->drush('pm-info ' . $arg1); - $found = preg_match("/$arg1/", $pmi); - if (!$found) { - throw new Exception($pmi); - } - preg_match('/Version\s{1,}\:\s{1,}7.x-(.*)/', $pmi, $matches); + $version_query = $this->getDriver()->drush('sql-query "SELECT info FROM system WHERE name like \'' . $arg1 . '\'"'); + preg_match('/"version";s:7:"7.x-([0-9]{1,2}.[0-9]{1,3})"/', $version_query, $matches); $installed_version=floatval($matches[1]); if (!$installed_version) { - throw new Exception($pmi); + throw new Exception($version_query); } if ($installed_version <= floatval($arg2)) { throw new PendingException("Skipping Scenario, module version is: " . $installed_version . "."); @@ -151,15 +143,11 @@ public function theModuleVersionIsGreaterThanOrEqualTo($arg1, $arg2) { * @Given the :arg1 module version is less than or equal to :arg2 */ public function theModuleVersionIsLessThanOrEqualTo($arg1, $arg2) { - $pmi = $this->getDriver()->drush('pm-info ' . $arg1); - $found = preg_match("/$arg1/", $pmi); - if (!$found) { - throw new Exception($pmi); - } - preg_match('/Version\s{1,}\:\s{1,}7.x-(.*)/', $pmi, $matches); + $version_query = $this->getDriver()->drush('sql-query "SELECT info FROM system WHERE name like \'' . $arg1 . '\'"'); + preg_match('/"version";s:7:"7.x-([0-9]{1,2}.[0-9]{1,3})"/', $version_query, $matches); $installed_version=floatval($matches[1]); if (!$installed_version) { - throw new Exception($pmi); + throw new Exception($version_query); } if ($installed_version >= floatval($arg2)) { throw new PendingException("Skipping Scenario, module version is: " . $installed_version . "."); From 9bd2e28c48b59cb155c8c53f06523a4625a496b1 Mon Sep 17 00:00:00 2001 From: Kellie Brownell Date: Fri, 3 Mar 2017 11:34:14 -0800 Subject: [PATCH 4/4] Use unserialize to find module version --- includes/bootstrap/SWSFeatureContext.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/includes/bootstrap/SWSFeatureContext.php b/includes/bootstrap/SWSFeatureContext.php index 191ca8f5..64ea8485 100644 --- a/includes/bootstrap/SWSFeatureContext.php +++ b/includes/bootstrap/SWSFeatureContext.php @@ -114,7 +114,8 @@ public function iWaitSeconds($seconds) { */ public function theModuleVersionIsBetweenAnd($arg1, $arg2, $arg3) { $version_query = $this->getDriver()->drush('sql-query "SELECT info FROM system WHERE name like \'' . $arg1 . '\'"'); - preg_match('/"version";s:7:"7.x-([0-9]{1,2}.[0-9]{1,3})"/', $version_query, $matches); + $version_array=unserialize($version_query); + preg_match('/7.x-([0-9]{1,2}.[0-9]{1,3})/', $version_array["version"], $matches); $installed_version=floatval($matches[1]); if (!$installed_version) { throw new Exception($version_query); @@ -129,8 +130,8 @@ public function theModuleVersionIsBetweenAnd($arg1, $arg2, $arg3) { */ public function theModuleVersionIsGreaterThanOrEqualTo($arg1, $arg2) { $version_query = $this->getDriver()->drush('sql-query "SELECT info FROM system WHERE name like \'' . $arg1 . '\'"'); - preg_match('/"version";s:7:"7.x-([0-9]{1,2}.[0-9]{1,3})"/', $version_query, $matches); - $installed_version=floatval($matches[1]); + $version_array=unserialize($version_query); + preg_match('/7.x-([0-9]{1,2}.[0-9]{1,3})/', $version_array["version"], $matches); if (!$installed_version) { throw new Exception($version_query); } @@ -144,7 +145,8 @@ public function theModuleVersionIsGreaterThanOrEqualTo($arg1, $arg2) { */ public function theModuleVersionIsLessThanOrEqualTo($arg1, $arg2) { $version_query = $this->getDriver()->drush('sql-query "SELECT info FROM system WHERE name like \'' . $arg1 . '\'"'); - preg_match('/"version";s:7:"7.x-([0-9]{1,2}.[0-9]{1,3})"/', $version_query, $matches); + $version_array=unserialize($version_query); + preg_match('/7.x-([0-9]{1,2}.[0-9]{1,3})/', $version_array["version"], $matches); $installed_version=floatval($matches[1]); if (!$installed_version) { throw new Exception($version_query);