我想用BDD和贝哈特在我的symfony项目,从现在开始。目前的项目是sf2.4,我努力让Behat 3工作。我使用the latest doc concerning behat3,由jakub在this post推荐。
问题
贝哈特3似乎运作良好。但是,为了能够真正开始,我需要访问Kernel(容器,教条等)。我试着用my_project,测试项目再现了Behat的例子。然而,使用这 - $>容器(),$这 - >内核级> getContainer()不变地引发一个 '现行异常'(代码停止在iShouldGet步骤):
public function iShouldGet(PyStringNode $string)
{
//$container = $this->kernel->getContainer();
//$container = $this->getContainer();
//$doctrine = $this->getContainer()->get('doctrine');
if ((string) $string !== $this->output) {
throw new Exception(
"Actual output is:\n" . $this->output
);
}
}
我试图创建相同贝哈特'ls' 的内AcmeDemoBundle测试:
|Acme
|Demo
|Features
|Context/FeatureContext.php
ls.feature
然而,它提出了一个错误:
[Behat\Testwork\Tester\Exception\WrongPathsException]
No specifications found at path(s) `@AcmeDemoBundle`.
解
这可能是由于使用Behat3,但我不确定。任何暗示为什么会出现这个问题/如何解决它?一般来说,关于如何整合behat到symfony2(2.4)项目的建议将非常值得赞赏。
非常感谢。
问候,
注意:这里是我的文件:
behat.yml
# behat.yml
default:
suites:
my_suite:
type: symfony_bundle
bundle: AcmeDemoBundle
mink_session: default
mink_javascript_session: selenium2
extensions:
#Behat\MinkExtension\Extension:
#Behat\MinkExtension\ServiceContainer\MinkExtension:
Behat\MinkExtension:
base_url: 'http://demo.com'
# this will be the url of our application
#base_url: 'http://wikipedia.org'
sessions:
default:
goutte: ~
selenium2:
selenium2: ~
Behat\Symfony2Extension: ~
应用程序/ autoload.php
<?php
use Doctrine\Common\Annotations\AnnotationRegistry;
use Composer\Autoload\ClassLoader;
/**
* @var ClassLoader $loader
*/
$loader = require __DIR__.'/../vendor/autoload.php';
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
$loader->add('Behat\Gherkin',realpath(__DIR__.'/../vendor/behat/gherkin/src'));
$loader->add('Behat\Behat' ,realpath(__DIR__.'/../vendor/behat/behat/src'));
$loader->add('Behat\BehatBundle' ,realpath(__DIR__.'/../vendor/bundles'));
return $loader;