Tình hìnhBehat 3 trong symfony2.4 (truy cập học thuyết)
Tôi muốn sử dụng BDD và Behat trong các dự án symfony tôi từ bây giờ. Dự án hiện tại là sf2.4, và tôi cố gắng làm cho Behat 3 hoạt động. Tôi sử dụng the latest doc concerning behat3, như được đề xuất bởi jakub trong this post.
vấn đề
Behat 3 dường như làm việc tốt. Tuy nhiên, để có thể thực sự bắt đầu, tôi cần phải có quyền truy cập vào Kernel (container, doctrine, etc ...). Tôi đã thử với my_project, thử nghiệm dự án tái tạo ví dụ ls cho Behat. Tuy nhiên, sử dụng $ this-> container(), $ this-> kernel-> getContainer() luôn đặt ra một 'cấp phát ngoại lệ' (mã dừng lại ở iShouldGet bước):
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
);
}
}
tôi đã cố gắng để tạo ra các behat cùng test 'ls' trong AcmeDemoBundle:
|Acme
|Demo
|Features
|Context/FeatureContext.php
ls.feature
Tuy nhiên, nó đặt ra một lỗi:
[Behat\Testwork\Tester\Exception\WrongPathsException]
No specifications found at path(s) `@AcmeDemoBundle`.
giải pháp
Nó có thể là do sử dụng Behat3, nhưng tôi không chắc chắn. Bất kỳ gợi ý nào tại sao vấn đề này xảy ra/cách giải quyết nó? Nói chung, lời khuyên tốt về cách tích hợp ứng xử vào symfony2 (2.4) sẽ được đánh giá cao.
Cảm ơn rất nhiều trước.
Kính trọng,
NB: Đây là tác phẩm của tôi:
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: ~
app/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;