0

我有一个遗留的 Symfony 2.0 项目(准确地说是 2.0.11 版),我想在其中添加行为测试。由于它是 Symfony 2.0,它使用deps供应商系统而不是作曲家。我目前无法升级 Symfony 版本或切换到 composer。

我尝试使用以下 deps 设置安装 behat:

[Mink]
    target=/Behat/Mink
    git=git://github.com/Behat/Mink.git
    version=v1.3.3

[MinkBundle]
    target=/Behat/MinkBundle
    git=git://github.com/Behat/MinkBundle.git

[BehatBundle]
    target=/Behat/BehatBundle
    git=git://github.com/Behat/BehatBundle.git

[Gherkin]
    target=/Behat/Gherkin
    git=git://github.com/Behat/Gherkin.git
    version=v2.1.1

[Behat]
    target=/Behat/Behat
    git=git://github.com/Behat/Behat.git
    version=v2.3.5

[Goutte]
    target=/Goutte
    git=git://github.com/fabpot/Goutte.git

(是的,我知道 BehatBundle 等已过时,但鉴于我使用的是 deps 和 sf2.0,我似乎需要这些过时的版本。)

当我运行时vendor/Behat/Behat/bin/behat,我会得到这里描述的问题:

PHP Warning:  require_once(behat/autoload.php): failed to open stream: No such file or directory in /home/sam/wo-code/PersonaBubble/vendor/Behat/Behat/bin/behat on line 23
PHP Fatal error:  require_once(): Failed opening required 'behat/autoload.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/sam/wo-code/PersonaBubble/vendor/Behat/Behat/bin/behat on line 23

我意识到 behat 2.3.5 实际上没有autoload.php文件。我在 Github 上查看了 Behat 的标签,发现2.1.3是最新版本,它有一个autoload.php(实际上autoload.php.dist,虽然每个早期版本也有autoload.php.dist而不是autoload.php,所以我认为就是这样)。

因此,我将我的 behat 版本号更改depsv2.1.3,删除了我的供应商并重新安装。然后 behat 命令发生了变化,所以我运行了:

php vendor/Behat/Behat/bin/behat.php

我现在看到了这个错误

PHP Fatal error:  Class 'Symfony\Component\Console\Application' not found in /home/sam/wo-code/PersonaBubble/vendor/Behat/Behat/src/Behat/Behat/Console/BehatApplication.php on line 26

有谁知道我应该使用什么正确版本的 behat 等来让它与 Symfony 2.0 和 deps 一起工作? 还是我缺少其他步骤。

PS 我最终通过 PHAR 运行 behat(尽管这有其他问题,所以我放弃了它,因为它不值得)。但是,我真的很想知道如何通过标准供应商安装来做到这一点,因此这篇文章。

4

1 回答 1

0

我目前无法升级 Symfony 版本或切换到 composer。

我理解你所说的,但下面的例子可能会给你一些提示,我希望!我希望它有点帮助。

我正在分享我在所有 Symfony2 项目中一直使用的东西。贝哈特+貂皮+硒

作曲家:

您需要某些版本,以便每个人都使用相同版本的everthing。

mySymfonyProject/composer.json:

"require": {
    "behat/behat": "2.5.*@stable",
    "behat/behat-bundle": "1.0.0",
    "behat/symfony2-extension": "1.1.2",
    "behat/mink": "1.5.0",
    "behat/mink-extension": "~1.3",
    "behat/mink-selenium2-driver": "1.1.1",
    "behat/mink-goutte-driver": "1.0.9"
},
"config": {
    "bin-dir": "bin"
},
"minimum-stability": "dev",

行为

mySymfonyProject/behat.yml:

default:
    context:
        class: FeatureContext
    extensions:
        Behat\Symfony2Extension\Extension:
            mink_driver: true
            kernel:
                env: test
                debug: true
        Behat\MinkExtension\Extension:
            base_url: 'http://mysymfonyproject.local/app_test.php/'
            javascript_session: selenium2
            browser_name: firefox
            goutte: ~
            selenium2: ~
    paths:
        features: %behat.paths.base%/src
        bootstrap: %behat.paths.features%/Context

下载到您的项目中。在这里,请确保下载页面中间的 2.43.1 版本。

运行:java -jar selenium-server-standalone-2.43.1.jar

上下文特征

mySymfonyProject/src/Site/CommonBundle/Features/Context/FeatureContext.php

<?php

namespace Site\CommonBundle\Features\Context;

use Behat\MinkExtension\Context\MinkContext;
use Behat\Symfony2Extension\Context\KernelAwareInterface;
use Symfony\Component\HttpKernel\KernelInterface;

class FeatureContext extends MinkContext implements KernelAwareInterface
{
    /**
     * Hold Symfony kernel object.
     *
     * @var object Kernel Object.
     */
    protected $kernel;

    /**
     * Helps to use doctrine and entity manager.
     *
     * @param KernelInterface $kernelInterface Interface for getting Kernel.
     */
    public function setKernel(KernelInterface $kernelInterface)
    {
        $this->kernel = $kernelInterface;
    }

    //And your own methods
}

测试

当您拥有功能文件时,您可以像这样运行它们(这可以一次性运行。有关更多信息,请阅读 behat doc):

bin/behat @SiteCommonBundle
于 2014-10-13T10:33:39.847 回答