[英]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.