From 49f78c54f0611021f0151a5fe15571d00b884312 Mon Sep 17 00:00:00 2001 From: Maxime Lhomme Date: Thu, 12 May 2016 18:00:49 +0200 Subject: [PATCH] =?UTF-8?q?[FIX#28659]=20On=20passe=20setCustomDateParams?= =?UTF-8?q?=20en=20beforeSuite=20comme=20setCustomDate=20ce=20qui=20=C3=A0?= =?UTF-8?q?=20pour=20effet=20de=20passer=20les=20fonctions=20et=20variable?= =?UTF-8?q?s=20membres=20en=20static?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/FixedDateContext.php | 44 +++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/src/FixedDateContext.php b/src/FixedDateContext.php index dc638e0..711d86d 100644 --- a/src/FixedDateContext.php +++ b/src/FixedDateContext.php @@ -2,25 +2,37 @@ namespace ETNA\FeatureContext; -use Behat\Behat\Event\SuiteEvent; +use Behat\Testwork\Hook\Scope\BeforeSuiteScope; class FixedDateContext extends BaseContext { - private $_date; - private $_custom_date; + private static $_date; + private static $_custom_date; public function __construct($date) { - $this->_date = $date; - $this->_custom_date = $date; + // Constructeur pour avoir des paramètres, + // sauf qu'on récupère les paramètres en BeforeSuite + // donc on ne fait rien ici } /** - * @BeforeScenario + * @BeforeSuite */ - public function setCustomDate() + public static function setCustomDateParams(BeforeSuiteScope $scope) { - $_custom_date = $this->_custom_date; + $environment = $scope->getEnvironment(); + $contexts_params = $environment->getContextClassesWithArguments(); + self::$_date = $contexts_params['ETNA\FeatureContext\FixedDateContext']["date"]; + self::$_custom_date = self::$_date; + } + + /** + * @BeforeSuite + */ + public static function setCustomDate() + { + $_custom_date = self::$_custom_date; uopz_set_return("time", function () use ($_custom_date) { return strtotime($_custom_date); }, true); @@ -37,9 +49,9 @@ public function setCustomDate() } /** - * @AfterScenario + * @AfterSuite */ - public function resetToNormalDate() + public static function resetToNormalDate() { uopz_unset_return("strtotime"); uopz_unset_return("date"); @@ -51,10 +63,10 @@ public function resetToNormalDate() */ public function queLaDateEst($new_date) { - $this->_custom_date = $new_date; + self::$_custom_date = $new_date; - $this->resetToNormalDate(); - $this->setCustomDate(); + self::resetToNormalDate(); + self::setCustomDate(); } /** @@ -62,9 +74,9 @@ public function queLaDateEst($new_date) */ public function jeRollbackLaDate() { - $this->_custom_date = $this->_date; + self::$_custom_date = self::$_date; - $this->resetToNormalDate(); - $this->setCustomDate(); + self::resetToNormalDate(); + self::setCustomDate(); } }