0

这些天我在玩一点 Behat,问题是我不知道我是否可以使用 PHPspec 和 Behat 来“断言”所有的东西,这个可读性很强,我想使用它。就我而言,我使用的是 Symfony。

如果没有,我如何在 Behat 中使用 PHPunit 的断言。我现在不能,我用 composer 安装了 PHPUnit,但是在 Behat 文档中他们需要一个文件,但是场景略有不同(他们没有使用 composer 安装它,不在 Vendor 目录中)

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

, require_once 有点优雅。

有什么想法吗?有答案吗,谢谢!

4

3 回答 3

3

您可以将 phpspec 的匹配器与expect helper结合起来。

几个使用示例:

// 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();
于 2014-07-01T05:58:19.053 回答
1

您当然可以将 Bahat 与 PHPUnit 一起使用。我没有尝试使用 PHPSpec,但我敢肯定,如果您可以访问执行断言的逻辑,这是可能的。通常,任何测试框架都会为“外部用户”公开该逻辑。

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

不确定我是否了解安装的全貌,但如果您使用的是作曲家,您可以简单地配置“自动加载”部分以包含您的源和上下文(如果它们是分开的)。我的工作几乎是开箱即用的:

{
    "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/。它们包含最新的必需品和一些不错的例子。

于 2014-06-19T21:20:12.490 回答
0

当然有可能。您可以使用 behat 来描述某些事物的行为方式,并使用 phpspec 来描述更详细的事物。很好的例子在这里:http ://code.tutsplus.com/tutorials/a-bdd-workflow-with-behat-and-phpspec--cms-21601

于 2016-07-06T22:29:46.273 回答