[英]How to use PHPUnit in Behat when using Symfony's PHPUnit Bridge?
[英]is it possible to use PHpspec with behat?, or just PhPunit with behat? (Symfony)
這些天,我在和Behat一起玩一些游戲,問題是我不知道我是否可以將PHPspec和Behat一起使用來“斷言”所有內容,這個內容可讀性強,我想使用它。 就我而言,我正在使用Symfony。
如果沒有,如何在Behat中使用來自PHPunit的Asserts。 我暫時不能,我在composer上安裝了PHPUnit,但是在Behat文檔中它們需要一個文件,但是情況稍有不同(它們不是通過使用composer來安裝的,不在Vendor目錄中)
來自DOC的網址: http : //docs.behat.org/quick_intro.html#more-about-features
,require_once不太優雅。
有任何想法嗎?有答案嗎?謝謝!
您可以將phpspec的匹配器與Expect 助手一起使用 。
幾個使用示例:
// matches if $something === 'something'
expect($something)->toBe('something');
// matches if $article->isActive() returns true
expect($article)->toBeActive();
// matches if $article->hasComments() returns false
expect($article)->notToHaveComments();
您當然可以將Bahat與PHPUnit一起使用。 我沒有嘗試使用PHPSpec,但是我敢肯定,如果您可以訪問執行斷言的邏輯,那是可能的。 通常,任何測試框架都會向“外部用戶”公開該邏輯。
/**
* @Then /^the magic should happen$/
*/
public function assertUnicornsExist()
{
// Make standard assertions through static calls…
PHPUnit_Framework_TestCase::assertTrue(true);
}
不確定我是否了解安裝方面的全貌,但是如果您使用的是composer,則可以簡單地配置“自動加載”部分以包括您的源和上下文(如果它們是分開的)。 我的開箱即用
{
"require": {
"behat/behat": "dev-master",
"behat/mink": "dev-master",
"behat/mink-extension": "dev-master",
"behat/mink-browserkit-driver": "dev-master",
"behat/mink-goutte-driver": "dev-master",
"phpunit/dbunit": "*"
},
"autoload": {
"psr-0": {
"": "src/"
}
}
}
然后,您只需包含vendor/autoload.php
。 我建議添加一個使用@BeforeSuite
掛鈎可以運行一次的引導程序。
/**
* @BeforeSuite
*/
public static function setUpSuite(BeforeSuiteScope $scope)
{
// if not bootstrapped already, then include bootstrap with init'ing the autoloader, etc…
}
另外,如果您剛開始使用Behat 3 –文檔尚不存在,請使用http://behat.readthedocs.org/en/latest/ 。 它們包含最新的要素和一些不錯的例子。
當然可以。 您可以使用behat來描述事物的行為方式,並使用phpspec來獲得更詳細的信息。 此處是一個很好的例子: http : //code.tutsplus.com/tutorials/a-bdd-workflow-with-behat-and-phpspec--cms-21601
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.