Skip to content

Commit

Permalink
Merge pull request #14 from misseur/fix/28659
Browse files Browse the repository at this point in the history
[FIX#28659] FixedTime en beforeSuite
  • Loading branch information
faouzic committed May 17, 2016
2 parents 04e9575 + 49f78c5 commit 221badf
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions src/FixedDateContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -37,9 +49,9 @@ public function setCustomDate()
}

/**
* @AfterScenario
* @AfterSuite
*/
public function resetToNormalDate()
public static function resetToNormalDate()
{
uopz_unset_return("strtotime");
uopz_unset_return("date");
Expand All @@ -51,20 +63,20 @@ 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();
}

/**
* @Given /^je rollback la date$/
*/
public function jeRollbackLaDate()
{
$this->_custom_date = $this->_date;
self::$_custom_date = self::$_date;

$this->resetToNormalDate();
$this->setCustomDate();
self::resetToNormalDate();
self::setCustomDate();
}
}

0 comments on commit 221badf

Please sign in to comment.