【问题标题】:Get current environment in Codeception 1.8在 Codeception 1.8 中获取当前环境
【发布时间】:2015-09-02 07:38:26
【问题描述】:

在 Codeception 2.1 中有一个新函数 current(),它有助于获取当前的测试环境:$scenario->current('env') 我用的是1.8版,没有这个功能。所以,我试图手动将方法 current() 添加到 Scenario 类,但它没有帮助:

protected $env = array(); 
protected $currents = array();

public function __construct(\Codeception\TestCase $test, $currents = array()) 
{ 
    $this->test = $test; 
    $this->currents = $currents; 
} 

public function env($env)
{
    if (!is_array($env)) { 
        $this->env[] = $env; 
        return; 
    } 
    foreach ($env as $e) { 
        $this->env($e); 
    } 
}

public function current($key) { 
    if (!isset($this->currents[$key])) { 
        echo $this->currents[$key]; 
       throw new TestRuntime("Current $key is not set in this scenario"); 
    } 
    return $this->currents[$key]; 
}

【问题讨论】:

    标签: php environment codeception


    【解决方案1】:

    我使用的是 2.1,但可能是这样的:

    传递 \Codeception\Scenario $scenario 作为第二个参数

    function testSometing(acceptanceTester $I, \Codeception\Scenario $scenario)        
    {
         $env = $scenario->current();
    }
    

    我为此苦苦挣扎了一段时间,直到我读到了这张票: https://github.com/Codeception/Codeception/issues/2225

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-02
      • 1970-01-01
      • 2017-03-29
      • 2017-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多