我想用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;