简体   繁体   English

是否可以将PHpspec与behat一起使用?或者仅将Phpunit与behat一起使用? (Symfony的)

[英]is it possible to use PHpspec with behat?, or just PhPunit with behat? (Symfony)

I'm playing a little with Behat these days, the thing is that I don't know if I can use PHPspec with Behat to "assert" all the stuff, this one is so readable that I would like to use it. 这些天,我在和Behat一起玩一些游戏,问题是我不知道我是否可以将PHPspec和Behat一起使用来“断言”所有内容,这个内容可读性强,我想使用它。 In my case I'm using Symfony. 就我而言,我正在使用Symfony。

If not, how can I use Asserts from PHPunit in Behat. 如果没有,如何在Behat中使用来自PHPunit的Asserts。 I couldn't for now, I installed PHPUnit with composer, but in the Behat Documentation they require a file, but the scenario is lightly different (they didn't installed it by using composer, is not in Vendor directory) 我暂时不能,我在composer上安装了PHPUnit,但是在Behat文档中它们需要一个文件,但是情况稍有不同(它们不是通过使用composer来安装的,不在Vendor目录中)

URL from DOC: http://docs.behat.org/quick_intro.html#more-about-features 来自DOC的网址: http : //docs.behat.org/quick_intro.html#more-about-features

, the require_once is little elegant. ,require_once不太优雅。

Any idea?, any answer?, thanks! 有任何想法吗?有答案吗?谢谢!

You can bring phpspec's matchers to behat with the expect helper . 您可以将phpspec的匹配器与Expect 助手一起使用

Few examples of use: 几个使用示例:

// 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();

You most certainly can use Bahat with PHPUnit. 您当然可以将Bahat与PHPUnit一起使用。 I didn't try with PHPSpec, but I'm certain it's possible if you can access the logic that performs assertions. 我没有尝试使用PHPSpec,但是我敢肯定,如果您可以访问执行断言的逻辑,那是可能的。 Typically any test framework would expose that logic for the "outside users". 通常,任何测试框架都会向“外部用户”公开该逻辑。

/**
 * @Then /^the magic should happen$/
 */
public function assertUnicornsExist()
{
    // Make standard assertions through static calls…
    PHPUnit_Framework_TestCase::assertTrue(true);
}

Not sure I get the full picture with regards to installation, but if you're using composer you can simply configure the "autoload" part to include your sources and contexts (if they are separate). 不确定我是否了解安装方面的全貌,但是如果您使用的是composer,则可以简单地配置“自动加载”部分以包括您的源和上下文(如果它们是分开的)。 Mine works pretty much out of the box: 我的开箱即用

{
    "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/"
        }
    }
}

Then you just include the vendor/autoload.php . 然后,您只需包含vendor/autoload.php I recommend adding in a bootstrap that would run once using the @BeforeSuite hook. 我建议添加一个使用@BeforeSuite挂钩可以运行一次的引导程序。

/**
 * @BeforeSuite
 */
 public static function setUpSuite(BeforeSuiteScope $scope)
 {
     // if not bootstrapped already, then include bootstrap with init'ing the autoloader, etc…
 }

Also, if you're starting off with Behat 3 – the docs are not there yet, use http://behat.readthedocs.org/en/latest/ . 另外,如果您刚开始使用Behat 3 –文档尚不存在,请使用http://behat.readthedocs.org/en/latest/ They contain the latest essentials and some decent examples. 它们包含最新的要素和一些不错的例子。

Of course it's possible. 当然可以。 You can use behat to describe how something should behave and phpspec for more detailed things. 您可以使用behat来描述事物的行为方式,并使用phpspec来获得更详细的信息。 Good example is here: http://code.tutsplus.com/tutorials/a-bdd-workflow-with-behat-and-phpspec--cms-21601 此处是一个很好的例子: http : //code.tutsplus.com/tutorials/a-bdd-workflow-with-behat-and-phpspec--cms-21601

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM