2014-01-24 24 views
1

我們使用behat在我們的系統上運行一些功能測試,模擬用戶通過我們網站的旅程。我已經寫了一些上下文和要檢查的事物的定義。帶有behat的定製環境背景

因爲behat將運行在不同的環境下(我們的開發PC,然後我們的登臺服務器......)運行的@BeforeSuite功能需要不同的設置。我會把它們放在behat.yml中,用自定義配置文件,但我不知道如何讀取這些信息

所以,我問的是我怎麼才能到我的上下文文件中的behat配置信息?在behat.yml配置

回答

1

參數經由構造注入到主上下文文件(在貝哈特2):

class FeatureContext extends BehatContext 
{ 
    private $parameters; 

    public function __construct(array $parameters) 
    { 
     $this->parameters = $parameters; 
    } 
} 

然而,由於使用@BeforeSuite,上下文實例尚不可用(和鉤方法是靜態的)。

您仍然可以獲取從事件參數:

class FeatureContext extends BehatContext 
{ 
    /** @BeforeSuite */ 
    public static function setup(SuiteEvent $event) 
    { 
     $parameters = $event->getContextParameters(); 
    } 
} 

相關文檔:http://docs.behat.org/guides/3.hooks.html#suite-hooks